]> Git trees. - libqmvoc.git/commitdiff
Add words to their word type container when reading them. Not written correctly yet.
authorFrederik Gladhorn <gladhorn@kde.org>
Thu, 22 Nov 2007 23:53:10 +0000 (23:53 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Thu, 22 Nov 2007 23:53:10 +0000 (23:53 +0000)
svn path=/branches/work/kdeedu_parley/libkdeedu/; revision=740313

keduvocdocument/keduvocdocument.cpp
keduvocdocument/keduvockvtml2reader.cpp
keduvocdocument/keduvockvtml2reader.h
keduvocdocument/keduvoclesson.cpp
keduvocdocument/keduvoclesson.h
keduvocdocument/keduvoctranslation.cpp

index 043762fb86319e5713cbcde18725acabb22b7b2c..217ad54cc19014a21ca2caf62d89b7f3ef151ae2 100644 (file)
@@ -113,10 +113,12 @@ void KEduVocDocument::KEduVocDocumentPrivate::init()
         delete m_lessonContainer;
     }
     m_lessonContainer = new KEduVocLesson("root");
+    m_lessonContainer->setContainerType(KEduVocLesson::LessonContainer);
     if ( m_wordTypeContainer ) {
         delete m_wordTypeContainer;
     }
     m_wordTypeContainer = new KEduVocLesson(i18n( "Word types" ));
+    m_wordTypeContainer->setContainerType(KEduVocLesson::WordTypeContainer);
 
     m_tenseDescriptions.clear();
     m_identifiers.clear();
index e27079a1d857d8041fb1f99606f00fcb2779b14a..2415d240853053b08797b95743cb6a029121dc32 100644 (file)
@@ -161,7 +161,7 @@ bool KEduVocKvtml2Reader::readGroups( QDomElement &domElementParent )
 
     groupElement = domElementParent.firstChildElement( KVTML_WORDTYPEDEFINITIONS );
     if ( !groupElement.isNull() ) {
-        readTypes( groupElement );
+        readWordTypes( groupElement );
     }
 
     groupElement = domElementParent.firstChildElement( KVTML_TENSES );
@@ -263,15 +263,6 @@ bool KEduVocKvtml2Reader::readEntry( QDomElement &entryElement )
         }
     }
 
-//     currentElement = entryElement.firstChildElement( KVTML_INQUERY );
-//     if ( !currentElement.isNull() ) {
-//         // set the inquery information
-//         if ( currentElement.text() == KVTML_TRUE ) {
-//             expr->setInPractice( true );
-//         } else {
-//             expr->setInPractice( false );
-//         }
-//     }
 
     // read translation children
     QDomNodeList translationList = entryElement.elementsByTagName( KVTML_TRANSLATION );
@@ -312,6 +303,8 @@ bool KEduVocKvtml2Reader::readTranslation( QDomElement &translationElement,
     if ( !currentElement.isNull() ) {
         QDomElement typeElement = currentElement.firstChildElement( KVTML_TYPENAME );
 
+
+
 QString wordTypeString = typeElement.text();
 typeElement = currentElement.firstChildElement( KVTML_SUBTYPENAME );
 QString childWordTypeString = typeElement.text();
@@ -321,8 +314,10 @@ if(!childWordTypeString.isEmpty()) {
     typeLesson = typeLesson->childLesson(childWordTypeString);
 }
 
-
+if ( typeLesson ) {
 expr->translation(index)->setWordType(typeLesson);
+}
+
     }
 
     //<pronunciation></pronunciation>
@@ -518,63 +513,74 @@ bool KEduVocKvtml2Reader::readArticle( QDomElement &articleElement, int identifi
 }
 
 
-bool KEduVocKvtml2Reader::readTypes( QDomElement &typesElement )
+bool KEduVocKvtml2Reader::readWordTypes( QDomElement &typesElement )
 {
     QString mainTypeName;
 
-    QDomElement currentTypeElement =    typesElement.firstChildElement( KVTML_WORDTYPEDEFINITION );
+    QDomElement currentTypeElement = typesElement.firstChildElement( KVTML_WORDTYPEDEFINITION );
     // go over <wordtypedefinition> elements
     while ( !currentTypeElement.isNull() ) {
         // set type and specialtype
         mainTypeName =
             currentTypeElement.firstChildElement( KVTML_TYPENAME ).text();
 
+        KEduVocLesson * wordTypeContainer = new KEduVocLesson(mainTypeName, m_doc->wordTypeContainer());
+        m_doc->wordTypeContainer()->appendChildLesson(wordTypeContainer);
+
+
         QString specialType = currentTypeElement.firstChildElement( KVTML_SPECIALWORDTYPE ).text();
         if ( !specialType.isEmpty() ) {
             // get the localized version
             if ( specialType == KVTML_SPECIALWORDTYPE_NOUN ) {
                 specialType = m_doc->wordTypes().specialTypeNoun();
+                wordTypeContainer->setContainerType(KEduVocLesson::WordTypeNounContainer);
             }
             if ( specialType == KVTML_SPECIALWORDTYPE_VERB ) {
                 specialType = m_doc->wordTypes().specialTypeVerb();
+                wordTypeContainer->setContainerType(KEduVocLesson::WordTypeVerbContainer);
             }
             if ( specialType == KVTML_SPECIALWORDTYPE_ADVERB ) {
                 specialType = m_doc->wordTypes().specialTypeAdverb();
+                wordTypeContainer->setContainerType(KEduVocLesson::WordTypeAdverbContainer);
             }
             if ( specialType == KVTML_SPECIALWORDTYPE_ADJECTIVE ) {
                 specialType = m_doc->wordTypes().specialTypeAdjective();
+                wordTypeContainer->setContainerType(KEduVocLesson::WordTypeAdjectiveContainer);
             }
         }
         m_doc->wordTypes().addType( mainTypeName, specialType );
 
-        KEduVocLesson * wordTypeContainer = new KEduVocLesson(mainTypeName, m_doc->wordTypeContainer());
-        m_doc->wordTypeContainer()->appendChildLesson(wordTypeContainer);
 
         // iterate sub type elements <subwordtypedefinition>
         QDomElement currentSubTypeElement = currentTypeElement.firstChildElement( KVTML_SUBWORDTYPEDEFINITION );
         while ( !currentSubTypeElement.isNull() ) {
             QString specialSubType = currentSubTypeElement.firstChildElement( KVTML_SPECIALWORDTYPE ).text();
+
+            QString subTypeName = currentSubTypeElement.firstChildElement( KVTML_SUBTYPENAME ).text();
+            KEduVocLesson * subWordTypeContainer = new KEduVocLesson(subTypeName, wordTypeContainer);
+            wordTypeContainer->appendChildLesson(subWordTypeContainer);
+
             if ( !specialSubType.isEmpty() ) {
                 // get the localized version
                 if ( specialSubType == KVTML_SPECIALWORDTYPE_NOUN_MALE ) {
                     specialSubType = m_doc->wordTypes().specialTypeNounMale();
+                    subWordTypeContainer->setContainerType(KEduVocLesson::WordTypeNounMaleContainer);
                 }
                 if ( specialSubType == KVTML_SPECIALWORDTYPE_NOUN_FEMALE ) {
                     specialSubType = m_doc->wordTypes().specialTypeNounFemale();
+                    subWordTypeContainer->setContainerType(KEduVocLesson::WordTypeNounFemaleContainer);
                 }
                 if ( specialSubType == KVTML_SPECIALWORDTYPE_NOUN_NEUTRAL ) {
                     specialSubType = m_doc->wordTypes().specialTypeNounNeutral();
+                    subWordTypeContainer->setContainerType(KEduVocLesson::WordTypeNounNeutralContainer);
                 }
             }
 
-            QString subTypeName = currentSubTypeElement.firstChildElement( KVTML_SUBTYPENAME ).text();
             // set type and specialtype
             m_doc->wordTypes().addSubType( mainTypeName, subTypeName,
                                             specialSubType );
             currentSubTypeElement = currentSubTypeElement.nextSiblingElement( KVTML_SUBWORDTYPEDEFINITION );
 
-            KEduVocLesson * subWordTypeLesson = new KEduVocLesson(subTypeName, wordTypeContainer);
-            wordTypeContainer->appendChildLesson(subWordTypeLesson);
 
         }
         currentTypeElement = currentTypeElement.nextSiblingElement( KVTML_WORDTYPEDEFINITION );
index e6368ccc0ff5fe0c0f08796abffdd20786b862f1..4c39acb6ff6e10fb7212fbc3a62f1fa3b0ee8c92 100644 (file)
@@ -88,7 +88,7 @@ private:
     /** read the types
      * @param typesElement QDomElement for the types group
      */
-    bool readTypes( QDomElement &typesElement );
+    bool readWordTypes( QDomElement &typesElement );
 
     /** read the tenses
      * @param tensesElement QDomElement for the tenses group
index f0f40dfe7ee6604a134c2e321f8a39dc5f6a75b0..11765651a1f31499372f7d3dfafbe7ecd034e77c 100644 (file)
@@ -40,6 +40,8 @@ public:
 
     // entries
     QList<KEduVocExpression*> m_entries;
+
+    EnumContainerType m_type;
 };
 
 KEduVocLesson::Private::~ Private()
@@ -56,6 +58,11 @@ KEduVocLesson::KEduVocLesson(const QString& name, KEduVocLesson *parent)
     d->m_parentLesson = parent;
     d->m_name = name;
     d->m_inPractice = false;
+    if(parent) {
+        d->m_type = parent->containerType();
+    } else {
+        d->m_type = LessonContainer;
+    }
 }
 
 KEduVocLesson::KEduVocLesson( const KEduVocLesson &other )
@@ -195,9 +202,19 @@ 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 d->m_childLessons[i];
         }
     }
     return 0;
 }
 
+void KEduVocLesson::setContainerType(KEduVocLesson::EnumContainerType type)
+{
+    d->m_type = type;
+}
+
+KEduVocLesson::EnumContainerType KEduVocLesson::containerType()
+{
+    return d->m_type;
+}
+
index 296267b2160d0d8c5408b6a897f6536ac65f4ba7..7497aacfdc586cc9e48e5a95fee55738d6a1fcc0 100644 (file)
@@ -31,21 +31,32 @@ class KEduVocExpression;
 /** class to store information about a lesson */
 class KEDUVOCDOCUMENT_EXPORT KEduVocLesson
 {
-
 public:
-     /** default constructor */
-     explicit KEduVocLesson(const QString& name, KEduVocLesson *parent = 0);
-
-     void appendChildLesson(KEduVocLesson *child);
-
-     QList<KEduVocLesson *> childLessons();
-     KEduVocLesson *childLesson(int row);
-     KEduVocLesson *childLesson(const QString& name);
-     int childLessonCount() const;
-
-     int row() const;
-     KEduVocLesson *parent();
-
+    enum EnumContainerType{
+        LessonContainer,
+        LeitnerContainer,
+        WordTypeContainer,
+        WordTypeNounContainer,
+        WordTypeNounMaleContainer,
+        WordTypeNounFemaleContainer,
+        WordTypeNounNeutralContainer,
+        WordTypeVerbContainer,
+        WordTypeAdjectiveContainer,
+        WordTypeAdverbContainer
+    };
+
+    /** default constructor */
+    explicit KEduVocLesson(const QString& name, KEduVocLesson *parent = 0);
+
+    void appendChildLesson(KEduVocLesson *child);
+
+    QList<KEduVocLesson *> childLessons();
+    KEduVocLesson *childLesson(int row);
+    KEduVocLesson *childLesson(const QString& name);
+    int childLessonCount() const;
+
+    int row() const;
+    KEduVocLesson *parent();
 
     /** copy constructor for d-pointer safe copying */
     KEduVocLesson( const KEduVocLesson &other );
@@ -96,6 +107,20 @@ public:
     /** equality operator */
     bool operator==(const KEduVocLesson &other);
 
+
+    /**
+     * The type of this container. @see EnumContainerType
+     * @return 
+     */
+    KEduVocLesson::EnumContainerType containerType();
+
+    /**
+     * Set the type of container.
+     * For convenience by default this is taken over from the parent, so no need to set.
+     * @param type the new type
+     */
+    void setContainerType(KEduVocLesson::EnumContainerType type);
+
 private:
     class Private;
     Private * const d;
index e84cfe6f629ff4350769ba95f8bec0146da01f24..d28a4fa07203a15e38e0e711038ca755d7ce5336 100644 (file)
@@ -372,6 +372,8 @@ void KEduVocTranslation::setWordType(KEduVocLesson * wordType)
     if ( d->m_wordType ) {
         d->m_wordType->removeEntry(d->m_entry);
     }
-    
+    if ( wordType ) {
+        wordType->addEntry(d->m_entry);
+    }
 }