void KanagramGame::nextVocab() { m_index++; if((uint)m_index >= m_fileList.size()) m_index = 0; m_filename = m_fileList[m_index]; checkFile(); KEduVocDocument *doc = new KEduVocDocument(this); doc->open(KURL(locate("appdata", m_filename)), false); m_docTitle = doc->getTitle(); m_answeredWords.clear(); }
void KanagramGame::previousVocab() { m_index--; if(m_index < 0) m_index = m_fileList.size() - 1; m_filename = m_fileList[m_index]; checkFile(); KEduVocDocument *doc = new KEduVocDocument(this); doc->open(KURL(locate("appdata", m_filename)), false); m_docTitle = doc->getTitle(); m_answeredWords.clear(); }
void KanagramGame::loadDefaultVocab() { m_filename = KanagramSettings::defaultVocab(); if (m_filename.isEmpty()) { // first run m_filename = locate("appdata", "data/" + KanagramSettings::dataLanguage() + "/objects.kvtml"); if (m_filename.isEmpty()) { refreshVocabList(); nextVocab(); } } kdDebug() << "in game " << m_filename <<endl; KEduVocDocument *doc = new KEduVocDocument(this); doc->open(KURL(locate("appdata", m_filename)), false); m_docTitle = doc->getTitle(); kdDebug() << m_docTitle <<endl; //Animals nextAnagram(); }
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; }
void KanagramGame::nextAnagram() { checkFile(); KEduVocDocument *doc = new KEduVocDocument(this); doc->open(KURL(locate("appdata", m_filename)), false); int totalWords = doc->numEntries(); int wordNumber = m_random.getLong(totalWords); if(doc->numEntries() == (int)m_answeredWords.size()) { m_answeredWords.clear(); } while(m_answeredWords.findIndex(doc->getEntry(wordNumber)->getOriginal()) != -1) { wordNumber = m_random.getLong(totalWords); } m_originalWord = doc->getEntry(wordNumber)->getOriginal(); m_answeredWords.append(m_originalWord); m_anagram = createAnagram(m_originalWord); m_hint = doc->getEntry(wordNumber)->getRemark(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::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); }
void KEduVocDocumentValidatorTest::testDocumentAboutInfo() { KTemporaryFile temp; temp.setSuffix(".kvtml"); temp.open(); KUrl fileName = KUrl(temp.fileName()); temp.close(); const QString generator = QString::fromLatin1( "Validator Unit Tests" ); const QString author = QString::fromLatin1( "Validator Test" ); const QString license = QString::fromLatin1( "test license" ); const QString comment = QString::fromLatin1( "comment" ); const QString category = QString::fromLatin1( "test document" ); const QString title = QString::fromLatin1( "Validator Test Title" ); KEduVocDocument doc; doc.setAuthor( author ); doc.setLicense( license ); doc.setDocumentComment( comment ); doc.setCategory( category ); doc.setTitle( title ); doc.saveAs(fileName, KEduVocDocument::Kvtml, generator); KEduVocDocument docRead; docRead.open(fileName); QCOMPARE( docRead.generator(), generator ); QCOMPARE( docRead.author(), author ); QCOMPARE( docRead.license(), license ); QCOMPARE( docRead.documentComment(), comment ); QCOMPARE( docRead.category(), category ); QCOMPARE( docRead.title(), title ); }
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::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); }