void KEduVocDocumentValidatorTest::testWordTypes()
{
    KEduVocDocument doc;
    // create doc - has no word types yet
    QCOMPARE(doc.wordTypeContainer()->childContainerCount(), 0);

    KEduVocWordType *noun;
    KEduVocWordType *nounMale;
    KEduVocWordType *nounFemale;
    KEduVocWordType *verb;

    noun = new KEduVocWordType("Noun", doc.wordTypeContainer());
    doc.wordTypeContainer()->appendChildContainer(noun);
    QCOMPARE(doc.wordTypeContainer()->childContainerCount(), 1);
    nounMale = new KEduVocWordType("Male", noun);
    noun->appendChildContainer(nounMale);
    nounFemale = new KEduVocWordType("Female", noun);
    noun->appendChildContainer(nounFemale);
    verb = new KEduVocWordType("Verb", doc.wordTypeContainer());
    doc.wordTypeContainer()->appendChildContainer(verb);
    QCOMPARE(doc.wordTypeContainer()->childContainerCount(), 2);
    QCOMPARE(doc.wordTypeContainer()->childContainer(0)->childContainerCount(), 2);

    // create some entries
    for(int i = 0; i < 20; i++) {
        KEduVocExpression *e =
            new KEduVocExpression(QStringList() << QString("lang1 %1").arg(i) << QString("lang2 %1").arg(i));
        doc.lesson()->appendEntry(e);
        e->translation(0)->setWordType(noun);
        e->translation(1)->setWordType(noun);
    }
    QCOMPARE(doc.lesson()->entryCount(), 20);
    QCOMPARE(noun->entryCount(), 20);
    doc.lesson()->entry(0)->translation(0)->setWordType(verb);
    // translation 1 is still noun, so it needs to be in both now
    QCOMPARE(noun->entryCount(), 20);
    QCOMPARE(verb->entryCount(), 1);
    doc.lesson()->entry(0)->translation(1)->setWordType(verb);
    QCOMPARE(noun->entryCount(), 19);
    QCOMPARE(verb->entryCount(), 1);

    // delete word type
    doc.wordTypeContainer()->deleteChildContainer(1);
    // the word type is set to 0 when removed
    QVERIFY(doc.lesson()->entry(0)->translation(0)->wordType() == 0);
    QVERIFY(doc.lesson()->entry(0)->translation(1)->wordType() == 0);
    QCOMPARE(doc.wordTypeContainer()->childContainerCount(), 1);
}
Exemple #2
0
void VocabEdit::slotSave()
{
    KEduVocDocument *doc = new KEduVocDocument(this);
    doc->setTitle(txtVocabName->text());
    doc->setDocumentComment(txtDescription->text());
    KEduVocIdentifier id;
    doc->appendIdentifier(id);
    for (int i = 0; i < m_vocabList.size(); i++)
    {
        doc->lesson()->appendEntry(&m_vocabList[i]);
    }

    QString fileName = txtVocabName->text().toLower().remove(' ') + ".kvtml";
    QString path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
                   "/kvtml/" + KanagramSettings::dataLanguage();
    QDir dir;
    dir.mkpath(path);
    QUrl url =
        QUrl::fromLocalFile(path +
                            QLatin1Char('/') + fileName);
    qCDebug(KANAGRAM) << "Saving file as " << url;
    doc->saveAs(url, KEduVocDocument::Automatic);

    m_textChanged = false;
}
Exemple #3
0
VocabEdit::VocabEdit(QWidget *parent, const QString  &fileName) : QDialog(parent), m_fileName("")
{
    setupUi(this);

    if (!fileName.isEmpty())
    {
        m_fileName = fileName;
        KEduVocDocument	*doc = new KEduVocDocument(this);
        doc->open(QUrl::fromLocalFile(m_fileName), KEduVocDocument::FileIgnoreLock);
        for (int i = 0; i < doc->lesson()->entryCount(KEduVocLesson::Recursive); i++)
        {
            KEduVocExpression expr = *doc->lesson()->entries(KEduVocLesson::Recursive).value(i);
            m_vocabList.append(expr);
            lboxWords->addItem(doc->lesson()->entries(KEduVocLesson::Recursive).value(i)->translation(0)->text());
        }
        txtVocabName->setText(doc->title());
        txtDescription->setText(doc->documentComment());
        delete doc;
    }

    connect(btnSave, &QPushButton::clicked, this, &VocabEdit::slotSave);
    connect(btnNewWord, &QPushButton::clicked, this, &VocabEdit::slotNewWord);
    connect(btnRemoveWord, &QPushButton::clicked, this, &VocabEdit::slotRemoveWord);
    connect(btnClose, &QPushButton::clicked, this, &VocabEdit::slotClose);

    connect(txtWord, &QLineEdit::textChanged, this, &VocabEdit::slotWordTextChanged);
    connect(txtHint, &QLineEdit::textChanged, this, &VocabEdit::slotHintTextChanged);

    //Connect the name and description boxes to a general textChanged slot, so that we can keep track of
    //whether they've been changed or not
    connect(txtVocabName, &QLineEdit::textChanged, this, &VocabEdit::slotTextChanged);
    connect(txtDescription, &QLineEdit::textChanged, this, &VocabEdit::slotTextChanged);

    connect(lboxWords, &QListWidget::itemSelectionChanged, this, &VocabEdit::slotSelectionChanged);

    //Has anything in the dialog changed?
    m_textChanged = false;
}
void KEduVocDocumentValidatorTest::testAddRemoveLanguage()
{
    KEduVocDocument doc;
    // create some initial languages
    doc.appendIdentifier();
    doc.appendIdentifier();
    doc.appendIdentifier();
    doc.appendIdentifier();
    doc.identifier(0).setName("0");
    doc.identifier(1).setName("1");
    doc.identifier(2).setName("2");
    doc.identifier(3).setName("3");

    QCOMPARE(doc.identifierCount(), 4);
    KEduVocLesson* lesson = new KEduVocLesson("lesson", doc.lesson());
    doc.lesson()->appendChildContainer(lesson);
    lesson->appendEntry(new KEduVocExpression);
    lesson->entry(0)->setTranslation(0, "0");
    lesson->entry(0)->setTranslation(1, "1");
    lesson->entry(0)->setTranslation(2, "2");
    lesson->entry(0)->setTranslation(3, "3");
    QCOMPARE(lesson->entry(0)->translationIndices().size(), 4);

    // throw away the second language
    doc.removeIdentifier(1);

    QCOMPARE(doc.identifierCount(), 3);
    QCOMPARE(doc.identifier(0).name(), QString("0"));
    QCOMPARE(doc.identifier(1).name(), QString("2"));
    QCOMPARE(doc.identifier(2).name(), QString("3"));

    QCOMPARE(lesson->entry(0)->translationIndices().size(), 3);
    QCOMPARE(lesson->entry(0)->translation(0)->text(), QString("0"));
    QCOMPARE(lesson->entry(0)->translation(1)->text(), QString("2"));
    QCOMPARE(lesson->entry(0)->translation(2)->text(), QString("3"));
}
void KEduVocDocumentValidatorTest::testLessons()
{
    QString lesson1 = QString::fromLatin1( "Lesson 1" );
    QString lesson1child1 = QString::fromLatin1( "Lesson 1.1" );
    QString lesson1child2 = QString::fromLatin1( "Lesson 1.2" );
    QString lesson2 = QString::fromLatin1( "Lesson 2" );
    QString lesson3 = QString::fromLatin1( "Lesson 3" );

    KEduVocDocument doc;
    doc.lesson()->appendChildContainer(new KEduVocLesson(lesson1, doc.lesson()));
    QCOMPARE(doc.lesson()->childContainerCount(), 1);
    QCOMPARE(doc.lesson()->childContainer(0)->containerType(), KEduVocContainer::Lesson);
    QCOMPARE(doc.lesson()->childContainer(0)->parent(), doc.lesson());
    QCOMPARE(doc.lesson()->childContainer(0)->name(), lesson1);

    doc.lesson()->appendChildContainer(new KEduVocLesson(lesson2, doc.lesson()));
    doc.lesson()->appendChildContainer(new KEduVocLesson(lesson3, doc.lesson()));
    QCOMPARE(doc.lesson()->childContainerCount(), 3);

    doc.lesson()->childContainer(0)->appendChildContainer(new KEduVocLesson(lesson1child1, doc.lesson()->childContainer(0)));
    doc.lesson()->childContainer(0)->appendChildContainer(new KEduVocLesson(lesson1child2, doc.lesson()->childContainer(0)));
    QCOMPARE(doc.lesson()->childContainer(0)->childContainerCount(), 2);


}