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 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")); }