]> Git trees. - libqmvoc.git/commitdiff
Work on the kvtml writer
authorPeter Hedlund <peter@peterandlinda.com>
Tue, 27 Feb 2007 21:51:33 +0000 (21:51 +0000)
committerPeter Hedlund <peter@peterandlinda.com>
Tue, 27 Feb 2007 21:51:33 +0000 (21:51 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=637811

kdeeducore/keduvocdocument.cpp
kdeeducore/keduvocdocument.h
kdeeducore/keduvockvtmlwriter.cpp
kdeeducore/keduvockvtmlwriter.h

index b41a89bede14f57b7ec3830ad7253e4d26a17ad0..480d524f41162d2d2149495dc7b141288fb9c8e0 100644 (file)
@@ -335,10 +335,9 @@ bool KEduVocDocument::saveAs(QObject *parent, const KUrl & url, FileType ft, con
       // TODO new writers provide an explicite error message
       // the two messages should be merged
       QString msg = i18n("Could not save \"%1\"\nDo you want to try again?", tmp.path());
-      int result = KMessageBox::warningContinueCancel(0, msg,
-                                                      i18n("I/O Failure"),
-                                                      KGuiItem(i18n("&Retry")));
-      if ( result == KMessageBox::Cancel ) return false;
+      int result = KMessageBox::warningContinueCancel(0, msg, i18n("Error Saving File"), KGuiItem(i18n("&Retry")));
+      if (result == KMessageBox::Cancel) 
+        return false;
     }
   }
   m_url = tmp;
index 36d14dbc7e4d3b56e5a9357088e8a0a50ee39227..7d4137d226ecf54a35f370e67851511dd7055f2b 100644 (file)
@@ -248,8 +248,6 @@ class LeitnerSystem;
 class KDEEDUCORE_EXPORT KEduVocDocument : public QObject
 {
   Q_OBJECT
-  friend class KEduVocKvtmlWriter;
-
 public:
 
   enum FileType { kvd_none,
@@ -698,6 +696,11 @@ public:
    */
   void setConjugation(int index, const KEduVocConjugation &con);
 
+  /**
+   * @returns                the number of conjugations
+  */
+  inline int conjugationCount() const { return m_conjugations.count(); }
+
   /**
    * @param index            index of translation
    * @returns                a pointer to articles if available
@@ -712,6 +715,11 @@ public:
    */
   void setArticle(int index, const KEduVocArticle &art);
 
+  /**
+   * @returns                the number of articles
+  */
+  inline int articleCount() const { return m_articles.count(); }
+
   /**
    * Returns the recommended size
    *
index d07c14d09e7a428549f1f6fcbdb1ffd006ce4c54..dcbcbf73d3671114b3d07e1b76c3349c0a395b3c 100644 (file)
@@ -27,7 +27,6 @@ KEduVocKvtmlWriter::KEduVocKvtmlWriter(QFile *file)
 {
   // the file must be already open
   m_outputFile = file;
-  m_errorMessage = "";
 }
 
 
@@ -42,7 +41,7 @@ bool KEduVocKvtmlWriter::writeDoc(KEduVocDocument *doc, const QString &generator
   QDomElement domElementKvtml = domDoc.createElement("kvtml");
   domDoc.appendChild(domElementKvtml);
 
-  domElementKvtml.setAttribute(KV_ENCODING, (QString)"UTF-8");
+  domElementKvtml.setAttribute(KV_ENCODING, (QString) "UTF-8");
   domElementKvtml.setAttribute(KV_GENERATOR, generator);
   domElementKvtml.setAttribute(KV_COLS, m_doc->numIdentifiers());
   domElementKvtml.setAttribute(KV_LINES, m_doc->numEntries());
@@ -65,8 +64,13 @@ bool KEduVocKvtmlWriter::writeDoc(KEduVocDocument *doc, const QString &generator
   if (!writeArticle(domDoc, domElementKvtml))
     return false;
 
-  if (!writeConjugHeader(domDoc, domElementKvtml, m_doc->m_conjugations))
-    return false;
+  QList<KEduVocConjugation> conjugations;
+  for (int i = 0; i < m_doc->conjugationCount(); i++)
+    conjugations.append(m_doc->conjugation(i));
+  if (conjugations.count() > 0) {
+    if (!writeConjugHeader(domDoc, domElementKvtml, conjugations))
+      return false;
+  }
 
   if (!writeOption(domDoc, domElementKvtml))
     return false;
@@ -81,144 +85,120 @@ bool KEduVocKvtmlWriter::writeDoc(KEduVocDocument *doc, const QString &generator
     return false;
 
   QString q_org, q_trans;
-  QList<KEduVocExpression>::const_iterator first =  m_doc->m_vocabulary.begin ();
   m_doc->queryIdentifier(q_org, q_trans);
 
-  int ent_no = 0;
-  int ent_percent = (int) m_doc->m_vocabulary.size () / 100;
-  float f_ent_percent = (int) m_doc->m_vocabulary.size () / 100.0;
-//TODO emit progressChanged(this, 0);
+  int entryCount = m_doc->numEntries();
 
-  while (first != m_doc->m_vocabulary.end ())
+  for (int i = 0; i < entryCount; i++)
   {
+    KEduVocExpression *entry = m_doc->entry(i);
     QDomElement domElementExpression = domDoc.createElement(KV_EXPR);
 
-    ent_no++;
-    if (ent_percent != 0 && (ent_no % ent_percent) == 0 )
+    if (entry->lesson() != 0)
     {
-      //TODO emit progressChanged(this, ent_no / (int) f_ent_percent);
-    }
-    if ((*first).lesson() != 0)
-    {
-      // entry belongs to lesson x
-      QString ls;
-      int lm = (*first).lesson();
-      if (lm > (int) m_doc->m_lessonDescriptions.size() )
+      int lm = entry->lesson();
+      if (lm > m_doc->lessonDescriptions().count())
       {
         // should not be
         kError() << "index of lesson member too high: " << lm << endl;
         lm = 0;
       }
-      ls.setNum (lm);
-      domElementExpression.setAttribute (KV_LESS_MEMBER, ls);
+      domElementExpression.setAttribute(KV_LESS_MEMBER, lm);
     }
 
-    if ((*first).isInQuery())
-    {
-      // entry was selected for query
-      domElementExpression.setAttribute (KV_SELECTED, (QString) "1");
-    }
+    if (entry->isInQuery())
+      domElementExpression.setAttribute(KV_SELECTED, 1);
 
-    if (!(*first).isActive())
-    {
-      // entry was inactive
-      domElementExpression.setAttribute (KV_INACTIVE, (QString) "1");
-    }
+    if (!entry->isActive())
+      domElementExpression.setAttribute (KV_INACTIVE, 1);
 
-    if ((*first).uniqueType() && !(*first).type(0).isEmpty())
-    {
-      domElementExpression.setAttribute (KV_EXPRTYPE, (*first).type(0));
-    }
+    if (entry->uniqueType() && !entry->type(0).isEmpty())
+      domElementExpression.setAttribute (KV_EXPRTYPE, entry->type(0));
 
     QDomElement domElementOriginal = domDoc.createElement(KV_ORG);
     if (first_expr)
     {
       // save space, only tell language in first entry
       QString s;
-      s.setNum (m_doc->sizeHint (0));
-      domElementOriginal.setAttribute(KV_SIZEHINT, s);
+      domElementOriginal.setAttribute(KV_SIZEHINT, m_doc->sizeHint(0));
 
       s = m_doc->originalIdentifier().simplified();
       if (s.isEmpty() )
         s = "original";
-      domElementOriginal.setAttribute (KV_LANG, s);
+      domElementOriginal.setAttribute(KV_LANG, s);
       if (s == q_org)
         domElementOriginal.setAttribute(KV_QUERY, (QString) KV_O);
       else if (s == q_trans)
         domElementOriginal.setAttribute(KV_QUERY, (QString) KV_T);
-
     }
 
-    if (!(*first).remark(0).isEmpty() )
-      domElementOriginal.setAttribute(KV_REMARK, (*first).remark(0));
+    if (!entry->remark(0).isEmpty() )
+      domElementOriginal.setAttribute(KV_REMARK, entry->remark(0));
 
-    if (!(*first).synonym(0).isEmpty() )
-      domElementOriginal.setAttribute(KV_SYNONYM, (*first).synonym(0));
+    if (!entry->synonym(0).isEmpty() )
+      domElementOriginal.setAttribute(KV_SYNONYM, entry->synonym(0));
 
-    if (!(*first).example(0).isEmpty() )
-      domElementOriginal.setAttribute(KV_EXAMPLE, (*first).example(0));
+    if (!entry->example(0).isEmpty() )
+      domElementOriginal.setAttribute(KV_EXAMPLE, entry->example(0));
 
-    if (!(*first).usageLabel(0).isEmpty() )
-      domElementOriginal.setAttribute(KV_USAGE, (*first).usageLabel(0));
+    if (!entry->usageLabel(0).isEmpty() )
+      domElementOriginal.setAttribute(KV_USAGE, entry->usageLabel(0));
 
-    if (!(*first).paraphrase(0).isEmpty() )
-      domElementOriginal.setAttribute(KV_PARAPHRASE, (*first).paraphrase(0));
+    if (!entry->paraphrase(0).isEmpty() )
+      domElementOriginal.setAttribute(KV_PARAPHRASE, entry->paraphrase(0));
 
-    if (!(*first).antonym(0).isEmpty() )
-      domElementOriginal.setAttribute(KV_ANTONYM, (*first).antonym(0));
+    if (!entry->antonym(0).isEmpty() )
+      domElementOriginal.setAttribute(KV_ANTONYM, entry->antonym(0));
 
-    if (!(*first).pronunciation(0).isEmpty() )
-      domElementOriginal.setAttribute(KV_PRONUNCE, (*first).pronunciation(0));
+    if (!entry->pronunciation(0).isEmpty() )
+      domElementOriginal.setAttribute(KV_PRONUNCE, entry->pronunciation(0));
 
-    if (!(*first).uniqueType() && !(*first).type(0).isEmpty())
-      domElementOriginal.setAttribute(KV_EXPRTYPE, (*first).type(0));
+    if (!entry->uniqueType() && !entry->type(0).isEmpty())
+      domElementOriginal.setAttribute(KV_EXPRTYPE, entry->type(0));
 
-    if (!writeMultipleChoice(domDoc, domElementOriginal, (*first).multipleChoice(0)))
+    if (!writeMultipleChoice(domDoc, domElementOriginal, entry->multipleChoice(0)))
       return false;
 
     QString s;
-    QString entype = s = (*first).type(0);
+    QString entype = s = entry->type(0);
     int pos = s.indexOf(QM_TYPE_DIV);
     if (pos >= 0)
-      entype = s.left (pos);
+      entype = s.left(pos);
     else
       entype = s;
 
-    if (entype == QM_VERB
-        && (*first).conjugation(0).numEntries() > 0)
+    if (entype == QM_VERB && entry->conjugation(0).numEntries() > 0)
     {
-      KEduVocConjugation conj = (*first).conjugation(0);
+      KEduVocConjugation conj = entry->conjugation(0);
       if (!writeConjugEntry(domDoc, domElementOriginal, conj))
         return false;
     }
-    else if (entype == QM_ADJ
-             && !(*first).comparison(0).isEmpty())
+    else if (entype == QM_ADJ && !entry->comparison(0).isEmpty())
     {
-      KEduVocComparison comp = (*first).comparison(0);
+      KEduVocComparison comp = entry->comparison(0);
       if (!writeComparison(domDoc, domElementOriginal, comp))
         return false;
     }
 
-    QDomText domTextOriginal = domDoc.createTextNode((*first).original());
+    QDomText domTextOriginal = domDoc.createTextNode(entry->original());
     domElementOriginal.appendChild(domTextOriginal);
     domElementExpression.appendChild(domElementOriginal);
 
     int trans = 1;
-    while (trans < (int)m_doc->m_identifiers.size())
+    while (trans < m_doc->numIdentifiers())
     {
       QDomElement domElementTranslation = domDoc.createElement(KV_TRANS);
       if (first_expr)
       {
         // save space, only tell language in first entry
         QString s;
-        s.setNum (m_doc->sizeHint (trans));
-        domElementTranslation.setAttribute(KV_SIZEHINT, s);
+        domElementTranslation.setAttribute(KV_SIZEHINT, m_doc->sizeHint(trans));
 
         s = m_doc->identifier(trans).simplified();
         if (s.isEmpty() )
         {
-          s.setNum (trans);
-          s.insert (0, "translation ");
+          s.setNum(trans);
+          s.prepend("translation ");
         }
         domElementTranslation.setAttribute(KV_LANG, s);
         if (s == q_org)
@@ -227,100 +207,74 @@ bool KEduVocKvtmlWriter::writeDoc(KEduVocDocument *doc, const QString &generator
           domElementTranslation.setAttribute(KV_QUERY, (QString) KV_T);
       }
 
-      QString s1, s2;
-
-      if ((*first).grade(trans, false) != 0
-        ||(*first).grade(trans, true) != 0)
-      {
-        domElementTranslation.setAttribute(KV_GRADE, (*first).gradeStr(trans, false)
-                  +';'
-                  +(*first).gradeStr(trans, true));
-      }
-
-      if ((*first).queryCount(trans, false) != 0
-        ||(*first).queryCount(trans, true) != 0)
-      {
-        s1.setNum((*first).queryCount(trans, false));
-        s2.setNum((*first).queryCount(trans, true));
-        domElementTranslation.setAttribute(KV_COUNT, s1 +';' +s2);
-      }
+      if (entry->grade(trans, false) != 0 || entry->grade(trans, true) != 0)
+        domElementTranslation.setAttribute(KV_GRADE, entry->gradeStr(trans, false) + ';' + entry->gradeStr(trans, true));
 
-      if ((*first).badCount(trans, false) != 0
-        ||(*first).badCount(trans, true) != 0)
-      {
-        s1.setNum((*first).badCount(trans, false));
-        s2.setNum((*first).badCount(trans, true));
-        domElementTranslation.setAttribute(KV_BAD, s1 +';' +s2);
-      }
+      if (entry->queryCount(trans, false) != 0 || entry->queryCount(trans, true) != 0)
+        domElementTranslation.setAttribute(KV_COUNT, QString::number(entry->queryCount(trans, false)) + ';' + QString::number(entry->queryCount(trans, true)));
 
-      if ((*first).queryDate(trans, false).toTime_t() != 0
-        ||(*first).queryDate(trans, true).toTime_t() != 0)
-      {
-        s1.setNum((*first).queryDate(trans, false).toTime_t());
-        s2.setNum((*first).queryDate(trans, true).toTime_t());
-        domElementTranslation.setAttribute(KV_DATE, s1 +';' +s2);
-      }
+      if (entry->badCount(trans, false) != 0 || entry->badCount(trans, true) != 0)
+        domElementTranslation.setAttribute(KV_BAD, QString::number(entry->badCount(trans, false)) + ';' + QString::number(entry->badCount(trans, true)));
 
-      if (!(*first).remark(trans).isEmpty() )
-        domElementTranslation.setAttribute(KV_REMARK, (*first).remark(trans));
+      if (entry->queryDate(trans, false).toTime_t() != 0 || entry->queryDate(trans, true).toTime_t() != 0)
+        domElementTranslation.setAttribute(KV_DATE, QString::number(entry->queryDate(trans, false).toTime_t()) + ';' + QString::number(entry->queryDate(trans, true).toTime_t()));
 
-      if (!(*first).fauxAmi(trans, false).isEmpty() )
-        domElementTranslation.setAttribute(KV_FAUX_AMI_F, (*first).fauxAmi(trans, false));
+      if (!entry->remark(trans).isEmpty() )
+        domElementTranslation.setAttribute(KV_REMARK, entry->remark(trans));
 
-      if (!(*first).fauxAmi(trans, true).isEmpty() )
-        domElementTranslation.setAttribute(KV_FAUX_AMI_T, (*first).fauxAmi(trans, true));
+      if (!entry->fauxAmi(trans, false).isEmpty() )
+        domElementTranslation.setAttribute(KV_FAUX_AMI_F, entry->fauxAmi(trans, false));
 
-      if (!(*first).synonym(trans).isEmpty() )
-        domElementTranslation.setAttribute(KV_SYNONYM, (*first).synonym(trans));
+      if (!entry->fauxAmi(trans, true).isEmpty() )
+        domElementTranslation.setAttribute(KV_FAUX_AMI_T, entry->fauxAmi(trans, true));
 
-      if (!(*first).example(trans).isEmpty() )
-        domElementTranslation.setAttribute(KV_EXAMPLE, (*first).example(trans));
+      if (!entry->synonym(trans).isEmpty() )
+        domElementTranslation.setAttribute(KV_SYNONYM, entry->synonym(trans));
 
-      if (!(*first).usageLabel(trans).isEmpty() )
-        domElementTranslation.setAttribute(KV_USAGE, (*first).usageLabel(trans));
+      if (!entry->example(trans).isEmpty() )
+        domElementTranslation.setAttribute(KV_EXAMPLE, entry->example(trans));
 
-      if (!(*first).paraphrase(trans).isEmpty() )
-        domElementTranslation.setAttribute(KV_PARAPHRASE, (*first).paraphrase(trans));
+      if (!entry->usageLabel(trans).isEmpty() )
+        domElementTranslation.setAttribute(KV_USAGE, entry->usageLabel(trans));
 
-      if (!(*first).antonym(trans).isEmpty() )
-        domElementTranslation.setAttribute(KV_ANTONYM, (*first).antonym(trans));
+      if (!entry->paraphrase(trans).isEmpty() )
+        domElementTranslation.setAttribute(KV_PARAPHRASE, entry->paraphrase(trans));
 
-      if (!(*first).pronunciation(trans).isEmpty() )
-        domElementTranslation.setAttribute(KV_PRONUNCE, (*first).pronunciation(trans));
+      if (!entry->antonym(trans).isEmpty() )
+        domElementTranslation.setAttribute(KV_ANTONYM, entry->antonym(trans));
 
-      if (!(*first).uniqueType() && !(*first).type(trans).isEmpty())
-        domElementTranslation.setAttribute(KV_EXPRTYPE, (*first).type(trans));
+      if (!entry->pronunciation(trans).isEmpty() )
+        domElementTranslation.setAttribute(KV_PRONUNCE, entry->pronunciation(trans));
 
-      // only save conjugations when type == verb
+      if (!entry->uniqueType() && !entry->type(trans).isEmpty())
+        domElementTranslation.setAttribute(KV_EXPRTYPE, entry->type(trans));
 
-      if (!writeMultipleChoice(domDoc, domElementTranslation, (*first).multipleChoice(trans)))
+      if (!writeMultipleChoice(domDoc, domElementTranslation, entry->multipleChoice(trans)))
         return false;
 
       QString s;
-      QString entype = s = (*first).type(0);
+      QString entype = s = entry->type(0);
       int pos = s.indexOf(QM_TYPE_DIV);
       if (pos >= 0)
         entype = s.left (pos);
       else
         entype = s;
 
-      if (entype == QM_VERB
-          && (*first).conjugation(trans).numEntries() > 0)
+      if (entype == QM_VERB && entry->conjugation(trans).numEntries() > 0)
       {
-        KEduVocConjugation conj = (*first).conjugation(trans);
+        KEduVocConjugation conj = entry->conjugation(trans);
         if (!writeConjugEntry(domDoc, domElementTranslation, conj))
           return false;
       }
 
-      if (entype == QM_ADJ
-          && !(*first).comparison(trans).isEmpty())
+      if (entype == QM_ADJ && !entry->comparison(trans).isEmpty())
       {
-        KEduVocComparison comp = (*first).comparison(trans);
+        KEduVocComparison comp = entry->comparison(trans);
         if (!writeComparison(domDoc, domElementTranslation, comp))
           return false;
       }
 
-      QDomText domTextTranslation = domDoc.createTextNode((*first).translation(trans));
+      QDomText domTextTranslation = domDoc.createTextNode(entry->translation(trans));
       domElementTranslation.appendChild(domTextTranslation);
       domElementExpression.appendChild(domElementTranslation);
 
@@ -329,7 +283,6 @@ bool KEduVocKvtmlWriter::writeDoc(KEduVocDocument *doc, const QString &generator
 
     domElementKvtml.appendChild(domElementExpression);
 
-    first++;
     first_expr = false;
   }
 
@@ -349,8 +302,8 @@ bool KEduVocKvtmlWriter::writeLesson(QDomDocument &domDoc, QDomElement &domEleme
 
   QDomElement domElementLesson = domDoc.createElement(KV_LESS_GRP);
   domElementLesson.setAttribute(KV_SIZEHINT, m_doc->sizeHint(-1));
-
   int count = 1;
+
   foreach(QString lesson, m_doc->lessonDescriptions())
   {
     if (!lesson.isNull())
@@ -361,13 +314,19 @@ bool KEduVocKvtmlWriter::writeLesson(QDomDocument &domDoc, QDomElement &domEleme
       domElementDesc.setAttribute(KV_LESS_NO, count);
       if (m_doc->currentLesson() == count)
         domElementDesc.setAttribute(KV_LESS_CURR, 1);
-      if (count - 1 < m_doc->lessonsInQuery().count() && m_doc->m_lessonsInQuery[count - 1])
+      bool inQuery = false;
+      ///@todo check that this is working
+      foreach(int liq, m_doc->lessonsInQuery())
+        if (liq == count - 1)
+          inQuery = true;
+
+      if (count - 1 < m_doc->lessonsInQuery().count() && inQuery)
         domElementDesc.setAttribute(KV_LESS_QUERY, 1);
 
       domElementDesc.appendChild(domTextDesc);
       domElementLesson.appendChild(domElementDesc);
+      count++;
     }
-    count++;
   }
 
   domElementParent.appendChild(domElementLesson);
@@ -389,7 +348,7 @@ bool KEduVocKvtmlWriter::writeArticle(QDomDocument &domDoc, QDomElement &domElem
  </article>
 */
 {
-  if (m_doc->m_articles.count() == 0)
+  if (m_doc->articleCount() == 0)
     return true;
 
   QDomElement domElementArticle = domDoc.createElement(KV_ARTICLE_GRP);
@@ -397,19 +356,19 @@ bool KEduVocKvtmlWriter::writeArticle(QDomDocument &domDoc, QDomElement &domElem
   QString indef;
   QString s;
 
-  for (int lfn = 0; lfn < qMin((int) m_doc->m_articles.count(), m_doc->numIdentifiers()); lfn++)
+  for (int lfn = 0; lfn < qMin(m_doc->articleCount(), m_doc->numIdentifiers()); lfn++)
   {
     QDomElement domElementEntry = domDoc.createElement(KV_ART_ENTRY);
     if (lfn == 0)
     {
       s = m_doc->originalIdentifier().simplified();
-      if (s.isEmpty() )
+      if (s.isEmpty())
         s = "original";
     }
     else
     {
       s = m_doc->identifier(lfn).simplified();
-      if (s.isEmpty() )
+      if (s.isEmpty())
       {
         s.setNum(lfn);
         s.prepend("translation ");
@@ -417,8 +376,8 @@ bool KEduVocKvtmlWriter::writeArticle(QDomDocument &domDoc, QDomElement &domElem
     }
     domElementEntry.setAttribute(KV_LANG, s);
 
-    m_doc->m_articles[lfn].female(def, indef);
-    if (!def.isEmpty() )
+    m_doc->article(lfn).female(def, indef);
+    if (!def.isEmpty())
     {
       QDomElement domElementFD = domDoc.createElement(KV_ART_FD);
       QDomText domTextFD = domDoc.createTextNode(def);
@@ -426,7 +385,7 @@ bool KEduVocKvtmlWriter::writeArticle(QDomDocument &domDoc, QDomElement &domElem
       domElementFD.appendChild(domTextFD);
       domElementEntry.appendChild(domElementFD);
     }
-    if (!indef.isEmpty() )
+    if (!indef.isEmpty())
     {
       QDomElement domElementFI = domDoc.createElement(KV_ART_FI);
       QDomText domTextFI = domDoc.createTextNode(indef);
@@ -435,8 +394,8 @@ bool KEduVocKvtmlWriter::writeArticle(QDomDocument &domDoc, QDomElement &domElem
       domElementEntry.appendChild(domElementFI);
     }
 
-    m_doc->m_articles[lfn].male(def, indef);
-    if (!def.isEmpty() )
+    m_doc->article(lfn).male(def, indef);
+    if (!def.isEmpty())
     {
       QDomElement domElementMD = domDoc.createElement(KV_ART_MD);
       QDomText domTextMD = domDoc.createTextNode(def);
@@ -444,7 +403,7 @@ bool KEduVocKvtmlWriter::writeArticle(QDomDocument &domDoc, QDomElement &domElem
       domElementMD.appendChild(domTextMD);
       domElementEntry.appendChild(domElementMD);
     }
-    if (!indef.isEmpty() )
+    if (!indef.isEmpty())
     {
       QDomElement domElementMI = domDoc.createElement(KV_ART_MI);
       QDomText domTextMI = domDoc.createTextNode(indef);
@@ -453,8 +412,8 @@ bool KEduVocKvtmlWriter::writeArticle(QDomDocument &domDoc, QDomElement &domElem
       domElementEntry.appendChild(domElementMI);
     }
 
-    m_doc->m_articles[lfn].natural(def, indef);
-    if (!def.isEmpty() )
+    m_doc->article(lfn).natural(def, indef);
+    if (!def.isEmpty())
     {
       QDomElement domElementND = domDoc.createElement(KV_ART_ND);
       QDomText domTextND = domDoc.createTextNode(def);
@@ -462,7 +421,7 @@ bool KEduVocKvtmlWriter::writeArticle(QDomDocument &domDoc, QDomElement &domElem
       domElementND.appendChild(domTextND);
       domElementEntry.appendChild(domElementND);
     }
-    if (!indef.isEmpty() )
+    if (!indef.isEmpty())
     {
       QDomElement domElementNI = domDoc.createElement(KV_ART_NI);
       QDomText domTextNI = domDoc.createTextNode(indef);
@@ -479,23 +438,38 @@ bool KEduVocKvtmlWriter::writeArticle(QDomDocument &domDoc, QDomElement &domElem
 }
 
 
+bool KEduVocKvtmlWriter::writeOption(QDomDocument &domDoc, QDomElement &domElementParent)
+{
+  QDomElement domElementOption = domDoc.createElement(KV_OPTION_GRP);
+  QDomElement domElementSort = domDoc.createElement(KV_OPT_SORT);
+
+  domElementSort.setAttribute(KV_BOOL_FLAG, (m_doc->isSortingEnabled()?1:0));
+  domElementOption.appendChild(domElementSort);
+
+  domElementParent.appendChild(domElementOption);
+  return true;
+}
+
+
 bool KEduVocKvtmlWriter::writeType(QDomDocument &domDoc, QDomElement &domElementParent)
 {
-  if (m_doc->m_typeDescriptions.size() == 0)
+  if (m_doc->typeDescriptions().count() == 0)
     return true;
 
   QDomElement domElementType = domDoc.createElement(KV_TYPE_GRP);
+  int count = 1;
 
-  for (int lfn = 0; lfn < (int) m_doc->m_typeDescriptions.size(); lfn++)
+  foreach(QString type, m_doc->typeDescriptions())
   {
-    if (!(m_doc->m_typeDescriptions[lfn].isNull()) )
+    if (!(type.isNull()) )
     {
       QDomElement domElementDesc = domDoc.createElement(KV_TYPE_DESC);
-      QDomText domTextDesc = domDoc.createTextNode(m_doc->m_typeDescriptions[lfn]);
+      QDomText domTextDesc = domDoc.createTextNode(type);
 
-      domElementDesc.setAttribute(KV_TYPE_NO, lfn+1);
+      domElementDesc.setAttribute(KV_TYPE_NO, count);
       domElementDesc.appendChild(domTextDesc);
       domElementType.appendChild(domElementDesc);
+      count++;
     }
   }
 
@@ -506,20 +480,22 @@ bool KEduVocKvtmlWriter::writeType(QDomDocument &domDoc, QDomElement &domElement
 
 bool KEduVocKvtmlWriter::writeTense(QDomDocument &domDoc, QDomElement &domElementParent)
 {
-  if (m_doc->m_tenseDescriptions.size() == 0)
+  if (m_doc->tenseDescriptions().count() == 0)
     return true;
 
   QDomElement domElementTense = domDoc.createElement(KV_TENSE_GRP);
+  int count = 1;
 
-  for (int lfn = 0; lfn < (int) m_doc->m_tenseDescriptions.size(); lfn++)
+  foreach(QString tense, m_doc->tenseDescriptions())
   {
-    if (!(m_doc->m_tenseDescriptions[lfn].isNull()) ) {
+    if (!(tense.isNull())) {
       QDomElement domElementDesc = domDoc.createElement(KV_TENSE_DESC);
-      QDomText domTextDesc = domDoc.createTextNode(m_doc->m_tenseDescriptions[lfn]);
+      QDomText domTextDesc = domDoc.createTextNode(tense);
 
-      domElementDesc.setAttribute(KV_TENSE_NO, lfn+1);
+      domElementDesc.setAttribute(KV_TENSE_NO, count);
       domElementDesc.appendChild(domTextDesc);
       domElementTense.appendChild(domElementDesc);
+      count++;
     }
   }
 
@@ -530,21 +506,23 @@ bool KEduVocKvtmlWriter::writeTense(QDomDocument &domDoc, QDomElement &domElemen
 
 bool KEduVocKvtmlWriter::writeUsage(QDomDocument &domDoc, QDomElement &domElementParent)
 {
-  if (m_doc->m_usageDescriptions.size() == 0)
+  if (m_doc->usageDescriptions().count() == 0)
     return true;
 
   QDomElement domElementUsage = domDoc.createElement(KV_USAGE_GRP);
+  int count = 1;
 
-  for (int lfn = 0; lfn < (int) m_doc->m_usageDescriptions.size(); lfn++)
+  foreach(QString usage, m_doc->usageDescriptions())
   {
-    if (!(m_doc->m_usageDescriptions[lfn].isNull()) )
+    if (!(usage.isNull()))
     {
       QDomElement domElementDesc = domDoc.createElement(KV_USAGE_DESC);
-      QDomText domTextDesc = domDoc.createTextNode(m_doc->m_usageDescriptions[lfn]);
+      QDomText domTextDesc = domDoc.createTextNode(usage);
 
-      domElementDesc.setAttribute(KV_USAGE_NO, lfn+1);
+      domElementDesc.setAttribute(KV_USAGE_NO, count);
       domElementDesc.appendChild(domTextDesc);
       domElementUsage.appendChild(domElementDesc);
+      count++;
     }
   }
 
@@ -553,166 +531,6 @@ bool KEduVocKvtmlWriter::writeUsage(QDomDocument &domDoc, QDomElement &domElemen
 }
 
 
-bool KEduVocKvtmlWriter::writeConjug(QDomDocument &domDoc, QDomElement &domElementParent, const KEduVocConjugation &curr_conjug, const QString &type)
-{
-  if (!curr_conjug.pers1Singular(type).isEmpty() )
-  {
-    QDomElement domElementP1s = domDoc.createElement(KV_CON_P1S);
-    QDomText domTextP1s = domDoc.createTextNode(curr_conjug.pers1Singular(type));
-
-    domElementP1s.appendChild(domTextP1s);
-    domElementParent.appendChild(domElementP1s);
-  }
-
-  if (!curr_conjug.pers2Singular(type).isEmpty() )
-  {
-    QDomElement domElementP2s = domDoc.createElement(KV_CON_P2S);
-    QDomText domTextP2s = domDoc.createTextNode(curr_conjug.pers2Singular(type));
-
-    domElementP2s.appendChild(domTextP2s);
-    domElementParent.appendChild(domElementP2s);
-  }
-
-  if (!curr_conjug.pers3FemaleSingular(type).isEmpty() ||
-    curr_conjug.pers3SingularCommon(type))
-  {
-    QDomElement domElementP3sf = domDoc.createElement(KV_CON_P3SF);
-    QDomText domTextP3sf = domDoc.createTextNode(curr_conjug.pers3FemaleSingular(type));
-
-    if (curr_conjug.pers3SingularCommon(type))
-      domElementP3sf.setAttribute(KV_CONJ_COMMON, 1);
-
-    domElementP3sf.appendChild(domTextP3sf);
-    domElementParent.appendChild(domElementP3sf);
-  }
-
-  if (!curr_conjug.pers3MaleSingular(type).isEmpty() )
-  {
-    QDomElement domElementP3sm = domDoc.createElement(KV_CON_P3SM);
-    QDomText domTextP3sm = domDoc.createTextNode(curr_conjug.pers3MaleSingular(type));
-
-    domElementP3sm.appendChild(domTextP3sm);
-    domElementParent.appendChild(domElementP3sm);
-  }
-
-  if (!curr_conjug.pers3NaturalSingular(type).isEmpty() )
-  {
-    QDomElement domElementP3sn = domDoc.createElement(KV_CON_P3SN);
-    QDomText domTextP3sn = domDoc.createTextNode(curr_conjug.pers3NaturalSingular(type));
-
-    domElementP3sn.appendChild(domTextP3sn);
-    domElementParent.appendChild(domElementP3sn);
-  }
-
-  if (!curr_conjug.pers1Plural(type).isEmpty() )
-  {
-    QDomElement domElementP1p = domDoc.createElement(KV_CON_P1P);
-    QDomText domTextP1p = domDoc.createTextNode(curr_conjug.pers1Plural(type));
-
-    domElementP1p.appendChild(domTextP1p);
-    domElementParent.appendChild(domElementP1p);
-  }
-
-  if (!curr_conjug.pers2Plural(type).isEmpty() )
-  {
-    QDomElement domElementP2p = domDoc.createElement(KV_CON_P2P);
-    QDomText domTextP2p = domDoc.createTextNode(curr_conjug.pers2Plural(type));
-
-    domElementP2p.appendChild(domTextP2p);
-    domElementParent.appendChild(domElementP2p);
-  }
-
-  if (!curr_conjug.pers3FemalePlural(type).isEmpty() ||
-    curr_conjug.pers3PluralCommon(type))
-  {
-    QDomElement domElementP3pf = domDoc.createElement(KV_CON_P3PF);
-    QDomText domTextP3pf = domDoc.createTextNode(curr_conjug.pers3FemalePlural(type));
-
-    if (curr_conjug.pers3PluralCommon(type))
-      domElementP3pf.setAttribute(KV_CONJ_COMMON, 1);
-
-    domElementP3pf.appendChild(domTextP3pf);
-    domElementParent.appendChild(domElementP3pf);
-  }
-
-  if (!curr_conjug.pers3MalePlural(type).isEmpty() )
-  {
-    QDomElement domElementP3pm = domDoc.createElement(KV_CON_P3PM);
-    QDomText domTextP3pm = domDoc.createTextNode(curr_conjug.pers3MalePlural(type));
-
-    domElementP3pm.appendChild(domTextP3pm);
-    domElementParent.appendChild(domElementP3pm);
-  }
-
-  if (!curr_conjug.pers3NaturalPlural(type).isEmpty() )
-  {
-    QDomElement domElementP3pn = domDoc.createElement(KV_CON_P3PN);
-    QDomText domTextP3pn = domDoc.createTextNode(curr_conjug.pers3NaturalPlural(type));
-
-    domElementP3pn.appendChild(domTextP3pn);
-    domElementParent.appendChild(domElementP3pn);
-  }
-
-  return true;
-}
-
-bool KEduVocKvtmlWriter::writeConjugHeader(QDomDocument &domDoc, QDomElement &domElementParent, QList<KEduVocConjugation> &curr_conjug)
-{
-/*
- <conjugation>    used in header for definiton of "prefix"
-  <e l="de">      lang determines also lang order in entries !!
-   <s1>I</s1>     which must NOT differ
-   <s2>you<2>
-   <s3f common="0">he</s3f>
-   <s3m>she</s3m>
-   <s3n>it</s3n>
-   <p1>we</p1>
-   <p2>you</p2>
-   <p3f common="1">they</p3f>
-   <p3m>they</p3m>
-   <p3n>they</p3n>
-  </e>
- </conjugation>
-
-*/
-  if (curr_conjug.size() == 0)
-    return true;
-
-  QDomElement domElementConjug = domDoc.createElement(KV_CONJUG_GRP);
-  QString s;
-
-  for (int ent = 0; ent < qMin((int) curr_conjug.size(), m_doc->numIdentifiers()); ent++)
-  {
-    QDomElement domElementEntry = domDoc.createElement(KV_CON_ENTRY);
-
-    if (ent == 0)
-    {
-      s = m_doc->originalIdentifier().simplified();  //EPT le Ident doit �re superflu
-      if (s.isEmpty() )
-        s = "original";
-    }
-    else
-    {
-      s = m_doc->identifier(ent).simplified();
-      if (s.isEmpty() )
-      {
-        s.setNum(ent);
-        s.insert(0, "translation ");
-      }
-    }
-    domElementEntry.setAttribute(KV_LANG, s);
-
-    if (!writeConjug(domDoc, domElementEntry, curr_conjug[ent], CONJ_PREFIX))
-      return false;
-
-    domElementConjug.appendChild(domElementEntry);
-  }
-
-  domElementParent.appendChild(domElementConjug);
-  return true;
-}
-
-
 bool KEduVocKvtmlWriter::writeComparison(QDomDocument &domDoc, QDomElement &domElementParent, const KEduVocComparison &comp)
 /*
  <comparison>
@@ -825,6 +643,63 @@ bool KEduVocKvtmlWriter::writeMultipleChoice(QDomDocument &domDoc, QDomElement &
 }
 
 
+bool KEduVocKvtmlWriter::writeConjugHeader(QDomDocument &domDoc, QDomElement &domElementParent, QList<KEduVocConjugation> &curr_conjug)
+{
+/*
+ <conjugation>    used in header for definiton of "prefix"
+  <e l="de">      lang determines also lang order in entries !!
+   <s1>I</s1>     which must NOT differ
+   <s2>you<2>
+   <s3f common="0">he</s3f>
+   <s3m>she</s3m>
+   <s3n>it</s3n>
+   <p1>we</p1>
+   <p2>you</p2>
+   <p3f common="1">they</p3f>
+   <p3m>they</p3m>
+   <p3n>they</p3n>
+  </e>
+ </conjugation>
+
+*/
+  if (curr_conjug.size() == 0)
+    return true;
+
+  QDomElement domElementConjug = domDoc.createElement(KV_CONJUG_GRP);
+  QString s;
+
+  for (int ent = 0; ent < qMin(curr_conjug.count(), m_doc->numIdentifiers()); ent++)
+  {
+    QDomElement domElementEntry = domDoc.createElement(KV_CON_ENTRY);
+
+    if (ent == 0)
+    {
+      s = m_doc->originalIdentifier().simplified();
+      if (s.isEmpty())
+        s = "original";
+    }
+    else
+    {
+      s = m_doc->identifier(ent).simplified();
+      if (s.isEmpty())
+      {
+        s.setNum(ent);
+        s.prepend("translation ");
+      }
+    }
+    domElementEntry.setAttribute(KV_LANG, s);
+
+    if (!writeConjug(domDoc, domElementEntry, curr_conjug[ent], CONJ_PREFIX))
+      return false;
+
+    domElementConjug.appendChild(domElementEntry);
+  }
+
+  domElementParent.appendChild(domElementConjug);
+  return true;
+}
+
+
 bool KEduVocKvtmlWriter::writeConjugEntry(QDomDocument &domDoc, QDomElement &domElementParent, KEduVocConjugation &curr_conjug)
 /*
  <conjugation>    in entry for definition of tenses of (irreg.) verbs
@@ -850,14 +725,14 @@ bool KEduVocKvtmlWriter::writeConjugEntry(QDomDocument &domDoc, QDomElement &dom
   QDomElement domElementConjug = domDoc.createElement(KV_CONJUG_GRP);
   QString type;
 
-  for (int lfn = 0; lfn < (int) curr_conjug.numEntries(); lfn++)
+  for (int lfn = 0; lfn < curr_conjug.numEntries(); lfn++)
   {
     QDomElement domElementType = domDoc.createElement(KV_CON_TYPE);
 
     type = curr_conjug.getType(lfn);
     domElementType.setAttribute(KV_CON_NAME, type);
 
-    if (!writeConjug(domDoc, domElementType, curr_conjug, curr_conjug.getType(lfn)) )
+    if (!writeConjug(domDoc, domElementType, curr_conjug, curr_conjug.getType(lfn)))
       return false;
 
     domElementConjug.appendChild(domElementType);
@@ -868,15 +743,103 @@ bool KEduVocKvtmlWriter::writeConjugEntry(QDomDocument &domDoc, QDomElement &dom
 }
 
 
-bool KEduVocKvtmlWriter::writeOption(QDomDocument &domDoc, QDomElement &domElementParent)
+bool KEduVocKvtmlWriter::writeConjug(QDomDocument &domDoc, QDomElement &domElementParent, const KEduVocConjugation &curr_conjug, const QString &type)
 {
-  QDomElement domElementOption = domDoc.createElement(KV_OPTION_GRP);
-  QDomElement domElementSort = domDoc.createElement(KV_OPT_SORT);
+  if (!curr_conjug.pers1Singular(type).isEmpty())
+  {
+    QDomElement domElementP1s = domDoc.createElement(KV_CON_P1S);
+    QDomText domTextP1s = domDoc.createTextNode(curr_conjug.pers1Singular(type));
 
-  domElementSort.setAttribute(KV_BOOL_FLAG, (m_doc->isSortingEnabled()?1:0));
-  domElementOption.appendChild(domElementSort);
+    domElementP1s.appendChild(domTextP1s);
+    domElementParent.appendChild(domElementP1s);
+  }
+
+  if (!curr_conjug.pers2Singular(type).isEmpty())
+  {
+    QDomElement domElementP2s = domDoc.createElement(KV_CON_P2S);
+    QDomText domTextP2s = domDoc.createTextNode(curr_conjug.pers2Singular(type));
+
+    domElementP2s.appendChild(domTextP2s);
+    domElementParent.appendChild(domElementP2s);
+  }
+
+  if (!curr_conjug.pers3FemaleSingular(type).isEmpty() || curr_conjug.pers3SingularCommon(type))
+  {
+    QDomElement domElementP3sf = domDoc.createElement(KV_CON_P3SF);
+    QDomText domTextP3sf = domDoc.createTextNode(curr_conjug.pers3FemaleSingular(type));
+
+    if (curr_conjug.pers3SingularCommon(type))
+      domElementP3sf.setAttribute(KV_CONJ_COMMON, 1);
+
+    domElementP3sf.appendChild(domTextP3sf);
+    domElementParent.appendChild(domElementP3sf);
+  }
+
+  if (!curr_conjug.pers3MaleSingular(type).isEmpty())
+  {
+    QDomElement domElementP3sm = domDoc.createElement(KV_CON_P3SM);
+    QDomText domTextP3sm = domDoc.createTextNode(curr_conjug.pers3MaleSingular(type));
+
+    domElementP3sm.appendChild(domTextP3sm);
+    domElementParent.appendChild(domElementP3sm);
+  }
+
+  if (!curr_conjug.pers3NaturalSingular(type).isEmpty())
+  {
+    QDomElement domElementP3sn = domDoc.createElement(KV_CON_P3SN);
+    QDomText domTextP3sn = domDoc.createTextNode(curr_conjug.pers3NaturalSingular(type));
+
+    domElementP3sn.appendChild(domTextP3sn);
+    domElementParent.appendChild(domElementP3sn);
+  }
+
+  if (!curr_conjug.pers1Plural(type).isEmpty())
+  {
+    QDomElement domElementP1p = domDoc.createElement(KV_CON_P1P);
+    QDomText domTextP1p = domDoc.createTextNode(curr_conjug.pers1Plural(type));
+
+    domElementP1p.appendChild(domTextP1p);
+    domElementParent.appendChild(domElementP1p);
+  }
+
+  if (!curr_conjug.pers2Plural(type).isEmpty())
+  {
+    QDomElement domElementP2p = domDoc.createElement(KV_CON_P2P);
+    QDomText domTextP2p = domDoc.createTextNode(curr_conjug.pers2Plural(type));
+
+    domElementP2p.appendChild(domTextP2p);
+    domElementParent.appendChild(domElementP2p);
+  }
+
+  if (!curr_conjug.pers3FemalePlural(type).isEmpty() || curr_conjug.pers3PluralCommon(type))
+  {
+    QDomElement domElementP3pf = domDoc.createElement(KV_CON_P3PF);
+    QDomText domTextP3pf = domDoc.createTextNode(curr_conjug.pers3FemalePlural(type));
+
+    if (curr_conjug.pers3PluralCommon(type))
+      domElementP3pf.setAttribute(KV_CONJ_COMMON, 1);
+
+    domElementP3pf.appendChild(domTextP3pf);
+    domElementParent.appendChild(domElementP3pf);
+  }
+
+  if (!curr_conjug.pers3MalePlural(type).isEmpty())
+  {
+    QDomElement domElementP3pm = domDoc.createElement(KV_CON_P3PM);
+    QDomText domTextP3pm = domDoc.createTextNode(curr_conjug.pers3MalePlural(type));
+
+    domElementP3pm.appendChild(domTextP3pm);
+    domElementParent.appendChild(domElementP3pm);
+  }
+
+  if (!curr_conjug.pers3NaturalPlural(type).isEmpty())
+  {
+    QDomElement domElementP3pn = domDoc.createElement(KV_CON_P3PN);
+    QDomText domTextP3pn = domDoc.createTextNode(curr_conjug.pers3NaturalPlural(type));
+
+    domElementP3pn.appendChild(domTextP3pn);
+    domElementParent.appendChild(domElementP3pn);
+  }
 
-  domElementParent.appendChild(domElementOption);
   return true;
 }
-
index a234253e5d4fc0cfda71449dede4a8d8185b409a..ef6f8a52070698cd95096da5989250afce7d7c61 100644 (file)
@@ -25,7 +25,6 @@
 #include <QtXml/QDomDocument>
 #include <QList>
 
-//#include "keduvocdocument.h"
 #include "keduvocgrammar.h"
 #include "keduvocmultiplechoice.h"
 
@@ -86,12 +85,9 @@ public:
   bool writeComparison(QDomDocument &domDoc, QDomElement &domElementParent, const KEduVocComparison &comp);
   bool writeMultipleChoice(QDomDocument &domDoc, QDomElement &domElementParent, const KEduVocMultipleChoice &mc);
 
-  QString errorMessage() const { return m_errorMessage; };
-
 private:
   QFile *m_outputFile;
   KEduVocDocument *m_doc;
-  QString m_errorMessage;
 };
 
 #endif