• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeedu
  • Sitemap
  • Contact Us
 

libkdeedu/keduvocdocument

keduvoctranslation.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                         Vocabulary Expression Translation for KDE Edu
00003     -----------------------------------------------------------------------
00004 
00005     Copyright 2007-2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *   This program is free software; you can redistribute it and/or modify  *
00011  *   it under the terms of the GNU General Public License as published by  *
00012  *   the Free Software Foundation; either version 2 of the License, or     *
00013  *   (at your option) any later version.                                   *
00014  *                                                                         *
00015  ***************************************************************************/
00016 
00017 
00018 #include "keduvoctranslation.h"
00019 
00020 #include "keduvocdeclension.h"
00021 #include "keduvocwordtype.h"
00022 #include "keduvocleitnerbox.h"
00023 #include "kvtml2defs.h"
00024 #include "keduvockvtml2writer.h"
00025 #include <KDebug>
00026 #include <QtCore/QMap>
00027 #include <assert.h>
00028 
00029 class KEduVocTranslation::KEduVocTranslationPrivate
00030 {
00031 public:
00032     KEduVocTranslationPrivate(KEduVocExpression* parent);
00033 
00034     ~KEduVocTranslationPrivate();
00035 
00036     KEduVocExpression* m_entry;
00037 
00039     KEduVocWordType* m_wordType;
00040 
00042     KEduVocLeitnerBox* m_leitnerBox;
00043 
00045     QString m_comment;
00047     QString m_hint;
00049     QString m_paraphrase;
00051     QString m_example;
00053     QString m_pronunciation;
00055     KUrl m_imageUrl;
00057     KUrl m_soundUrl;
00058 
00060     QStringList m_multipleChoice;
00061 
00063     QMap <QString, KEduVocConjugation> m_conjugations;
00064 
00066     QString m_comparative;
00067     QString m_superlative;
00068 
00069     KEduVocDeclension* m_declension;
00070 
00071     // connections to other translations
00073     QList< KEduVocTranslation* > m_synonyms;
00075     QList< KEduVocTranslation* > m_antonyms;
00077     QList< KEduVocTranslation* > m_falseFriends;
00078 };
00079 
00080 KEduVocTranslation::KEduVocTranslationPrivate::KEduVocTranslationPrivate(KEduVocExpression* parent)
00081 {
00082     m_entry = parent;
00083     m_wordType = 0;
00084     m_leitnerBox = 0;
00085     m_declension = 0;
00086 }
00087 
00088 
00089 KEduVocTranslation::KEduVocTranslationPrivate::~ KEduVocTranslationPrivate()
00090 {
00091     delete m_declension;
00092 }
00093 
00094 KEduVocTranslation::KEduVocTranslation(KEduVocExpression* entry) : d( new KEduVocTranslationPrivate(entry) )
00095 {
00096 
00097     assert(d);
00098 
00099 }
00100 
00101 
00102 KEduVocTranslation::KEduVocTranslation(KEduVocExpression* entry, const QString &translation ) : d( new KEduVocTranslationPrivate(entry) )
00103 {
00104     setText(translation.simplified());
00105 
00106     assert(d);
00107 
00108 }
00109 
00110 KEduVocTranslation::KEduVocTranslation( const KEduVocTranslation &other )
00111     : KEduVocText(other),
00112     // set the entry to 0, the translation will be put into a copied entry by the expression copy constructor
00113     d( new KEduVocTranslationPrivate(0) )
00114 {
00115     // beter no word type copy as this is pointer copying
00116     // will not work as this is not added to the word type container!
00117 //  d->m_wordType = other.d->m_wordType;
00118 //  d->m_leitnerBox = translation.d->m_leitnerBox;
00119     d->m_comment = other.d->m_comment;
00120     d->m_paraphrase = other.d->m_paraphrase;
00121     d->m_example = other.d->m_example;
00122     d->m_pronunciation = other.d->m_pronunciation;
00123     d->m_conjugations = other.d->m_conjugations;
00124     d->m_comparative = other.d->m_comparative;
00125     d->m_superlative = other.d->m_superlative;
00126     d->m_multipleChoice = other.d->m_multipleChoice;
00127     d->m_imageUrl = other.d->m_imageUrl;
00128     d->m_soundUrl = other.d->m_soundUrl;
00129 //  no copies of the following for now. we don't know enough to also add this as synonym/etc
00130 //  d->m_synonyms = other.d->m_synonyms;
00131 //  d->m_antonyms = other.d->m_antonyms;
00132 //  d->m_falseFriends = other.d->m_falseFriends;
00133     if (other.d->m_declension) {
00134         d->m_declension = new KEduVocDeclension(*other.d->m_declension);
00135     }
00136 
00137  assert(d);
00138 
00139 }
00140 
00141 KEduVocTranslation::~KEduVocTranslation()
00142 {
00143     setWordType(0);
00144     setLeitnerBox(0);
00145     foreach (KEduVocTranslation *synonym, d->m_synonyms) {
00146         synonym->removeSynonym(this);
00147     }
00148     foreach (KEduVocTranslation *antonym, d->m_antonyms) {
00149         antonym->removeAntonym(this);
00150     }
00151     foreach (KEduVocTranslation *falseFriend, d->m_falseFriends) {
00152         falseFriend->removeFalseFriend(this);
00153     }
00154     delete d;
00155 }
00156 
00157 bool KEduVocTranslation::operator == ( const KEduVocTranslation & translation ) const
00158 {
00159     return KEduVocText::operator==(translation) &&
00160         d->m_wordType == translation.d->m_wordType &&
00161         d->m_leitnerBox == translation.d->m_leitnerBox &&
00162         d->m_comment == translation.d->m_comment &&
00163         d->m_paraphrase == translation.d->m_paraphrase &&
00164         d->m_example == translation.d->m_example &&
00165         d->m_pronunciation == translation.d->m_pronunciation &&
00166         d->m_imageUrl == translation.d->m_imageUrl &&
00167         d->m_soundUrl == translation.d->m_soundUrl &&
00168         d->m_comparative == translation.d->m_comparative &&
00169         d->m_superlative == translation.d->m_superlative &&
00170         d->m_multipleChoice == translation.d->m_multipleChoice &&
00171         d->m_synonyms == translation.d->m_synonyms &&
00172         d->m_antonyms == translation.d->m_antonyms &&
00173         d->m_falseFriends == translation.d->m_falseFriends &&
00174         d->m_conjugations == translation.d->m_conjugations;
00176 }
00177 
00178 KEduVocTranslation & KEduVocTranslation::operator = ( const KEduVocTranslation & translation )
00179 {
00180     KEduVocText::operator=(translation);
00181     d->m_entry = translation.d->m_entry;
00182 //     d->m_wordType = translation.d->m_wordType;
00183 //     d->m_leitnerBox = translation.d->m_leitnerBox;
00184     d->m_comment = translation.d->m_comment;
00185     d->m_paraphrase = translation.d->m_paraphrase;
00186     d->m_example = translation.d->m_example;
00187     d->m_pronunciation = translation.d->m_pronunciation;
00188     d->m_imageUrl = translation.d->m_imageUrl;
00189     d->m_soundUrl = translation.d->m_soundUrl;
00190     d->m_comparative = translation.d->m_comparative;
00191     d->m_superlative = translation.d->m_superlative;
00192     d->m_multipleChoice = translation.d->m_multipleChoice;
00193     d->m_falseFriends = translation.d->m_falseFriends;
00194     d->m_synonyms = translation.d->m_synonyms;
00195     d->m_antonyms = translation.d->m_antonyms;
00196     d->m_conjugations = translation.d->m_conjugations;
00197     if (translation.d->m_declension) {
00198         d->m_declension = new KEduVocDeclension(*translation.d->m_declension);
00199     }
00200 
00201     assert(d);
00202 
00203     return *this;
00204 }
00205 
00206 
00207 QString KEduVocTranslation::comment() const
00208 {
00209     return d->m_comment;
00210 }
00211 
00212 
00213 void KEduVocTranslation::setComment( const QString & expr )
00214 {
00215     d->m_comment = expr.simplified();
00216 }
00217 
00218 
00219 void KEduVocTranslation::addFalseFriend( KEduVocTranslation* falseFriend )
00220 {
00221     d->m_falseFriends.append(falseFriend);
00222 }
00223 
00224 void KEduVocTranslation::removeFalseFriend(KEduVocTranslation * falseFriend)
00225 {
00226     d->m_falseFriends.removeAt(d->m_falseFriends.indexOf(falseFriend));
00227 }
00228 
00229 QList< KEduVocTranslation* > KEduVocTranslation::falseFriends() const
00230 {
00231     return d->m_falseFriends;
00232 }
00233 
00234 
00235 void KEduVocTranslation::addSynonym( KEduVocTranslation* synonym )
00236 {
00237     d->m_synonyms.append(synonym);
00238 }
00239 
00240 void KEduVocTranslation::removeSynonym(KEduVocTranslation * synonym)
00241 {
00242     d->m_synonyms.removeAt(d->m_synonyms.indexOf(synonym));
00243 }
00244 
00245 QList<KEduVocTranslation*> KEduVocTranslation::synonyms() const
00246 {
00247     return d->m_synonyms;
00248 }
00249 
00250 void KEduVocTranslation::addAntonym( KEduVocTranslation* antonym )
00251 {
00252     d->m_antonyms.append(antonym);
00253 }
00254 
00255 QList<KEduVocTranslation*> KEduVocTranslation::antonyms() const
00256 {
00257     return d->m_antonyms;
00258 }
00259 
00260 void KEduVocTranslation::removeAntonym(KEduVocTranslation * antonym)
00261 {
00262     d->m_antonyms.removeAt(d->m_antonyms.indexOf(antonym));
00263 }
00264 
00265 void KEduVocTranslation::setExample( const QString & expr )
00266 {
00267     d->m_example = expr.simplified();
00268 }
00269 
00270 
00271 QString KEduVocTranslation::example() const
00272 {
00273     return d->m_example;
00274 }
00275 
00276 
00277 void KEduVocTranslation::setParaphrase( const QString & expr )
00278 {
00279     d->m_paraphrase = expr.simplified();
00280 }
00281 
00282 
00283 QString KEduVocTranslation::paraphrase() const
00284 {
00285     return d->m_paraphrase;
00286 }
00287 
00288 
00289 void KEduVocTranslation::setConjugation( const QString& tense, const KEduVocConjugation& con )
00290 {
00291     d->m_conjugations[tense] = con;
00292 }
00293 
00294 
00295 KEduVocConjugation& KEduVocTranslation::conjugation( const QString& tense )
00296 {
00297     return d->m_conjugations[tense];
00298 }
00299 
00300 
00301 QStringList & KEduVocTranslation::multipleChoice()
00302 {
00303     return d->m_multipleChoice;
00304 }
00305 
00306 
00307 QString KEduVocTranslation::pronunciation() const
00308 {
00309     return d->m_pronunciation;
00310 }
00311 
00312 
00313 void KEduVocTranslation::setPronunciation( const QString & expr )
00314 {
00315     d->m_pronunciation = expr.simplified();
00316 }
00317 
00318 QStringList KEduVocTranslation::conjugationTenses() const
00319 {
00320     return d->m_conjugations.keys();
00321 }
00322 
00323 QMap< QString, KEduVocConjugation > KEduVocTranslation::conjugations() const
00324 {
00325     return d->m_conjugations;
00326 }
00327 
00328 void KEduVocTranslation::setConjugations(const QMap< QString, KEduVocConjugation > & conjugations)
00329 {
00330     d->m_conjugations = conjugations;
00331 }
00332 
00334 KUrl KEduVocTranslation::soundUrl()
00335 {
00336     return d->m_soundUrl;
00337 }
00338 
00341 void KEduVocTranslation::setSoundUrl(const KUrl &url)
00342 {
00343     d->m_soundUrl = url;
00344 }
00345 
00347 KUrl KEduVocTranslation::imageUrl()
00348 {
00349     return d->m_imageUrl;
00350 }
00351 
00355 void KEduVocTranslation::setImageUrl(const KUrl &url)
00356 {
00357     d->m_imageUrl = url;
00358 }
00359 
00360 KEduVocWordType * KEduVocTranslation::wordType() const
00361 {
00362     if (d)
00363         return d->m_wordType;
00364     else
00365         return 0;
00366 }
00367 
00368 void KEduVocTranslation::setWordType(KEduVocWordType * wordType)
00369 {
00370     if ( d->m_wordType ) {
00371         d->m_wordType->removeTranslation(this);
00372     }
00373     if ( wordType ) {
00374         wordType->addTranslation(this);
00375     }
00376     d->m_wordType = wordType;
00377 }
00378 
00379 KEduVocLeitnerBox * KEduVocTranslation::leitnerBox() const
00380 {
00381     return d->m_leitnerBox;
00382 }
00383 
00384 void KEduVocTranslation::setLeitnerBox(KEduVocLeitnerBox * leitnerBox)
00385 {
00386     if ( d->m_leitnerBox ) {
00387         d->m_leitnerBox->removeTranslation(this);
00388     }
00389     if ( leitnerBox ) {
00390         leitnerBox->addTranslation(this);
00391     }
00392     d->m_leitnerBox = leitnerBox;
00393 }
00394 
00395 KEduVocExpression * KEduVocTranslation::entry()
00396 {
00397     return d->m_entry;
00398 }
00399 
00400 QString KEduVocTranslation::comparative() const
00401 {
00402     return d->m_comparative;
00403 }
00404 
00405 void KEduVocTranslation::setComparative(const QString & comparative)
00406 {
00407     d->m_comparative = comparative;
00408 }
00409 
00410 QString KEduVocTranslation::superlative() const
00411 {
00412     return d->m_superlative;
00413 }
00414 
00415 void KEduVocTranslation::setSuperlative(const QString & superlative)
00416 {
00417     d->m_superlative = superlative;
00418 }
00419 
00420 KEduVocDeclension * KEduVocTranslation::declension()
00421 {
00422     return d->m_declension;
00423 }
00424 
00425 void KEduVocTranslation::setDeclension(KEduVocDeclension * declension)
00426 {
00427     // remove the old declension object
00428     delete d->m_declension;
00429     d->m_declension = declension;
00430 }
00431 
00432 void KEduVocTranslation::toKVTML2(QDomElement & parent)
00433 {
00434     // text and grade
00435     KEduVocText::toKVTML2(parent);
00436 
00437     // declension
00438     if (d->m_declension) {
00439         d->m_declension->toKVTML2(parent);
00440     }
00441 
00442     // conjugation
00443     foreach ( const QString &tense, conjugationTenses() ) {
00444         QDomElement conjugationElement = parent.ownerDocument().createElement( KVTML_CONJUGATION );
00445         conjugation(tense).toKVTML2(conjugationElement, tense);
00446         parent.appendChild( conjugationElement );
00447     }
00448 
00449     // <comment>
00450     KEduVocKvtml2Writer::appendTextElement( parent, KVTML_COMMENT, comment() );
00451 
00452     // <pronunciation>
00453     KEduVocKvtml2Writer::appendTextElement( parent, KVTML_PRONUNCIATION, pronunciation() );
00454 
00455     // <example>
00456     KEduVocKvtml2Writer::appendTextElement( parent, KVTML_EXAMPLE, example() );
00457 
00458     // <paraphrase>
00459     KEduVocKvtml2Writer::appendTextElement( parent, KVTML_PARAPHRASE, paraphrase() );
00460 
00463 }
00464 
00465 void KEduVocTranslation::fromKVTML2(QDomElement & parent)
00466 {
00467     KEduVocText::fromKVTML2(parent);
00468 
00469     setDeclension(KEduVocDeclension::fromKVTML2(parent));
00470 
00471     setComment( parent.firstChildElement( KVTML_COMMENT ).text() );
00472 
00473     setPronunciation( parent.firstChildElement( KVTML_PRONUNCIATION ).text() );
00474 
00475     //<example></example>
00476     setExample( parent.firstChildElement( KVTML_EXAMPLE ).text() );
00477 
00478     //<paraphrase></paraphrase>
00479     setParaphrase( parent.firstChildElement( KVTML_PARAPHRASE ).text() );
00480 
00481     // conjugations
00482     QDomElement conjugationElement = parent.firstChildElement( KVTML_CONJUGATION );
00483     while ( !conjugationElement.isNull() ) {
00484         QDomElement tenseElement = conjugationElement.firstChildElement( KVTML_TENSE );
00485         QString tense = tenseElement.text();
00486         KEduVocConjugation *conjugation = KEduVocConjugation::fromKVTML2(conjugationElement);
00487         setConjugation(tense, *conjugation);
00488         delete conjugation;
00489         conjugationElement = conjugationElement.nextSiblingElement( KVTML_CONJUGATION );
00490     }
00491 
00494 }
00495 
00496 void KEduVocTranslation::setEntry(KEduVocExpression * entry)
00497 {
00498     d->m_entry = entry;
00499 }
00500 
00501 
00502 

libkdeedu/keduvocdocument

Skip menu "libkdeedu/keduvocdocument"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeedu

Skip menu "kdeedu"
  • kalzium
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  •   docs
  •   src
  • parley
  •   stepcore
Generated for kdeedu by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal