From: Frederik Gladhorn Date: Thu, 30 Aug 2007 12:08:14 +0000 (+0000) Subject: Moved article management from doc class to identifier. X-Git-Tag: v3.94.0~114 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=99443faf09b1b763b1ee0d6c8aa1605524e452f6;p=libqmvoc.git Moved article management from doc class to identifier. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=706431 --- diff --git a/keduvocdocument/keduvocdocument.cpp b/keduvocdocument/keduvocdocument.cpp index a6dc68b..12c6b6b 100644 --- a/keduvocdocument/keduvocdocument.cpp +++ b/keduvocdocument/keduvocdocument.cpp @@ -96,7 +96,6 @@ public: */ QString m_category; - QList m_articles; QList m_conjugations; // make this a map so removals don't require renumbering :) @@ -112,7 +111,6 @@ public: void KEduVocDocument::KEduVocDocumentPrivate::init() { m_lessons.clear(); - m_articles.clear(); m_tenseDescriptions.clear(); m_identifiers.clear(); m_sortIdentifier.clear(); @@ -696,35 +694,6 @@ KEduVocConjugation KEduVocDocument::conjugation( int idx ) const } -void KEduVocDocument::setArticle( int idx, const KEduVocArticle &art ) -{ - if ( idx < 0 ) return; - - // extend conjugation with empty elements - if ( d->m_articles.size() <= idx ) - for ( int i = d->m_articles.size(); i < idx+1; i++ ) - d->m_articles.append( KEduVocArticle() ); - - d->m_articles[idx] = art; -} - - -KEduVocArticle KEduVocDocument::article( int idx ) const -{ - if ( idx >= d->m_articles.size() || idx < 0 ) { - return KEduVocArticle(); - } else { - return d->m_articles[idx]; - } -} - - -int KEduVocDocument::articleCount() const -{ - return d->m_articles.count(); -} - - int KEduVocDocument::sizeHint( int idx ) const { if ( idx < 0 ) { @@ -864,6 +833,7 @@ int KEduVocDocument::identifierCount() const int KEduVocDocument::appendIdentifier( const KEduVocIdentifier& id ) { int i = d->m_identifiers.size(); +kDebug() << "appendIdentifier: " << i << id.name() << id.locale(); d->m_identifiers.append( id ); if ( id.name().isEmpty() ) { if ( i == 0 ) { diff --git a/keduvocdocument/keduvocdocument.h b/keduvocdocument/keduvocdocument.h index 685b19c..df22271 100644 --- a/keduvocdocument/keduvocdocument.h +++ b/keduvocdocument/keduvocdocument.h @@ -517,30 +517,6 @@ public: */ int conjugationCount() const; - - -///@todo move into identifier! - // *** article methods *** - - /** - * @param index index of translation - * @returns a pointer to articles if available - */ - KEduVocArticle article( int index ) const; - - /** - * Sets the articles - * - * @param index index of translation - * @param art article block - */ - void setArticle( int index, const KEduVocArticle &art ); - - /** - * @returns the number of articles - */ - int articleCount() const; - // *** file format specific methods *** /** diff --git a/keduvocdocument/keduvocidentifier.cpp b/keduvocdocument/keduvocidentifier.cpp index d1dd3d0..cf7bd23 100644 --- a/keduvocdocument/keduvocidentifier.cpp +++ b/keduvocdocument/keduvocidentifier.cpp @@ -59,7 +59,6 @@ public: KEduVocIdentifier::KEduVocIdentifier() : d( new Private ) { - d->m_name = i18nc("A default title for a single column of vocabulary. Will hardly be used. Should be very generic.", "Title"); ///@todo maybe the user locale would be more appropriate d->m_locale = "en"; } @@ -109,3 +108,15 @@ void KEduVocIdentifier::setLocale(const QString & locale) d->m_locale = locale; } + +void KEduVocIdentifier::setArticle( const KEduVocArticle& articles ) +{ + d->m_articles = articles; +} + + +KEduVocArticle KEduVocIdentifier::article() const +{ + return d->m_articles; +} + diff --git a/keduvocdocument/keduvocidentifier.h b/keduvocdocument/keduvocidentifier.h index 1b48201..6969191 100644 --- a/keduvocdocument/keduvocidentifier.h +++ b/keduvocdocument/keduvocidentifier.h @@ -87,6 +87,20 @@ public: */ void setLocale( const QString& name ); + + /** + * Articles (a, the in English, el, la,... in Spanish) + * @returns articles + */ + KEduVocArticle article() const; + + /** + * Sets the articles for this identifier + * @param art article block + */ + void setArticle( const KEduVocArticle& article ); + + private: class Private; Private * const d; diff --git a/keduvocdocument/keduvockvtml2reader.cpp b/keduvocdocument/keduvockvtml2reader.cpp index fa37fe0..a861cbb 100644 --- a/keduvocdocument/keduvockvtml2reader.cpp +++ b/keduvocdocument/keduvockvtml2reader.cpp @@ -539,7 +539,7 @@ bool KEduVocKvtml2Reader::readArticle( QDomElement &articleElement, int identifi nat_indef = subElement.text(); } } - m_doc->setArticle( identifierNum, KEduVocArticle( fem_def, fem_indef, mal_def, mal_indef, nat_def, nat_indef ) ); + m_doc->identifier(identifierNum).setArticle( KEduVocArticle( fem_def, fem_indef, mal_def, mal_indef, nat_def, nat_indef ) ); return true; } diff --git a/keduvocdocument/keduvockvtml2writer.cpp b/keduvocdocument/keduvockvtml2writer.cpp index 2544c16..620ec7e 100644 --- a/keduvocdocument/keduvockvtml2writer.cpp +++ b/keduvocdocument/keduvockvtml2writer.cpp @@ -211,7 +211,7 @@ bool KEduVocKvtml2Writer::writeArticle( QDomElement &articleElement, int article QString indef; // male - m_doc->article( article ).getMale( &def, &indef ); + m_doc->identifier(article).article().getMale( &def, &indef ); if ( !def.isEmpty() ) { definite.appendChild( newTextElement( KVTML_MALE, def ) ); } @@ -220,7 +220,7 @@ bool KEduVocKvtml2Writer::writeArticle( QDomElement &articleElement, int article } // female - m_doc->article( article ).getFemale( &def, &indef ); + m_doc->identifier(article).article().getFemale( &def, &indef ); if ( !def.isEmpty() ) { definite.appendChild( newTextElement( KVTML_FEMALE, def ) ); } @@ -229,7 +229,7 @@ bool KEduVocKvtml2Writer::writeArticle( QDomElement &articleElement, int article } // neutral - m_doc->article( article ).getNatural( &def, &indef ); + m_doc->identifier(article).article().getNatural( &def, &indef ); if ( !def.isEmpty() ) { definite.appendChild( newTextElement( KVTML_NEUTRAL, def ) ); } diff --git a/keduvocdocument/keduvockvtmlreader.cpp b/keduvocdocument/keduvockvtmlreader.cpp index ee748a2..30441a2 100644 --- a/keduvocdocument/keduvockvtmlreader.cpp +++ b/keduvocdocument/keduvockvtmlreader.cpp @@ -144,7 +144,6 @@ bool KEduVocKvtmlReader::readBody( QDomElement &domElementParent ) return false; } - // initialize the list of predefined types m_doc->wordTypes()->createDefaultWordTypes(); currentElement = domElementParent.firstChildElement( KV_TYPE_GRP ); @@ -333,7 +332,7 @@ bool KEduVocKvtmlReader::readArticle( QDomElement &domElementParent ) nat_indef = ""; } - m_doc->setArticle( i, KEduVocArticle( fem_def, fem_indef, mal_def, mal_indef, nat_def, nat_indef ) ); + m_doc->identifier(i).setArticle( KEduVocArticle( fem_def, fem_indef, mal_def, mal_indef, nat_def, nat_indef ) ); } } @@ -1163,6 +1162,8 @@ bool KEduVocKvtmlReader::readExpression( QDomElement &domElementParent ) bool KEduVocKvtmlReader::addLanguage( int languageId, const QString& language) { + +kDebug() << "addLanguage( " << languageId << ", " << language << ")"; if ( m_doc->identifierCount() <= languageId ) { m_doc->appendIdentifier(); // first entry @@ -1172,13 +1173,14 @@ bool KEduVocKvtmlReader::addLanguage( int languageId, const QString& language) } } else { if ( !language.isEmpty() ) { - if ( language != m_doc->identifier( languageId ).locale() ) { + if ( language != m_doc->identifier(languageId).locale() ) { // different originals ? m_errorMessage = i18n( "Ambiguous definition of language code" ); return false; } } } + return true; } diff --git a/keduvocdocument/keduvockvtmlwriter.cpp b/keduvocdocument/keduvockvtmlwriter.cpp index 44941a0..0dddc75 100644 --- a/keduvocdocument/keduvockvtmlwriter.cpp +++ b/keduvocdocument/keduvockvtmlwriter.cpp @@ -332,31 +332,18 @@ bool KEduVocKvtmlWriter::writeArticle( QDomDocument &domDoc, QDomElement &domEle */ { - if ( m_doc->articleCount() == 0 ) - return true; - QDomElement domElementArticle = domDoc.createElement( KV_ARTICLE_GRP ); QString def; QString indef; QString s; - for ( int i = 0; i < qMin( m_doc->articleCount(), m_doc->identifierCount() ); i++ ) + for ( int i = 0; i < m_doc->identifierCount(); i++ ) { QDomElement domElementEntry = domDoc.createElement( KV_ART_ENTRY ); - if ( i == 0 ) { - s = m_doc->identifier( 0 ).name().simplified(); - if ( s.isEmpty() ) - s = "original"; - } else { - s = m_doc->identifier( i ).name().simplified(); - if ( s.isEmpty() ) { - s.setNum( i ); - s.prepend( "translation " ); - } - } + s = m_doc->identifier(i).name().simplified(); domElementEntry.setAttribute( KV_LANG, s ); - m_doc->article( i ).getFemale( &def, &indef ); + m_doc->identifier(i).article().getFemale( &def, &indef ); if ( !def.isEmpty() ) { QDomElement domElementFD = domDoc.createElement( KV_ART_FD ); QDomText domTextFD = domDoc.createTextNode( def ); @@ -372,7 +359,7 @@ bool KEduVocKvtmlWriter::writeArticle( QDomDocument &domDoc, QDomElement &domEle domElementEntry.appendChild( domElementFI ); } - m_doc->article( i ).getMale( &def, &indef ); + m_doc->identifier(i).article().getMale( &def, &indef ); if ( !def.isEmpty() ) { QDomElement domElementMD = domDoc.createElement( KV_ART_MD ); QDomText domTextMD = domDoc.createTextNode( def ); @@ -388,7 +375,7 @@ bool KEduVocKvtmlWriter::writeArticle( QDomDocument &domDoc, QDomElement &domEle domElementEntry.appendChild( domElementMI ); } - m_doc->article( i ).getNatural( &def, &indef ); + m_doc->identifier(i).article().getNatural( &def, &indef ); if ( !def.isEmpty() ) { QDomElement domElementND = domDoc.createElement( KV_ART_ND ); QDomText domTextND = domDoc.createTextNode( def );