From 1f0e0fbaf7a7fdb4f1fbe4dfe2906e2a82da60f9 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Thu, 22 Nov 2007 22:46:07 +0000 Subject: [PATCH] Change expression to contain a pointer to its translations and the translations have a pointer to their parent expression. Also translation now contain pointers to their word types represented by lessons. svn path=/branches/work/kdeedu_parley/libkdeedu/; revision=740298 --- keduvocdocument/keduvoccsvwriter.cpp | 2 +- keduvocdocument/keduvocdocument.cpp | 4 +- keduvocdocument/keduvocexpression.cpp | 34 +++++----- keduvocdocument/keduvocexpression.h | 13 ++-- keduvocdocument/keduvockvtml2reader.cpp | 58 +++++++++-------- keduvocdocument/keduvockvtml2reader.h | 2 +- keduvocdocument/keduvockvtml2writer.cpp | 83 +++++++++++++------------ keduvocdocument/keduvockvtml2writer.h | 4 +- keduvocdocument/keduvoclesson.cpp | 10 +++ keduvocdocument/keduvoclesson.h | 1 + keduvocdocument/keduvoctranslation.cpp | 78 +++++++++++------------ keduvocdocument/keduvoctranslation.h | 25 +++----- keduvocdocument/keduvocwordtype.h | 2 - 13 files changed, 157 insertions(+), 159 deletions(-) diff --git a/keduvocdocument/keduvoccsvwriter.cpp b/keduvocdocument/keduvoccsvwriter.cpp index 1917158..f6b7f9a 100644 --- a/keduvocdocument/keduvoccsvwriter.cpp +++ b/keduvocdocument/keduvoccsvwriter.cpp @@ -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() ) diff --git a/keduvocdocument/keduvocdocument.cpp b/keduvocdocument/keduvocdocument.cpp index 2495559..dbf63ec 100644 --- a/keduvocdocument/keduvocdocument.cpp +++ b/keduvocdocument/keduvocdocument.cpp @@ -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; diff --git a/keduvocdocument/keduvocexpression.cpp b/keduvocdocument/keduvocexpression.cpp index 4630cc5..b30095c 100644 --- a/keduvocdocument/keduvocexpression.cpp +++ b/keduvocdocument/keduvocexpression.cpp @@ -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 m_lessons; bool m_active; - QMap m_translations; + QMap 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)); } + diff --git a/keduvocdocument/keduvocexpression.h b/keduvocdocument/keduvocexpression.h index 0ff9507..6781df1 100644 --- a/keduvocdocument/keduvocexpression.h +++ b/keduvocdocument/keduvocexpression.h @@ -22,6 +22,7 @@ #include +#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 translationIndices() const; diff --git a/keduvocdocument/keduvockvtml2reader.cpp b/keduvocdocument/keduvockvtml2reader.cpp index dfdf856..be6b0f0 100644 --- a/keduvocdocument/keduvockvtml2reader.cpp +++ b/keduvocdocument/keduvockvtml2reader.cpp @@ -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); } // currentElement = translationElement.firstChildElement( KVTML_PRONUNCIATION ); if ( !currentElement.isNull() ) { - expr->translation( index ).setPronunciation( currentElement.text() ); + expr->translation(index)->setPronunciation( currentElement.text() ); } // 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() ); } // currentElement = translationElement.firstChildElement( KVTML_ANTONYM ); if ( !currentElement.isNull() ) { - expr->translation( index ).setAntonym( currentElement.text() ); + expr->translation(index)->setAntonym( currentElement.text() ); } // currentElement = translationElement.firstChildElement( KVTML_SYNONYM ); if ( !currentElement.isNull() ) { - expr->translation( index ).setSynonym( currentElement.text() ); + expr->translation(index)->setSynonym( currentElement.text() ); } // currentElement = translationElement.firstChildElement( KVTML_EXAMPLE ); if ( !currentElement.isNull() ) { - expr->translation( index ).setExample( currentElement.text() ); + expr->translation(index)->setExample( currentElement.text() ); } // 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 ); } // 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, KEduVocTranslation* translation ) /* good @@ -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 ); } } diff --git a/keduvocdocument/keduvockvtml2reader.h b/keduvocdocument/keduvockvtml2reader.h index 893d4be..e6368cc 100644 --- a/keduvocdocument/keduvockvtml2reader.h +++ b/keduvocdocument/keduvockvtml2reader.h @@ -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, KEduVocTranslation* translation ); /** read a grade * @param gradeElement element to read from diff --git a/keduvocdocument/keduvockvtml2writer.cpp b/keduvocdocument/keduvockvtml2writer.cpp index 8cbd85a..8b930e1 100644 --- a/keduvocdocument/keduvockvtml2writer.cpp +++ b/keduvocdocument/keduvockvtml2writer.cpp @@ -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, KEduVocTranslation* translation ) { // Kniebeugen - translationElement.appendChild( newTextElement( KVTML_TEXT, translation.text() ) ); + translationElement.appendChild( newTextElement( KVTML_TEXT, translation->text() ) ); // - if ( !translation.type().isEmpty() ) { + if ( translation->wordType() ) { QDomElement wordTypeElement = m_domDoc.createElement( KVTML_WORDTYPE ); translationElement.appendChild( wordTypeElement ); //noun - wordTypeElement.appendChild( newTextElement( KVTML_TYPENAME, translation.type() ) ); - // male - 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() ) ); + // male + wordTypeElement.appendChild( newTextElement( KVTML_SUBTYPENAME, translation->wordType()->name() ) ); + } } } // - if ( !translation.comment().isEmpty() ) { - translationElement.appendChild( newTextElement( KVTML_COMMENT, translation.comment() ) ); + if ( !translation->comment().isEmpty() ) { + translationElement.appendChild( newTextElement( KVTML_COMMENT, translation->comment() ) ); } // - if ( !translation.pronunciation().isEmpty() ) { - translationElement.appendChild( newTextElement( KVTML_PRONUNCIATION, translation.pronunciation() ) ); + if ( !translation->pronunciation().isEmpty() ) { + translationElement.appendChild( newTextElement( KVTML_PRONUNCIATION, translation->pronunciation() ) ); } // // 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 } // - if ( !translation.antonym().isEmpty() ) { - translationElement.appendChild( newTextElement( KVTML_ANTONYM, translation.antonym() ) ); + if ( !translation->antonym().isEmpty() ) { + translationElement.appendChild( newTextElement( KVTML_ANTONYM, translation->antonym() ) ); } // - if ( !translation.synonym().isEmpty() ) { - translationElement.appendChild( newTextElement( KVTML_SYNONYM, translation.synonym() ) ); + if ( !translation->synonym().isEmpty() ) { + translationElement.appendChild( newTextElement( KVTML_SYNONYM, translation->synonym() ) ); } // - if ( !translation.example().isEmpty() ) { - translationElement.appendChild( newTextElement( KVTML_EXAMPLE, translation.example() ) ); + if ( !translation->example().isEmpty() ) { + translationElement.appendChild( newTextElement( KVTML_EXAMPLE, translation->example() ) ); } // - foreach( QString usage, translation.usages() ) { + foreach( QString usage, translation->usages() ) { translationElement.appendChild( newTextElement( KVTML_USAGE, usage ) ); } // - 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, KEduVocTranslation* translation ) /* good @@ -522,7 +523,7 @@ bool KEduVocKvtml2Writer::writeMultipleChoice( QDomElement &multipleChoiceElemen */ { - foreach ( QString choice, translation.multipleChoice() ) { + foreach ( QString choice, translation->multipleChoice() ) { multipleChoiceElement.appendChild( newTextElement( KVTML_CHOICE, choice ) ); } return true; diff --git a/keduvocdocument/keduvockvtml2writer.h b/keduvocdocument/keduvockvtml2writer.h index 1de872f..8c32fc8 100644 --- a/keduvocdocument/keduvockvtml2writer.h +++ b/keduvocdocument/keduvockvtml2writer.h @@ -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, KEduVocTranslation* translation ); /** 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, KEduVocTranslation* translation ); private: QDomElement newTextElement( const QString &elementName, const QString &text ); diff --git a/keduvocdocument/keduvoclesson.cpp b/keduvocdocument/keduvoclesson.cpp index 1a0fd15..f0f40df 100644 --- a/keduvocdocument/keduvoclesson.cpp +++ b/keduvocdocument/keduvoclesson.cpp @@ -191,3 +191,13 @@ KEduVocLesson * KEduVocLesson::parent() return d->m_parentLesson; } +KEduVocLesson * KEduVocLesson::childLesson(const QString & name) +{ + for(int i = 0; im_childLessons.count(); i++){ + if(d->m_childLessons.value(i)->name() == name) { + return d->m_childLessons.value(i); + } + } + return 0; +} + diff --git a/keduvocdocument/keduvoclesson.h b/keduvocdocument/keduvoclesson.h index a6643be..296267b 100644 --- a/keduvocdocument/keduvoclesson.h +++ b/keduvocdocument/keduvoclesson.h @@ -40,6 +40,7 @@ public: QList childLessons(); KEduVocLesson *childLesson(int row); + KEduVocLesson *childLesson(const QString& name); int childLessonCount() const; int row() const; diff --git a/keduvocdocument/keduvoctranslation.cpp b/keduvocdocument/keduvoctranslation.cpp index 7fc0b26..e84cfe6 100644 --- a/keduvocdocument/keduvoctranslation.cpp +++ b/keduvocdocument/keduvoctranslation.cpp @@ -21,24 +21,22 @@ #include #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); + } + +} + diff --git a/keduvocdocument/keduvoctranslation.h b/keduvocdocument/keduvoctranslation.h index 7f1ef30..827b5fe 100644 --- a/keduvocdocument/keduvoctranslation.h +++ b/keduvocdocument/keduvoctranslation.h @@ -24,8 +24,9 @@ #include #include - +class KEduVocExpression; class KEduVocGrade; +class KEduVocLesson; /** @author Frederik Gladhorn @@ -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(); diff --git a/keduvocdocument/keduvocwordtype.h b/keduvocdocument/keduvocwordtype.h index 79cb26c..f8f14a5 100644 --- a/keduvocdocument/keduvocwordtype.h +++ b/keduvocdocument/keduvocwordtype.h @@ -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; -- 2.47.3