From 913e8a451b5e5554c867d876ae7acfc78c118b61 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Sun, 24 Feb 2008 20:06:02 +0000 Subject: [PATCH] move more into the translation class svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=778877 --- keduvocdocument/keduvockvtml2writer.cpp | 37 ++++--------------------- keduvocdocument/keduvockvtml2writer.h | 7 +++++ keduvocdocument/keduvoctranslation.cpp | 27 ++++++++++++++---- 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/keduvocdocument/keduvockvtml2writer.cpp b/keduvocdocument/keduvockvtml2writer.cpp index 1e2317d..d2ed9a5 100644 --- a/keduvocdocument/keduvockvtml2writer.cpp +++ b/keduvocdocument/keduvockvtml2writer.cpp @@ -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() - - // - if ( !translation->comment().isEmpty() ) { - translationElement.appendChild( newTextElement( KVTML_COMMENT, translation->comment() ) ); - } - - // - if ( !translation->pronunciation().isEmpty() ) { - translationElement.appendChild( newTextElement( KVTML_PRONUNCIATION, translation->pronunciation() ) ); - } - // // loop through the identifiers for ( int i = 0; i < m_doc->identifierCount(); ++i ) { @@ -401,26 +389,6 @@ bool KEduVocKvtml2Writer::writeTranslation( QDomElement &translationElement, KEd } } - // - if ( !translation->antonym().isEmpty() ) { - translationElement.appendChild( newTextElement( KVTML_ANTONYM, translation->antonym() ) ); - } - - // - if ( !translation->synonym().isEmpty() ) { - translationElement.appendChild( newTextElement( KVTML_SYNONYM, translation->synonym() ) ); - } - - // - if ( !translation->example().isEmpty() ) { - translationElement.appendChild( newTextElement( KVTML_EXAMPLE, translation->example() ) ); - } - - // - 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 ); diff --git a/keduvocdocument/keduvockvtml2writer.h b/keduvocdocument/keduvockvtml2writer.h index 3f09718..75f0113 100644 --- a/keduvocdocument/keduvockvtml2writer.h +++ b/keduvocdocument/keduvockvtml2writer.h @@ -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: diff --git a/keduvocdocument/keduvoctranslation.cpp b/keduvocdocument/keduvoctranslation.cpp index 5bae3c8..9016377 100644 --- a/keduvocdocument/keduvoctranslation.cpp +++ b/keduvocdocument/keduvoctranslation.cpp @@ -17,12 +17,12 @@ #include "keduvoctranslation.h" -#include - -#include - #include "keduvocdeclension.h" #include "keduvocwordtype.h" +#include "kvtml2defs.h" +#include "keduvockvtml2writer.h" +#include +#include 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); } + + // + KEduVocKvtml2Writer::appendTextElement( parent, KVTML_COMMENT, comment() ); + + // + KEduVocKvtml2Writer::appendTextElement( parent, KVTML_PRONUNCIATION, pronunciation() ); + + // + KEduVocKvtml2Writer::appendTextElement( parent, KVTML_ANTONYM, antonym() ); + + // + KEduVocKvtml2Writer::appendTextElement( parent, KVTML_SYNONYM, synonym() ); + + // + KEduVocKvtml2Writer::appendTextElement( parent, KVTML_EXAMPLE, example() ); + + // + KEduVocKvtml2Writer::appendTextElement( parent, KVTML_PARAPHRASE, paraphrase() ); } -- 2.47.3