From 8a17484b281b990b15a1f0509f6a3b797c8be990 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Sat, 1 Sep 2007 11:12:27 +0000 Subject: [PATCH] Fix: Writer did not write tag, but put third persons directly next to the others. Conjugation class: No more macros. Move over to a QMap for tense-conjugation entries. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=707256 --- keduvocdocument/keduvocconjugation.cpp | 109 ++++++++++-------------- keduvocdocument/keduvocconjugation.h | 1 - keduvocdocument/keduvockvtml2reader.cpp | 2 + keduvocdocument/keduvockvtml2writer.cpp | 22 +++-- 4 files changed, 62 insertions(+), 72 deletions(-) diff --git a/keduvocdocument/keduvocconjugation.cpp b/keduvocdocument/keduvocconjugation.cpp index da91c99..d834017 100644 --- a/keduvocdocument/keduvocconjugation.cpp +++ b/keduvocdocument/keduvocconjugation.cpp @@ -37,7 +37,8 @@ public: s3common = false; } - QString type; + bool operator==(const conjug_t& other) const; + bool p3common; bool s3common; QString pers1_sing; @@ -52,8 +53,7 @@ public: QString pers3_n_plur; }; - typedef QList conjug_tList; - conjug_tList m_conjugations; + QMap m_conjugations; }; @@ -85,7 +85,8 @@ bool KEduVocConjugation::operator == ( const KEduVocConjugation& a ) const { ///@todo conjugations: rewrite operator== kDebug() <<"Implement KEduVocConjugation::operator=="; - return d->m_conjugations[0].type == a.d->m_conjugations[0].type; +// return d->m_conjugations[0].type == a.d->m_conjugations[0].type; + return d->m_conjugations == a.d->m_conjugations; } @@ -95,192 +96,174 @@ int KEduVocConjugation::entryCount() const } - - QString KEduVocConjugation::getType( int idx ) { kDebug() << "KEduVocConjugation::getType()" << idx; if ( idx >= d->m_conjugations.count() ) return QString(); - return d->m_conjugations[idx].type; -} - - -void KEduVocConjugation::setType( int idx, const QString & type ) -{ - if ( idx >= d->m_conjugations.size() ) - return; - - d->m_conjugations[idx].type = type; + return d->m_conjugations.keys().value(idx); } -#define _GET_CON_(elem, type, default) \ - for (int i = 0; i < d->m_conjugations.size(); i++) \ - if (d->m_conjugations[i].type == type) \ - return d->m_conjugations[i].elem; \ - return default; - - bool KEduVocConjugation::pers3SingularCommon( const QString &type ) const { - _GET_CON_( s3common, type, false ); + return d->m_conjugations.value(type).s3common; } bool KEduVocConjugation::pers3PluralCommon( const QString &type ) const { - _GET_CON_( p3common, type, false ); + return d->m_conjugations.value(type).p3common; } QString KEduVocConjugation::pers1Singular( const QString &type ) const { - _GET_CON_( pers1_sing, type, "" ); + return d->m_conjugations.value(type).pers1_sing; } QString KEduVocConjugation::pers2Singular( const QString &type ) const { - _GET_CON_( pers2_sing, type, "" ); + return d->m_conjugations.value(type).pers2_sing; } QString KEduVocConjugation::pers3FemaleSingular( const QString &type ) const { - _GET_CON_( pers3_f_sing, type, "" ); + return d->m_conjugations.value(type).pers3_f_sing; } QString KEduVocConjugation::pers3MaleSingular( const QString &type ) const { - _GET_CON_( pers3_m_sing, type, "" ); + return d->m_conjugations.value(type).pers3_m_sing; } QString KEduVocConjugation::pers3NaturalSingular( const QString &type ) const { - _GET_CON_( pers3_n_sing, type, "" ); + return d->m_conjugations.value(type).pers3_n_sing; } QString KEduVocConjugation::pers1Plural( const QString &type ) const { - _GET_CON_( pers1_plur, type, "" ); + return d->m_conjugations.value(type).pers1_plur; } QString KEduVocConjugation::pers2Plural( const QString &type ) const { - _GET_CON_( pers2_plur, type, "" ); + return d->m_conjugations.value(type).pers2_plur; } QString KEduVocConjugation::pers3FemalePlural( const QString &type ) const { - _GET_CON_( pers3_f_plur, type, "" ); + return d->m_conjugations.value(type).pers3_f_plur; } QString KEduVocConjugation::pers3MalePlural( const QString &type ) const { - _GET_CON_( pers3_m_plur, type, "" ); + return d->m_conjugations.value(type).pers3_m_plur; } QString KEduVocConjugation::pers3NaturalPlural( const QString &type ) const { - _GET_CON_( pers3_n_plur, type, "" ); + return d->m_conjugations.value(type).pers3_n_plur; } -#undef _GET_CON_ - - -#define _SET_CON_(elem, type, str) \ - for (int i = 0; i < d->m_conjugations.size(); i++) \ - if (d->m_conjugations[i].type == type) { \ - d->m_conjugations[i].elem = str; \ - return; \ - } \ - Private::conjug_t ct; \ - ct.type = type; \ - ct.elem = str; \ - d->m_conjugations.append(ct); - - void KEduVocConjugation::setPers3PluralCommon( const QString &type, bool f ) { - _SET_CON_( p3common, type, f ); + d->m_conjugations[type].p3common = f; } void KEduVocConjugation::setPers3SingularCommon( const QString &type, bool f ) { - _SET_CON_( s3common, type, f ); + d->m_conjugations[type].s3common = f; } void KEduVocConjugation::setPers1Singular( const QString &type, const QString &str ) { - _SET_CON_( pers1_sing, type, str ); + d->m_conjugations[type].pers1_sing = str; } void KEduVocConjugation::setPers2Singular( const QString &type, const QString &str ) { - _SET_CON_( pers2_sing, type, str ); + d->m_conjugations[type].pers2_sing = str; } void KEduVocConjugation::setPers3FemaleSingular( const QString &type, const QString &str ) { - _SET_CON_( pers3_f_sing, type, str ); + d->m_conjugations[type].pers3_f_sing = str; } void KEduVocConjugation::setPers3MaleSingular( const QString &type, const QString &str ) { - _SET_CON_( pers3_m_sing, type, str ); + d->m_conjugations[type].pers3_m_sing = str; } void KEduVocConjugation::setPers3NaturalSingular( const QString &type, const QString &str ) { - _SET_CON_( pers3_n_sing, type, str ); + d->m_conjugations[type].pers3_n_sing = str; } void KEduVocConjugation::setPers1Plural( const QString &type, const QString &str ) { - _SET_CON_( pers1_plur, type, str ); + d->m_conjugations[type].pers1_plur = str; } void KEduVocConjugation::setPers2Plural( const QString &type, const QString &str ) { - _SET_CON_( pers2_plur, type, str ); + d->m_conjugations[type].pers2_plur = str; } void KEduVocConjugation::setPers3FemalePlural( const QString &type, const QString &str ) { - _SET_CON_( pers3_f_plur, type, str ); + d->m_conjugations[type].pers3_f_plur = str; } void KEduVocConjugation::setPers3MalePlural( const QString &type, const QString &str ) { - _SET_CON_( pers3_m_plur, type, str ); + d->m_conjugations[type].pers3_m_plur = str; } void KEduVocConjugation::setPers3NaturalPlural( const QString &type, const QString &str ) { - _SET_CON_( pers3_n_plur, type, str ); + d->m_conjugations[type].pers3_n_plur = str; } -#undef _SET_CON_ + +bool KEduVocConjugation::Private::conjug_t::operator ==(const conjug_t & other) const +{ + return s3common == other.s3common && + p3common == other.p3common && + pers1_sing == other.pers1_sing && + pers2_sing == other.pers2_sing && + pers3_m_sing == other.pers3_m_sing && + pers3_f_sing == other.pers3_f_sing && + pers3_n_sing == other.pers3_n_sing && + pers1_plur == other.pers1_plur && + pers2_plur == other.pers2_plur && + pers3_m_plur == other.pers3_m_plur && + pers3_f_plur == other.pers3_f_plur && + pers3_n_plur == other.pers3_n_plur; +} diff --git a/keduvocdocument/keduvocconjugation.h b/keduvocdocument/keduvocconjugation.h index c4b75c8..b3f887d 100644 --- a/keduvocdocument/keduvocconjugation.h +++ b/keduvocdocument/keduvocconjugation.h @@ -73,7 +73,6 @@ public: int entryCount() const; QString getType( int index ); - void setType( int index, const QString & type ); QString pers1Singular( const QString &type ) const; QString pers2Singular( const QString &type ) const; diff --git a/keduvocdocument/keduvockvtml2reader.cpp b/keduvocdocument/keduvockvtml2reader.cpp index 8fc36d6..0392ce3 100644 --- a/keduvocdocument/keduvockvtml2reader.cpp +++ b/keduvocdocument/keduvockvtml2reader.cpp @@ -604,6 +604,7 @@ kDebug() << "Reading conjugation for tense: " << tense; if ( !currentElement.isNull() ) { s3_common = true; singthirdmale = currentElement.text(); +kDebug() << " Reading common: " << tense << " first sing: " << singfirst << " sing third: " << singthirdmale; singthirdfemale = singthirdmale; singthirdneutral = singthirdmale; } else { @@ -612,6 +613,7 @@ kDebug() << "Reading conjugation for tense: " << tense; if ( !currentElement.isNull() ) { singthirdmale = currentElement.text(); } +kDebug() << " Reading NOT common: " << tense << " first sing: " << singfirst << " sing third: " << singthirdmale; currentElement = currentGroup.firstChildElement( KVTML_FEMALE ); if ( !currentElement.isNull() ) { diff --git a/keduvocdocument/keduvockvtml2writer.cpp b/keduvocdocument/keduvockvtml2writer.cpp index 4acec09..adbc5d4 100644 --- a/keduvocdocument/keduvockvtml2writer.cpp +++ b/keduvocdocument/keduvockvtml2writer.cpp @@ -518,12 +518,15 @@ bool KEduVocKvtml2Writer::writeConjugation( QDomElement &conjugationElement, singular.appendChild( newTextElement( KVTML_1STPERSON, first ) ); singular.appendChild( newTextElement( KVTML_2NDPERSON, second ) ); + QDomElement thirdPerson = m_domDoc.createElement( KVTML_3RDPERSON ); + singular.appendChild( thirdPerson ); + if ( third_common ) { - singular.appendChild( newTextElement( KVTML_COMMON, third_female ) ); + thirdPerson.appendChild( newTextElement( KVTML_COMMON, third_female ) ); } else { - singular.appendChild( newTextElement( KVTML_MALE, third_male ) ); - singular.appendChild( newTextElement( KVTML_FEMALE, third_female ) ); - singular.appendChild( newTextElement( KVTML_NEUTRAL, third_neutral ) ); + thirdPerson.appendChild( newTextElement( KVTML_MALE, third_male ) ); + thirdPerson.appendChild( newTextElement( KVTML_FEMALE, third_female ) ); + thirdPerson.appendChild( newTextElement( KVTML_NEUTRAL, third_neutral ) ); } conjugationElement.appendChild( singular ); } @@ -543,12 +546,15 @@ bool KEduVocKvtml2Writer::writeConjugation( QDomElement &conjugationElement, plural.appendChild( newTextElement( KVTML_1STPERSON, first ) ); plural.appendChild( newTextElement( KVTML_2NDPERSON, second ) ); + QDomElement thirdPerson = m_domDoc.createElement( KVTML_3RDPERSON ); + plural.appendChild( thirdPerson ); + if ( third_common ) { - plural.appendChild( newTextElement( KVTML_COMMON, third_female ) ); + thirdPerson.appendChild( newTextElement( KVTML_COMMON, third_female ) ); } else { - plural.appendChild( newTextElement( KVTML_MALE, third_male ) ); - plural.appendChild( newTextElement( KVTML_FEMALE, third_female ) ); - plural.appendChild( newTextElement( KVTML_NEUTRAL, third_neutral ) ); + thirdPerson.appendChild( newTextElement( KVTML_MALE, third_male ) ); + thirdPerson.appendChild( newTextElement( KVTML_FEMALE, third_female ) ); + thirdPerson.appendChild( newTextElement( KVTML_NEUTRAL, third_neutral ) ); } conjugationElement.appendChild( plural ); } -- 2.47.3