]> Git trees. - libqmvoc.git/commitdiff
Moved article management from doc class to identifier.
authorFrederik Gladhorn <gladhorn@kde.org>
Thu, 30 Aug 2007 12:08:14 +0000 (12:08 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Thu, 30 Aug 2007 12:08:14 +0000 (12:08 +0000)
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=706431

keduvocdocument/keduvocdocument.cpp
keduvocdocument/keduvocdocument.h
keduvocdocument/keduvocidentifier.cpp
keduvocdocument/keduvocidentifier.h
keduvocdocument/keduvockvtml2reader.cpp
keduvocdocument/keduvockvtml2writer.cpp
keduvocdocument/keduvockvtmlreader.cpp
keduvocdocument/keduvockvtmlwriter.cpp

index a6dc68b0c96dce7a63a5e2ab38723bee177735df..12c6b6b98712d161f77ba6fca04445e93268a5b9 100644 (file)
@@ -96,7 +96,6 @@ public:
       */
     QString                   m_category;
 
-    QList<KEduVocArticle>     m_articles;
     QList<KEduVocConjugation> 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 ) {
index 685b19c98391acba68bcfc04c5cdd12108a2eeba..df22271b3077439f0b24db1bce6738c5c9d0c5f2 100644 (file)
@@ -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 ***
 
     /**
index d1dd3d0162d80d92cf39a3b42e0eb6ee86520b5f..cf7bd2320d69def62217dd7aec6e56e169a68310 100644 (file)
@@ -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;
+}
+
index 1b48201308710635b75672b0dad2ad29ff1b64f9..696919199a5243d2b1f9f5634e1698f4a8ac80a6 100644 (file)
@@ -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;
index fa37fe0b6ea59b4fdb7b8bd7062524a801df9211..a861cbbe110cac9195cd02e67f190ab0c4e21c8c 100644 (file)
@@ -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;
 }
index 2544c164391fea62799ab8dc0b7d79d6c6da04ec..620ec7e7da4f6542572e8a5e74ae3aab0d64bbb2 100644 (file)
@@ -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 ) );
     }
index ee748a282c7629ecd6b3a6c5643395e7c05f9a6e..30441a2aae92da10b815b7c61ffe4842d3b6e342 100644 (file)
@@ -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;
 }
 
 
index 44941a0d7b91f250a88c3257fb53b325f9c20edd..0dddc75e499c24f8583bcc6577448f195b7e30ba 100644 (file)
@@ -332,31 +332,18 @@ bool KEduVocKvtmlWriter::writeArticle( QDomDocument &domDoc, QDomElement &domEle
  </article>
 */
 {
-    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 );