]> Git trees. - libqmvoc.git/commitdiff
Change expression to contain a pointer to its translations and the translations have...
authorFrederik Gladhorn <gladhorn@kde.org>
Thu, 22 Nov 2007 22:46:07 +0000 (22:46 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Thu, 22 Nov 2007 22:46:07 +0000 (22:46 +0000)
Also translation now contain pointers to their word types represented by lessons.

svn path=/branches/work/kdeedu_parley/libkdeedu/; revision=740298

13 files changed:
keduvocdocument/keduvoccsvwriter.cpp
keduvocdocument/keduvocdocument.cpp
keduvocdocument/keduvocexpression.cpp
keduvocdocument/keduvocexpression.h
keduvocdocument/keduvockvtml2reader.cpp
keduvocdocument/keduvockvtml2reader.h
keduvocdocument/keduvockvtml2writer.cpp
keduvocdocument/keduvockvtml2writer.h
keduvocdocument/keduvoclesson.cpp
keduvocdocument/keduvoclesson.h
keduvocdocument/keduvoctranslation.cpp
keduvocdocument/keduvoctranslation.h
keduvocdocument/keduvocwordtype.h

index 191715874f4115506c9c6721c11a698821ef76c5..f6b7f9ab646399666d87022b029c7cb080b46f88 100644 (file)
@@ -64,7 +64,7 @@ bool KEduVocCsvWriter::writeDoc( KEduVocDocument *doc, const QString &generator
             else
                 currentRow += separator;
 
-            currentRow += expression->translation( i ).text();
+            currentRow += expression->translation( i )->text();
         }
 
         if ( !currentRow.isEmpty() )
index 249555993c35095603edd7af8b882a1373f4423f..dbf63ec05af5bfc6c6b5396db71b7d119afab7cd 100644 (file)
@@ -867,8 +867,8 @@ public:
         int cmp;
         foreach( int i, exp->translationIndices() ) {
 
-            s1 = exp->translation( i ).text();
-            s2 = y.exp->translation( i ).text();
+            s1 = exp->translation( i )->text();
+            s2 = y.exp->translation( i )->text();
             cmp = QString::compare( s1.toUpper(), s2.toUpper() );
             if ( cmp != 0 )
                 return cmp < 0;
index 4630cc5399a8620e48cfd6725ff24b5ab5a7b8b1..b30095c290d1ae4dff50944fcb36780f5e82a59f 100644 (file)
@@ -27,10 +27,9 @@ public:
     KEduVocExpressionPrivate( KEduVocExpression* qq )
             : q( qq )
     {
-        init();
+        m_active = true;
     }
-
-    void init();
+    ~KEduVocExpressionPrivate();
 
     bool operator== ( const KEduVocExpressionPrivate &p ) const;
 
@@ -39,14 +38,13 @@ public:
     QList<KEduVocLesson*> m_lessons;
     bool m_active;
 
-    QMap <int, KEduVocTranslation> m_translations;
+    QMap <int, KEduVocTranslation*> m_translations;
 };
 
 
-void KEduVocExpression::KEduVocExpressionPrivate::init()
+KEduVocExpression::KEduVocExpressionPrivate::~ KEduVocExpressionPrivate()
 {
-    m_translations.clear();
-    m_active = true;
+    qDeleteAll(m_translations);
 }
 
 
@@ -90,13 +88,11 @@ KEduVocExpression::~KEduVocExpression()
 
 void KEduVocExpression::removeTranslation( int index )
 {
-    d->m_translations.remove( index );
+    delete d->m_translations.take(index);
 
     for ( int j = index; j < d->m_translations.count(); j++ ) {
-        translation(j) = translation(j+1);
+        d->m_translations[j] = d->m_translations.value(j+1);
     }
-    kDebug() << "Checkme - removing last tranlation ?!!?";
-    ///@todo - no idea if this works
     d->m_translations.remove(d->m_translations.count() - 1);
 }
 
@@ -107,7 +103,7 @@ void KEduVocExpression::setTranslation( int index, const QString & expr )
         return;
     }
 
-    d->m_translations[index] = expr.simplified();
+    d->m_translations[index] = new KEduVocTranslation(this, expr.simplified());
 }
 
 
@@ -132,15 +128,15 @@ void KEduVocExpression::setActive( bool flag )
 void KEduVocExpression::resetGrades( int index )
 {
     if ( index == -1 ) { // clear grades for all languages
-        foreach( KEduVocTranslation trans, d->m_translations ) {
-            trans.resetGrades();
+        foreach( KEduVocTranslation* trans, d->m_translations ) {
+            trans->resetGrades();
         }
         return;
     }
 
     // only language index
     if ( d->m_translations.contains( index ) ) {
-        d->m_translations[index].resetGrades();
+        d->m_translations[index]->resetGrades();
     }
 }
 
@@ -157,9 +153,12 @@ bool KEduVocExpression::operator== ( const KEduVocExpression &expression ) const
     return ( *d == *expression.d );
 }
 
-KEduVocTranslation& KEduVocExpression::translation( int index ) const
+KEduVocTranslation* KEduVocExpression::translation( int index )
 {
-    return d->m_translations[index];
+    if(d->m_translations.contains(index)) {
+        return d->m_translations[index];
+    }
+    d->m_translations[index] = new KEduVocTranslation(this);
 }
 
 QList< int > KEduVocExpression::translationIndices() const
@@ -177,3 +176,4 @@ void KEduVocExpression::removeLesson(KEduVocLesson * l)
     d->m_lessons.removeAt(d->m_lessons.indexOf(l));
 }
 
+
index 0ff9507487016d7e22ada990aa49f041eb0ae52f..6781df1e2b9913bc426904ecdfaa67939fbba9ad 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <QtCore/QDateTime>
 
+#include "keduvoclesson.h"
 #include "keduvocgrammar.h"
 #include "keduvocmultiplechoice.h"
 #include "keduvoctranslation.h"
@@ -78,13 +79,7 @@ public:
     int sizeHint() const;
     void setSizeHint( int sizeHint );
 
-    /** returns this translation
-     *
-     * @return                 expression or "" if no translation available
-     */
-    QString translationString( int index ) const;
-
-    void setTranslation( int index, const KEduVocTranslation & translation );
+    void setTranslation( int index, KEduVocTranslation* translation );
     /**
      * Add a translation to this expression
      * @param index            number of translation = the identifier
@@ -102,11 +97,11 @@ public:
 
 
     /**
-     * Get a mutable reference to the translation
+     * Get a pointer to the translation
      * @param index of the language identifier
      * @return the translation
      */
-    KEduVocTranslation & translation( int index ) const;
+    KEduVocTranslation* translation( int index );
 
     QList<int> translationIndices() const;
 
index dfdf856add1b332d66c0f1207da7ce76792fd6ad..be6b0f0b28bfeeb5fa0b99dee553f3bbc8f11890 100644 (file)
@@ -300,67 +300,73 @@ bool KEduVocKvtml2Reader::readTranslation( QDomElement &translationElement,
 {
     QDomElement currentElement = translationElement.firstChildElement( KVTML_TEXT );
     if ( !currentElement.isNull() ) {
-        expr->translation( index ).setText( currentElement.text() );
+        expr->translation(index)->setText( currentElement.text() );
     }
 
     currentElement = translationElement.firstChildElement( KVTML_COMMENT );
     if ( !currentElement.isNull() ) {
-        expr->translation( index ).setComment( currentElement.text() );
+        expr->translation(index)->setComment( currentElement.text() );
     }
 
     currentElement = translationElement.firstChildElement( KVTML_WORDTYPE );
     if ( !currentElement.isNull() ) {
         QDomElement typeElement = currentElement.firstChildElement( KVTML_TYPENAME );
-        expr->translation( index ).setType( typeElement.text() );
-        // read subtype if the type is not empty
-        typeElement = currentElement.firstChildElement( KVTML_SUBTYPENAME );
-        if ( !typeElement.isNull() ) {
-            expr->translation( index ).setSubType( typeElement.text() );
-        }
+
+QString wordTypeString = typeElement.text();
+typeElement = currentElement.firstChildElement( KVTML_SUBTYPENAME );
+QString childWordTypeString = typeElement.text();
+
+KEduVocLesson* typeLesson = m_doc->wordTypeLesson()->childLesson(wordTypeString);
+if(!childWordTypeString.isEmpty()) {
+    typeLesson = typeLesson->childLesson(childWordTypeString);
+}
+
+
+expr->translation(index)->setWordType(typeLesson);
     }
 
     //<pronunciation></pronunciation>
     currentElement = translationElement.firstChildElement( KVTML_PRONUNCIATION );
     if ( !currentElement.isNull() ) {
-        expr->translation( index ).setPronunciation( currentElement.text() );
+        expr->translation(index)->setPronunciation( currentElement.text() );
     }
 
     //<falsefriend fromid="1"></falsefriend>
     currentElement = translationElement.firstChildElement( KVTML_FALSEFRIEND );
     if ( !currentElement.isNull() ) {
         int fromid = currentElement.attribute( KVTML_FROMID ).toInt();
-        expr->translation( index ).setFalseFriend( fromid, currentElement.text() );
+        expr->translation(index)->setFalseFriend( fromid, currentElement.text() );
     }
 
     //<antonym></antonym>
     currentElement = translationElement.firstChildElement( KVTML_ANTONYM );
     if ( !currentElement.isNull() ) {
-        expr->translation( index ).setAntonym( currentElement.text() );
+        expr->translation(index)->setAntonym( currentElement.text() );
     }
 
     //<synonym></synonym>
     currentElement = translationElement.firstChildElement( KVTML_SYNONYM );
     if ( !currentElement.isNull() ) {
-        expr->translation( index ).setSynonym( currentElement.text() );
+        expr->translation(index)->setSynonym( currentElement.text() );
     }
 
     //<example></example>
     currentElement = translationElement.firstChildElement( KVTML_EXAMPLE );
     if ( !currentElement.isNull() ) {
-        expr->translation( index ).setExample( currentElement.text() );
+        expr->translation(index)->setExample( currentElement.text() );
     }
 
     //<usage></usage> can be as often as there are usage labels
     currentElement = translationElement.firstChildElement( KVTML_USAGE );
     while ( !currentElement.isNull() ) {
-        expr->translation( index ).usages().insert( currentElement.text() );
+        expr->translation(index)->usages().insert( currentElement.text() );
         currentElement = currentElement.nextSiblingElement( KVTML_USAGE );
     }
 
     //<paraphrase></paraphrase>
     currentElement = translationElement.firstChildElement( KVTML_PARAPHRASE );
     if ( !currentElement.isNull() ) {
-        expr->translation( index ).setParaphrase( currentElement.text() );
+        expr->translation(index)->setParaphrase( currentElement.text() );
     }
 
     // conjugations
@@ -371,7 +377,7 @@ bool KEduVocKvtml2Reader::readTranslation( QDomElement &translationElement,
         QDomElement tenseElement = currentElement.firstChildElement( KVTML_TENSE );
         QString tense = tenseElement.text();
 
-        readConjugation( currentElement, expr->translation(index).conjugation(tense) );
+        readConjugation( currentElement, expr->translation(index)->conjugation(tense) );
         currentElement = currentElement.nextSiblingElement( KVTML_CONJUGATION );
     }
 
@@ -388,25 +394,25 @@ bool KEduVocKvtml2Reader::readTranslation( QDomElement &translationElement,
     if ( !currentElement.isNull() ) {
         KEduVocComparison comparison;
         readComparison( currentElement, comparison );
-        expr->translation( index ).setComparison( comparison );
+        expr->translation(index)->setComparison( comparison );
     }
 
     // multiple choice
     currentElement = translationElement.firstChildElement( KVTML_MULTIPLECHOICE );
     if ( !currentElement.isNull() ) {
-        readMultipleChoice( currentElement, expr->translation( index ) );
+        readMultipleChoice( currentElement, expr->translation(index) );
     }
 
     // image
     currentElement = translationElement.firstChildElement( KVTML_IMAGE );
     if ( !currentElement.isNull() ) {
-        expr->translation( index ).setImageUrl( KUrl( m_doc->url(), currentElement.text() ) );
+        expr->translation(index)->setImageUrl( KUrl( m_doc->url(), currentElement.text() ) );
     }
 
     // sound
     currentElement = translationElement.firstChildElement( KVTML_SOUND );
     if ( !currentElement.isNull() ) {
-        expr->translation( index ).setSoundUrl( KUrl( m_doc->url(), currentElement.text() ) );
+        expr->translation(index)->setSoundUrl( KUrl( m_doc->url(), currentElement.text() ) );
     }
 
     return true;
@@ -641,7 +647,7 @@ bool KEduVocKvtml2Reader::readComparison( QDomElement &domElementParent, KEduVoc
 }
 
 
-bool KEduVocKvtml2Reader::readMultipleChoice( QDomElement &multipleChoiceElement, KEduVocTranslation &translation )
+bool KEduVocKvtml2Reader::readMultipleChoice( QDomElement &multipleChoiceElement, KEduVocTranslationtranslation )
 /*
  <multiplechoice>
    <choice>good</choice>
@@ -659,7 +665,7 @@ bool KEduVocKvtml2Reader::readMultipleChoice( QDomElement &multipleChoiceElement
     {
         currentElement = choiceNodes.item( i ).toElement();
         if ( currentElement.parentNode() == multipleChoiceElement ) {
-            translation.multipleChoice().append( currentElement.text() );
+            translation->multipleChoice().append( currentElement.text() );
         }
     }
     return true;
@@ -677,19 +683,19 @@ bool KEduVocKvtml2Reader::readGrade( QDomElement &gradeElement, KEduVocExpressio
     QDomElement currentElement = gradeElement.firstChildElement( KVTML_CURRENTGRADE );
     if ( !currentElement.isNull() ) {
         int value = currentElement.text().toInt();
-        expr->translation( index ).gradeFrom( id ).setGrade( value );
+        expr->translation(index)->gradeFrom( id ).setGrade( value );
     }
 
     currentElement = gradeElement.firstChildElement( KVTML_COUNT );
     if ( !currentElement.isNull() ) {
         int value = currentElement.text().toInt();
-        expr->translation( index ).gradeFrom( id ).setPracticeCount( value );
+        expr->translation(index)->gradeFrom( id ).setPracticeCount( value );
     }
 
     currentElement = gradeElement.firstChildElement( KVTML_ERRORCOUNT );
     if ( !currentElement.isNull() ) {
         int value = currentElement.text().toInt();
-        expr->translation( index ).gradeFrom( id ).setBadCount( value );
+        expr->translation(index)->gradeFrom( id ).setBadCount( value );
     }
 
     currentElement = gradeElement.firstChildElement( KVTML_DATE );
@@ -697,7 +703,7 @@ bool KEduVocKvtml2Reader::readGrade( QDomElement &gradeElement, KEduVocExpressio
         QString dateString = currentElement.text();
         if ( !dateString.isEmpty() ) {
             QDateTime value = QDateTime::fromString( dateString, Qt::ISODate );
-            expr->translation( index ).gradeFrom( id ).setPracticeDate( value );
+            expr->translation(index)->gradeFrom( id ).setPracticeDate( value );
         }
     }
 
index 893d4be6f40fe539d06e7603e982b02b268e437c..e6368ccc0ff5fe0c0f08796abffdd20786b862f1 100644 (file)
@@ -120,7 +120,7 @@ private:
      * @param multipleChoiceElement element to read from
      * @param mc KEduVocMultipleChoice object to read to
      */
-    bool readMultipleChoice( QDomElement &multipleChoiceElement, KEduVocTranslation &translation );
+    bool readMultipleChoice( QDomElement &multipleChoiceElement, KEduVocTranslationtranslation );
 
     /** read a grade
      * @param gradeElement element to read from
index 8cbd85a311ae8b078130db74a10a9e43ced84c80..8b930e1106d5233dc888a5f5d158e25cbccc2b65 100644 (file)
@@ -341,10 +341,6 @@ bool KEduVocKvtml2Writer::writeEntries( QDomElement &entriesElement )
         // write inactive
         entryElement.appendChild( newTextElement( KVTML_INACTIVE, thisEntry->isActive() ? KVTML_FALSE : KVTML_TRUE ) );
 
-// kvtml 1 relic no longer used
-//         // write inquery
-//         entryElement.appendChild( newTextElement( KVTML_INQUERY, thisEntry->isInQuery() ? KVTML_TRUE : KVTML_FALSE ) );
-
         // loop through translations
         foreach( int trans, thisEntry->translationIndices() ) {
             // write translations
@@ -359,38 +355,43 @@ bool KEduVocKvtml2Writer::writeEntries( QDomElement &entriesElement )
     return true;
 }
 
-bool KEduVocKvtml2Writer::writeTranslation( QDomElement &translationElement, KEduVocTranslation &translation )
+bool KEduVocKvtml2Writer::writeTranslation( QDomElement &translationElement, KEduVocTranslationtranslation )
 {
     // <text>Kniebeugen</text>
-    translationElement.appendChild( newTextElement( KVTML_TEXT, translation.text() ) );
+    translationElement.appendChild( newTextElement( KVTML_TEXT, translation->text() ) );
 
     // <wordtype></wordtype>
-    if ( !translation.type().isEmpty() ) {
+    if ( translation->wordType() ) {
         QDomElement wordTypeElement = m_domDoc.createElement( KVTML_WORDTYPE );
         translationElement.appendChild( wordTypeElement );
         //<typename>noun</typename>
-        wordTypeElement.appendChild( newTextElement( KVTML_TYPENAME, translation.type() ) );
-        // <subwordtype>male</subwordtype>
-        if ( !translation.subType().isEmpty() ) {
-            wordTypeElement.appendChild( newTextElement( KVTML_SUBTYPENAME, translation.subType() ) );
+
+        if(translation->wordType()->parent() == m_doc->wordTypeLesson()) {
+            wordTypeElement.appendChild( newTextElement( KVTML_TYPENAME, translation->wordType()->name() ) );
+        } else {
+            if(translation->wordType()->parent()->parent() == m_doc->wordTypeLesson()) {
+                wordTypeElement.appendChild( newTextElement( KVTML_TYPENAME, translation->wordType()->parent()->name() ) );
+            // <subwordtype>male</subwordtype>
+                wordTypeElement.appendChild( newTextElement( KVTML_SUBTYPENAME, translation->wordType()->name() ) );
+            }
         }
     }
 
     // <comment></comment>
-    if ( !translation.comment().isEmpty() ) {
-        translationElement.appendChild( newTextElement( KVTML_COMMENT, translation.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() ) );
+    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 ) {
         // see if this identifier has a falsefriend in this translation
-        QString thisFriend = translation.falseFriend( i );
+        QString thisFriend = translation->falseFriend( i );
         if ( !thisFriend.isEmpty() ) {
             // if so, create it, and set the fromid to i
             QDomElement thisFriendElement = newTextElement( KVTML_FALSEFRIEND, thisFriend );
@@ -400,33 +401,33 @@ bool KEduVocKvtml2Writer::writeTranslation( QDomElement &translationElement, KEd
     }
 
     // <antonym></antonym>
-    if ( !translation.antonym().isEmpty() ) {
-        translationElement.appendChild( newTextElement( KVTML_ANTONYM, translation.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() ) );
+    if ( !translation->synonym().isEmpty() ) {
+        translationElement.appendChild( newTextElement( KVTML_SYNONYM, translation->synonym() ) );
     }
 
     // <example></example>
-    if ( !translation.example().isEmpty() ) {
-        translationElement.appendChild( newTextElement( KVTML_EXAMPLE, translation.example() ) );
+    if ( !translation->example().isEmpty() ) {
+        translationElement.appendChild( newTextElement( KVTML_EXAMPLE, translation->example() ) );
     }
 
     // <usage></usage>
-    foreach( QString usage, translation.usages() ) {
+    foreach( QString usage, translation->usages() ) {
         translationElement.appendChild( newTextElement( KVTML_USAGE, usage ) );
     }
 
     // <paraphrase></paraphrase>
-    if ( !translation.paraphrase().isEmpty() ) {
-        translationElement.appendChild( newTextElement( KVTML_PARAPHRASE, translation.paraphrase() ) );
+    if ( !translation->paraphrase().isEmpty() ) {
+        translationElement.appendChild( newTextElement( KVTML_PARAPHRASE, translation->paraphrase() ) );
     }
 
     // grades
     for ( int i = 0; i < m_doc->identifierCount(); ++i ) {
-        KEduVocGrade thisGrade = translation.gradeFrom( i );
+        KEduVocGrade thisGrade = translation->gradeFrom( i );
         if ( thisGrade.practiceCount() > 0 ) {
             QDomElement gradeElement = m_domDoc.createElement( KVTML_GRADE );
             gradeElement.setAttribute( KVTML_FROMID, QString::number( i ) );
@@ -447,46 +448,46 @@ bool KEduVocKvtml2Writer::writeTranslation( QDomElement &translationElement, KEd
     }
 
     // conjugation
-    foreach ( QString tense, translation.conjugationTenses() ) {
+    foreach ( QString tense, translation->conjugationTenses() ) {
         QDomElement thisElement = m_domDoc.createElement( KVTML_CONJUGATION );
-        writeConjugation( thisElement, translation.conjugation(tense), tense );
+        writeConjugation( thisElement, translation->conjugation(tense), tense );
         translationElement.appendChild( thisElement );
     }
 
     // comparison
-    if ( !translation.comparison().isEmpty() ) {
+    if ( !translation->comparison().isEmpty() ) {
         QDomElement comparisonElement = m_domDoc.createElement( KVTML_COMPARISON );
-        writeComparison( comparisonElement, translation.comparison() );
+        writeComparison( comparisonElement, translation->comparison() );
         translationElement.appendChild( comparisonElement );
     }
 
     // multiplechoice
-    if ( !translation.multipleChoice().isEmpty() ) {
+    if ( !translation->multipleChoice().isEmpty() ) {
         QDomElement multipleChoiceElement = m_domDoc.createElement( KVTML_MULTIPLECHOICE );
         writeMultipleChoice( multipleChoiceElement, translation );
         translationElement.appendChild( multipleChoiceElement );
     }
 
     // image
-    if ( !translation.imageUrl().isEmpty() ) {
+    if ( !translation->imageUrl().isEmpty() ) {
         QString urlString;
-        if ( translation.imageUrl().url().startsWith(m_doc->url().upUrl().url()) ) {
+        if ( translation->imageUrl().url().startsWith(m_doc->url().upUrl().url()) ) {
             // try to save as relative url
-            urlString = KUrl::relativeUrl( m_doc->url() , translation.imageUrl() );
+            urlString = KUrl::relativeUrl( m_doc->url() , translation->imageUrl() );
         } else {
-            urlString =  translation.imageUrl().url();
+            urlString =  translation->imageUrl().url();
         }
         translationElement.appendChild( newTextElement( KVTML_IMAGE, urlString ) );
     }
 
     // sound
-    if ( !translation.soundUrl().isEmpty() ) {
+    if ( !translation->soundUrl().isEmpty() ) {
         QString urlString;
-        if ( translation.soundUrl().url().startsWith(m_doc->url().upUrl().url()) ) {
+        if ( translation->soundUrl().url().startsWith(m_doc->url().upUrl().url()) ) {
             // try to save as relative url
-            urlString = KUrl::relativeUrl( m_doc->url() , translation.soundUrl() );
+            urlString = KUrl::relativeUrl( m_doc->url() , translation->soundUrl() );
         } else {
-            urlString =  translation.soundUrl().url();
+            urlString =  translation->soundUrl().url();
         }
         translationElement.appendChild( newTextElement( KVTML_SOUND, urlString ) );
     }
@@ -511,7 +512,7 @@ bool KEduVocKvtml2Writer::writeComparison( QDomElement &comparisonElement, const
 }
 
 
-bool KEduVocKvtml2Writer::writeMultipleChoice( QDomElement &multipleChoiceElement, KEduVocTranslation &translation )
+bool KEduVocKvtml2Writer::writeMultipleChoice( QDomElement &multipleChoiceElement, KEduVocTranslationtranslation )
 /*
  <multiplechoice>
    <choice>good</choice>
@@ -522,7 +523,7 @@ bool KEduVocKvtml2Writer::writeMultipleChoice( QDomElement &multipleChoiceElemen
  </multiplechoice>
 */
 {
-    foreach ( QString choice, translation.multipleChoice() ) {
+    foreach ( QString choice, translation->multipleChoice() ) {
         multipleChoiceElement.appendChild( newTextElement( KVTML_CHOICE, choice ) );
     }
     return true;
index 1de872fce33f8ff9550eb73124c82cade815599c..8c32fc8a4d76f135fb46f6c4519db4195ccc026d 100644 (file)
@@ -91,7 +91,7 @@ public:
      * @param translationElement QDomElement translation to write to, with id pre-set
      * @param translation object to write
      */
-    bool writeTranslation( QDomElement &translationElement, KEduVocTranslation &translation );
+    bool writeTranslation( QDomElement &translationElement, KEduVocTranslationtranslation );
 
     /** write the lesson group
      * @param parentLesson the parent lesson of the current lesson
@@ -110,7 +110,7 @@ public:
      * @param multipleChoiceElement QDomElement multiplechoice to write to
      * @returns success
      */
-    bool writeMultipleChoice( QDomElement &multipleChoiceElement, KEduVocTranslation &translation );
+    bool writeMultipleChoice( QDomElement &multipleChoiceElement, KEduVocTranslationtranslation );
 
 private:
     QDomElement newTextElement( const QString &elementName, const QString &text );
index 1a0fd15821294d240d4a2fb4c3c25fe740f45158..f0f40dfe7ee6604a134c2e321f8a39dc5f6a75b0 100644 (file)
@@ -191,3 +191,13 @@ KEduVocLesson * KEduVocLesson::parent()
     return d->m_parentLesson;
 }
 
+KEduVocLesson * KEduVocLesson::childLesson(const QString & name)
+{
+    for(int i = 0; i<d->m_childLessons.count(); i++){
+        if(d->m_childLessons.value(i)->name() == name) {
+            return d->m_childLessons.value(i);
+        }
+    }
+    return 0;
+}
+
index a6643be7a61f359e305302653323004a56d64d93..296267b2160d0d8c5408b6a897f6536ac65f4ba7 100644 (file)
@@ -40,6 +40,7 @@ public:
 
      QList<KEduVocLesson *> childLessons();
      KEduVocLesson *childLesson(int row);
+     KEduVocLesson *childLesson(const QString& name);
      int childLessonCount() const;
 
      int row() const;
index 7fc0b26a11d6b8e3437a72cca8b47a15bb9f6f10..e84cfe6f629ff4350769ba95f8bec0146da01f24 100644 (file)
 #include <KDebug>
 
 #include "keduvocgrade.h"
-// #include "keduvocdeclination.h"
+#include "keduvocdeclination.h"
 #include "keduvoclesson.h"
 
 class KEduVocTranslation::KEduVocTranslationPrivate
 {
 public:
+    KEduVocTranslationPrivate(KEduVocExpression* parent);
+
+    KEduVocExpression* m_entry;
+
     /// This is the word itself. The vocabulary. This is what it is all about.
     QString m_translation;
 
-    /// Type of a word noun, verb, adjective etc
-    QString m_type;
-    /// Subtype of a word: male/female or regular/irregular...
-    QString m_subType;
-
     /// Type of a word noun, verb, adjective etc
     KEduVocLesson* m_wordType;
 
-
     /// A comment giving additional information.
     QString m_comment;
     /// A hint, to make guessing the word easier.
@@ -67,7 +65,7 @@ public:
     /// The comparison forms of adjectives and adverbs: fast, faster, fastest
     KEduVocComparison m_comparison;
 
-//     KEduVocDeclination* m_declination;
+    KEduVocDeclination* m_declination;
 
     // Here come all int indexFrom grades. (If you want, imagine the TO grades as int indexFrom of the other translation. That is where they belong. )
     // User is asked to give THIS here as answer, than the grades go here.
@@ -81,20 +79,27 @@ public:
 };
 
 
-KEduVocTranslation::KEduVocTranslation() : d( new KEduVocTranslationPrivate )
+KEduVocTranslation::KEduVocTranslationPrivate::KEduVocTranslationPrivate(KEduVocExpression* parent)
+{
+    m_entry = parent;
+    m_wordType = 0;
+    m_declination = 0;
+}
+
+KEduVocTranslation::KEduVocTranslation(KEduVocExpression* entry) : d( new KEduVocTranslationPrivate(entry) )
 {}
 
 
-KEduVocTranslation::KEduVocTranslation( const QString &translation ) : d( new KEduVocTranslationPrivate )
+KEduVocTranslation::KEduVocTranslation(KEduVocExpression* entry, const QString &translation ) : d( new KEduVocTranslationPrivate(entry) )
 {
     d->m_translation = translation.simplified();
 }
 
-KEduVocTranslation::KEduVocTranslation( const KEduVocTranslation &other ) : d( new KEduVocTranslationPrivate )
+KEduVocTranslation::KEduVocTranslation( const KEduVocTranslation &other ) : d( new KEduVocTranslationPrivate(other.d->m_entry) )
 {
+//     d->m_entry = other.d->m_entry;
     d->m_translation = other.d->m_translation;
-    d->m_type = other.d->m_type;
-    d->m_subType = other.d->m_subType;
+    d->m_wordType = other.d->m_wordType;
     d->m_usages = other.d->m_usages;
     d->m_comment = other.d->m_comment;
     d->m_paraphrase = other.d->m_paraphrase;
@@ -119,9 +124,9 @@ KEduVocTranslation::~KEduVocTranslation()
 
 bool KEduVocTranslation::operator == ( const KEduVocTranslation & translation ) const
 {
-    return d->m_translation == translation.d->m_translation &&
-           d->m_type == translation.d->m_type &&
-           d->m_subType == translation.d->m_subType &&
+    return d->m_entry == translation.d->m_entry &&
+           d->m_translation == translation.d->m_translation &&
+           d->m_wordType == translation.d->m_wordType &&
            d->m_usages == translation.d->m_usages &&
            d->m_comment == translation.d->m_comment &&
            d->m_paraphrase == translation.d->m_paraphrase &&
@@ -141,9 +146,9 @@ bool KEduVocTranslation::operator == ( const KEduVocTranslation & translation )
 
 KEduVocTranslation & KEduVocTranslation::operator = ( const KEduVocTranslation & translation )
 {
+    d->m_entry = translation.d->m_entry;
     d->m_translation = translation.d->m_translation;
-    d->m_type = translation.d->m_type;
-    d->m_subType = translation.d->m_subType;
+    d->m_wordType = translation.d->m_wordType;
     d->m_usages = translation.d->m_usages;
     d->m_comment = translation.d->m_comment;
     d->m_paraphrase = translation.d->m_paraphrase;
@@ -305,29 +310,6 @@ void KEduVocTranslation::setPronunciation( const QString & expr )
     d->m_pronunciation = expr.simplified();
 }
 
-
-QString KEduVocTranslation::type() const
-{
-    return d->m_type;
-}
-
-
-void KEduVocTranslation::setType( const QString &type )
-{
-    d->m_type = type;
-}
-
-QString KEduVocTranslation::subType() const
-{
-    return d->m_subType;
-}
-
-
-void KEduVocTranslation::setSubType( const QString &type )
-{
-    d->m_subType = type;
-}
-
 void KEduVocTranslation::resetGrades()
 {
     d->m_grades.clear();
@@ -379,3 +361,17 @@ void KEduVocTranslation::setImageUrl(const KUrl &url)
 {
     d->m_imageUrl = url;
 }
+
+KEduVocLesson * KEduVocTranslation::wordType() const
+{
+    return d->m_wordType;
+}
+
+void KEduVocTranslation::setWordType(KEduVocLesson * wordType)
+{
+    if ( d->m_wordType ) {
+        d->m_wordType->removeEntry(d->m_entry);
+    }
+    
+}
+
index 7f1ef3041101d3f3186f691d3d9406e42547571a..827b5fee6d0024f4c96f49704416653d445313f4 100644 (file)
@@ -24,8 +24,9 @@
 #include <KDE/KUrl>
 #include <QtCore/QString>
 
-
+class KEduVocExpression;
 class KEduVocGrade;
+class KEduVocLesson;
 
 /**
  @author Frederik Gladhorn <frederik.gladhorn@kdemail.net>
@@ -36,13 +37,13 @@ public:
     /**
      * Default constructor for an empty translation.
      */
-    KEduVocTranslation();
+    KEduVocTranslation(KEduVocExpression* entry);
 
     /**
         * Constructor
         * @param translation is used as translation
         */
-    KEduVocTranslation( const QString &translation );
+    KEduVocTranslation(KEduVocExpression* entry, const QString &translation );
 
     /** copy constructor for d-pointer safet */
     KEduVocTranslation( const KEduVocTranslation &other );
@@ -162,27 +163,17 @@ public:
      */
     QString irregularPlural() const;
 
-    /** returns type of this expression
+    /** returns the word type of this expression
     *
     * @return                 type or "" if no type available
     */
-    QString type() const;
+    KEduVocLesson* wordType() const;
 
-    /** sets type of this expression
+    /** sets the word type of this expression
     * @param type             type of this expression ("" = none)
     */
-    void setType( const QString &type );
+    void setWordType( KEduVocLesson* wordType );
 
-    /** returns subtype of this expression
-    *
-    * @return                 type or "" if no type available
-    */
-    QString subType() const;
-
-    /** sets subtype of this expression
-    * @param type             type of this expression ("" = none)
-    */
-    void setSubType( const QString &type );
 
     /** reset the grades for this translation */
     void resetGrades();
index 79cb26ceb477a16bf7bc758d3ffa0d4b77fb1349..f8f14a53a47479d3e9c8a195325d8afbe61c50ad 100644 (file)
@@ -140,8 +140,6 @@ public:
     QString specialTypeAdverb() const;
 
 private:
-
-
     QString mainTypeName( int index ) const;
     int mainTypeIndex( const QString& name ) const;
     int subTypeIndex( const QString& mainTypeName, const QString& subTypeName ) const;