From: Jeremy Paul Whiting Date: Wed, 25 Jul 2007 15:17:17 +0000 (+0000) Subject: fleshed out readLesson X-Git-Tag: v3.92.0~5 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=0f0edaa070e8f285c59d0598a5ed1ba0fa5e5125;p=libqmvoc.git fleshed out readLesson svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=692438 --- diff --git a/kdeeducore/keduvockvtml2reader.cpp b/kdeeducore/keduvockvtml2reader.cpp index 56d3878..c5e2dbc 100644 --- a/kdeeducore/keduvockvtml2reader.cpp +++ b/kdeeducore/keduvockvtml2reader.cpp @@ -350,7 +350,7 @@ bool KEduVocKvtml2Reader::readEntry(QDomElement &entryElement) } // TODO: probably should insert at id position with a check to see if it exists - m_doc->appendEntry(&expr); + m_doc->insertEntry(&expr, id); return result; } @@ -375,12 +375,6 @@ bool KEduVocKvtml2Reader::readTranslation(QDomElement &translationElement, expr.translation(index).setType(currentElement.text()); } - currentElement = translationElement.firstChildElement(KVTML_INQUERY); - if (!currentElement.isNull()) - { - // TODO: ask fregl what inquery is for, and do something with it - } - // currentElement = translationElement.firstChildElement(KVTML_PRONUNCIATION); if (!currentElement.isNull()) @@ -388,20 +382,7 @@ bool KEduVocKvtml2Reader::readTranslation(QDomElement &translationElement, expr.translation(index).setPronunciation(currentElement.text()); } - // - currentElement = translationElement.firstChildElement(KVTML_FALSEFRIENDFROM); - if (!currentElement.isNull()) - { - // TODO: figure out what to do with falsefriend information - } - - // - currentElement = translationElement.firstChildElement(KVTML_FALSEFRIENDTO); - if (!currentElement.isNull()) - { - } - - // + // currentElement = translationElement.firstChildElement(KVTML_FALSEFRIEND); if (!currentElement.isNull()) { @@ -412,7 +393,7 @@ bool KEduVocKvtml2Reader::readTranslation(QDomElement &translationElement, currentElement = translationElement.firstChildElement(KVTML_ANTONYM); if (!currentElement.isNull()) { - // TODO: figure out what to do with falsefriend information + expr.translation(index).setAntonym(currentElement.text()); } // @@ -499,98 +480,58 @@ bool KEduVocKvtml2Reader::readTranslation(QDomElement &translationElement, // TODO: do something with the sound } -// if (query_id == KV_O) -// q_org = lang; - -// if (query_id == KV_T) - -// q_trans = lang; - - -// if (!faux_ami_f.isEmpty() ) -// expr.translation(i).setFalseFriend (0, faux_ami_f); -// if (!faux_ami_t.isEmpty() ) -// expr.translation(0).setFalseFriend (i, faux_ami_t); -// if ( i != 0 ) { -// expr.translation(i).gradeFrom(0).setQueryCount(qcount); -// expr.translation(0).gradeFrom(i).setQueryCount(r_qcount); -// expr.translation(i).gradeFrom(0).setBadCount(bcount); -// expr.translation(0).gradeFrom(i).setBadCount(r_bcount); -// expr.translation(i).gradeFrom(0).setQueryDate(qdate); -// expr.translation(0).gradeFrom(i).setQueryDate(r_qdate); -// } -////kDebug() << "KEduVocKvtml2Reader::readExpression(): id: " << i << " translation: " << textstr << endl; - -// // Next translation -// currentElement = currentElement.nextSiblingElement(KV_TRANS); -// i++; -// } - - //if (m_doc->entryCount() == 0) - // m_doc->setQueryIdentifier(q_org, q_trans); return true; } -bool KEduVocKvtml2Reader::readLesson(QDomElement &domElementParent) +bool KEduVocKvtml2Reader::readLesson(QDomElement &lessonElement) { - QString s; - QStringList descriptions; - QDomAttr attribute; - QDomElement currentElement; - - //------------------------------------------------------------------------- - // Attributes - //------------------------------------------------------------------------- - - attribute = domElementParent.attributeNode(KV_SIZEHINT); - if (!attribute.isNull()) - m_doc->setSizeHint(-1, attribute.value().toInt()); - - //------------------------------------------------------------------------- - // Children - //------------------------------------------------------------------------- - - QDomNodeList entryList = domElementParent.elementsByTagName(KV_LESS_DESC); - if (entryList.length() <= 0) + // NOTE: currently this puts an identifier into the last lesson it is in, once support for multiple lessons + // is in the entry class, all lessons that include an entry will be in there + int lessonId = 0; + + //Lesson name + QDomElement currentElement = lessonElement.firstChildElement(KVTML_NAME); + if (!currentElement.isNull()) + { + lessonId = m_doc->appendLesson(currentElement.text()); + } + else + { + m_errorMessage = i18n("each lesson must have a name"); return false; - - descriptions.clear(); - QList inQueryList; - inQueryList.clear(); - - for (int i = 0; i < entryList.count(); ++i) { - currentElement = entryList.item(i).toElement(); - if (currentElement.parentNode() == domElementParent) { - int no = 0; - bool isCurr = false; - - attribute = currentElement.attributeNode(KV_LESS_NO); - if (!attribute.isNull()) - no = attribute.value().toInt(); - - attribute = currentElement.attributeNode(KV_LESS_CURR); - if (!attribute.isNull()) - isCurr = attribute.value().toInt() != 0; - - if (isCurr && no != 0) - m_doc->setCurrentLesson(no); - - attribute = currentElement.attributeNode(KV_LESS_QUERY); - if (!attribute.isNull()) - if (attribute.value().toInt() != 0 && no > 0) - inQueryList.append(no); - - s = currentElement.text(); - if (s.isNull()) - s = ""; - descriptions.append(s); + } + + //true + currentElement = lessonElement.firstChildElement(KVTML_QUERY); + if (!currentElement.isNull()) + { + if (currentElement.text() == KVTML_TRUE) + { + m_doc->addLessonToQuery(lessonId); } } - - if (inQueryList.count() > 0) - m_doc->setLessonsInQuery(inQueryList); - m_doc->setLessonDescriptions(descriptions); - + + //true + currentElement = lessonElement.firstChildElement(KVTML_CURRENT); + if (!currentElement.isNull()) + { + if (currentElement.text() == KVTML_TRUE) + { + m_doc->setCurrentLesson(lessonId); + } + } + + //0 + currentElement = lessonElement.firstChildElement(KVTML_ENTRYID); + while (!currentElement.isNull()) + { + int entryId = currentElement.text().toInt(); + // TODO: once we have a lesson class, add each of these entryids to the lesson + // set this lesson for the given enty + m_doc->entry(entryId)->setLesson(lessonId); + currentElement = currentElement.nextSiblingElement(KVTML_ENTRYID); + } + return true; } @@ -600,13 +541,13 @@ bool KEduVocKvtml2Reader::readArticle(QDomElement &articleElement, int identifie
der - die - das + die + das ein - eine - ein + eine + ein
*/ diff --git a/kdeeducore/keduvockvtml2reader.h b/kdeeducore/keduvockvtml2reader.h index be1d044..fe8cd3b 100644 --- a/kdeeducore/keduvockvtml2reader.h +++ b/kdeeducore/keduvockvtml2reader.h @@ -113,6 +113,9 @@ public: */ bool readGrade(QDomElement &gradeElement, KEduVocExpression &expr, int index); + /** read a lesson, and append it to the document + * @param lessonElement element to read from + */ bool readLesson(QDomElement &lessonElement); QString errorMessage() const { return m_errorMessage; } diff --git a/kdeeducore/kvtml2defs.h b/kdeeducore/kvtml2defs.h index d974d20..f2e3fe2 100644 --- a/kdeeducore/kvtml2defs.h +++ b/kdeeducore/kvtml2defs.h @@ -62,6 +62,7 @@ #define KVTML_LESSON "lesson" #define KVTML_QUERY "query" #define KVTML_CURRENT "current" +#define KVTML_ENTRYID "entryid" #define KVTML_ENTRIES "entries" #define KVTML_ENTRY "entry" @@ -71,9 +72,8 @@ #define KVTML_TRANSLATION "translation" #define KVTML_TEXT "text" #define KVTML_PRONUNCIATION "pronunciation" -#define KVTML_FALSEFRIENDFROM "falsefriendfrom" -#define KVTML_FALSEFRIENDTO "falsefriendto" #define KVTML_FALSEFRIEND "falsefriend" +#define KVTML_FROMID "fromid" #define KVTML_ANTONYM "antonym" #define KVTML_SYNONYM "synonym" #define KVTML_EXAMPLE "example" diff --git a/kdeeducore/kvtml2todo b/kdeeducore/kvtml2todo index e5f40e6..61411ee 100644 --- a/kdeeducore/kvtml2todo +++ b/kdeeducore/kvtml2todo @@ -1,7 +1,6 @@ Temporary todo for kvtml2 reader: - read lessons read falsefriend tags store identifier name, sizehint and type? (need a place to store it first) diff --git a/kdeeducore/kvtml_empty_sample.kvtml b/kdeeducore/kvtml_empty_sample.kvtml index 60f0023..2267d7c 100644 --- a/kdeeducore/kvtml_empty_sample.kvtml +++ b/kdeeducore/kvtml_empty_sample.kvtml @@ -72,12 +72,9 @@ Kniebeugen - 1 - - - + @@ -138,7 +135,7 @@ Lesson with grades example true true - + 0