]> Git trees. - libqmvoc.git/commitdiff
move more into the translation class
authorFrederik Gladhorn <gladhorn@kde.org>
Sun, 24 Feb 2008 20:06:02 +0000 (20:06 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Sun, 24 Feb 2008 20:06:02 +0000 (20:06 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=778877

keduvocdocument/keduvockvtml2writer.cpp
keduvocdocument/keduvockvtml2writer.h
keduvocdocument/keduvoctranslation.cpp

index 1e2317d82f72ecc7b1627f1b95b32c5957a6a393..d2ed9a5ceac3960fcc7e9798aa38d205eff74fbc 100644 (file)
@@ -376,18 +376,6 @@ bool KEduVocKvtml2Writer::writeTranslation( QDomElement &translationElement, KEd
     // so far only for KEduVocWord - text and grades
     translation->toKVTML2(translationElement);
 
-    ///@todo move into translation->toXML()
-
-    // <comment></comment>
-    if ( !translation->comment().isEmpty() ) {
-        translationElement.appendChild( newTextElement( KVTML_COMMENT, translation->comment() ) );
-    }
-
-    // <pronunciation></pronunciation>
-    if ( !translation->pronunciation().isEmpty() ) {
-        translationElement.appendChild( newTextElement( KVTML_PRONUNCIATION, translation->pronunciation() ) );
-    }
-
     // <falsefriend fromid="0"></falsefriend>
     // loop through the identifiers
     for ( int i = 0; i < m_doc->identifierCount(); ++i ) {
@@ -401,26 +389,6 @@ bool KEduVocKvtml2Writer::writeTranslation( QDomElement &translationElement, KEd
         }
     }
 
-    // <antonym></antonym>
-    if ( !translation->antonym().isEmpty() ) {
-        translationElement.appendChild( newTextElement( KVTML_ANTONYM, translation->antonym() ) );
-    }
-
-    // <synonym></synonym>
-    if ( !translation->synonym().isEmpty() ) {
-        translationElement.appendChild( newTextElement( KVTML_SYNONYM, translation->synonym() ) );
-    }
-
-    // <example></example>
-    if ( !translation->example().isEmpty() ) {
-        translationElement.appendChild( newTextElement( KVTML_EXAMPLE, translation->example() ) );
-    }
-
-    // <paraphrase></paraphrase>
-    if ( !translation->paraphrase().isEmpty() ) {
-        translationElement.appendChild( newTextElement( KVTML_PARAPHRASE, translation->paraphrase() ) );
-    }
-
     // conjugation
     foreach ( const QString &tense, translation->conjugationTenses() ) {
         QDomElement thisElement = m_domDoc.createElement( KVTML_CONJUGATION );
@@ -616,6 +584,11 @@ bool KEduVocKvtml2Writer::writePersonalPronoun(QDomElement & pronounElement, con
 
 void KEduVocKvtml2Writer::appendTextElement(QDomElement & parent, const QString & elementName, const QString & text)
 {
+    // empty will never be written
+    if (text.isEmpty()) {
+        return;
+    }
+
     QDomDocument domDoc = parent.ownerDocument();
     QDomElement element = domDoc.createElement( elementName );
     parent.appendChild( element );
index 3f09718b23c8a92b066b884b0ba15d4019484988..75f011320e7e6146db65bdc2de509928d0ced2c8 100644 (file)
@@ -112,6 +112,13 @@ public:
      */
     bool writeMultipleChoice( QDomElement &multipleChoiceElement, KEduVocTranslation* translation );
 
+    /**
+     * Helper function, appends a new element AND a text child to @p parent
+     * Only appends if @p text is NOT empty.
+     * @param parent 
+     * @param elementName 
+     * @param text 
+     */
     static void appendTextElement( QDomElement &parent, const QString &elementName, const QString &text );
 
 private:
index 5bae3c8d30b4ea09bbcc9a9c5673e2c38d17f3c7..9016377825783369d6fef0a504e0405e41a0160b 100644 (file)
 
 #include "keduvoctranslation.h"
 
-#include <QtCore/QMap>
-
-#include <KDebug>
-
 #include "keduvocdeclension.h"
 #include "keduvocwordtype.h"
+#include "kvtml2defs.h"
+#include "keduvockvtml2writer.h"
+#include <KDebug>
+#include <QtCore/QMap>
 
 class KEduVocTranslation::KEduVocTranslationPrivate
 {
@@ -360,10 +360,27 @@ void KEduVocTranslation::setDeclension(KEduVocDeclension * declension)
 
 void KEduVocTranslation::toKVTML2(QDomElement & parent)
 {
-    kDebug() << "Write translation xml.";
     KEduVocText::toKVTML2(parent);
     if (d->m_declension) {
         d->m_declension->toKVTML2(parent);
     }
+
+    // <comment>
+    KEduVocKvtml2Writer::appendTextElement( parent, KVTML_COMMENT, comment() );
+
+    // <pronunciation>
+    KEduVocKvtml2Writer::appendTextElement( parent, KVTML_PRONUNCIATION, pronunciation() );
+
+    // <antonym>
+    KEduVocKvtml2Writer::appendTextElement( parent, KVTML_ANTONYM, antonym() );
+
+    // <synonym>
+    KEduVocKvtml2Writer::appendTextElement( parent, KVTML_SYNONYM, synonym() );
+
+    // <example>
+    KEduVocKvtml2Writer::appendTextElement( parent, KVTML_EXAMPLE, example() );
+
+    // <paraphrase>
+    KEduVocKvtml2Writer::appendTextElement( parent, KVTML_PARAPHRASE, paraphrase() );
 }