]> Git trees. - libqmvoc.git/commitdiff
Begin the port to new kvtml dtd and word type xml
authorFrederik Gladhorn <gladhorn@kde.org>
Tue, 27 Nov 2007 11:50:41 +0000 (11:50 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Tue, 27 Nov 2007 11:50:41 +0000 (11:50 +0000)
svn path=/branches/work/kdeedu_parley/libkdeedu/; revision=742174

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

index 2415d240853053b08797b95743cb6a029121dc32..05ceccfc098c194cac396d69808ad58fab83a7d9 100644 (file)
@@ -303,21 +303,18 @@ bool KEduVocKvtml2Reader::readTranslation( QDomElement &translationElement,
     if ( !currentElement.isNull() ) {
         QDomElement typeElement = currentElement.firstChildElement( KVTML_TYPENAME );
 
+        QString wordTypeString = typeElement.text();
+        typeElement = currentElement.firstChildElement( KVTML_WORDTYPE );
+        QString childWordTypeString = typeElement.text();
 
+        KEduVocLesson* typeLesson = m_doc->wordTypeContainer()->childLesson(wordTypeString);
+        if(!childWordTypeString.isEmpty()) {
+            typeLesson = typeLesson->childLesson(childWordTypeString);
+        }
 
-QString wordTypeString = typeElement.text();
-typeElement = currentElement.firstChildElement( KVTML_SUBTYPENAME );
-QString childWordTypeString = typeElement.text();
-
-KEduVocLesson* typeLesson = m_doc->wordTypeContainer()->childLesson(wordTypeString);
-if(!childWordTypeString.isEmpty()) {
-    typeLesson = typeLesson->childLesson(childWordTypeString);
-}
-
-if ( typeLesson ) {
-expr->translation(index)->setWordType(typeLesson);
-}
-
+        if ( typeLesson ) {
+            expr->translation(index)->setWordType(typeLesson);
+        }
     }
 
     //<pronunciation></pronunciation>
@@ -548,15 +545,15 @@ bool KEduVocKvtml2Reader::readWordTypes( QDomElement &typesElement )
                 wordTypeContainer->setContainerType(KEduVocLesson::WordTypeAdjectiveContainer);
             }
         }
-        m_doc->wordTypes().addType( mainTypeName, specialType );
+//         m_doc->wordTypes().addType( mainTypeName, specialType );
 
 
         // iterate sub type elements <subwordtypedefinition>
-        QDomElement currentSubTypeElement = currentTypeElement.firstChildElement( KVTML_SUBWORDTYPEDEFINITION );
+        QDomElement currentSubTypeElement = currentTypeElement.firstChildElement( KVTML_WORDTYPEDEFINITION );
         while ( !currentSubTypeElement.isNull() ) {
             QString specialSubType = currentSubTypeElement.firstChildElement( KVTML_SPECIALWORDTYPE ).text();
 
-            QString subTypeName = currentSubTypeElement.firstChildElement( KVTML_SUBTYPENAME ).text();
+            QString subTypeName = currentSubTypeElement.firstChildElement( KVTML_TYPENAME ).text();
             KEduVocLesson * subWordTypeContainer = new KEduVocLesson(subTypeName, wordTypeContainer);
             wordTypeContainer->appendChildLesson(subWordTypeContainer);
 
@@ -577,10 +574,9 @@ bool KEduVocKvtml2Reader::readWordTypes( QDomElement &typesElement )
             }
 
             // set type and specialtype
-            m_doc->wordTypes().addSubType( mainTypeName, subTypeName,
-                                            specialSubType );
-            currentSubTypeElement = currentSubTypeElement.nextSiblingElement( KVTML_SUBWORDTYPEDEFINITION );
-
+//             m_doc->wordTypes().addSubType( mainTypeName, subTypeName,
+//                                             specialSubType );
+            currentSubTypeElement = currentSubTypeElement.nextSiblingElement( KVTML_WORDTYPEDEFINITION );
 
         }
         currentTypeElement = currentTypeElement.nextSiblingElement( KVTML_WORDTYPEDEFINITION );
index 5c8af09a0b02e72dde3287256b0a9199b78d759e..d8fbffaaa07ce99835f1498d7a18d58915d2f057 100644 (file)
@@ -58,7 +58,7 @@ bool KEduVocKvtml2Writer::writeDoc( KEduVocDocument *doc, const QString &generat
 
     // types
     currentElement = m_domDoc.createElement( KVTML_WORDTYPEDEFINITIONS );
-    writeTypes( currentElement );
+    writeTypes( currentElement, m_doc->wordTypeContainer() );
     if ( currentElement.hasChildNodes() ) {
         domElementKvtml.appendChild( currentElement );
     }
@@ -262,51 +262,43 @@ bool KEduVocKvtml2Writer::writeArticle( QDomElement &articleElement, int article
     return true;
 }
 
-bool KEduVocKvtml2Writer::writeTypes( QDomElement &typesElement )
+bool KEduVocKvtml2Writer::writeTypes( QDomElement &typesElement, KEduVocLesson* parentContainer )
 {
-    KEduVocWordType wt = m_doc->wordTypes();
-    foreach( QString mainTypeName, wt.typeNameList() ) {
-        kDebug() << "Writing type: " << mainTypeName;
+    foreach( KEduVocLesson* wordType, parentContainer->childLessons() ) {
+        kDebug() << "Writing type: " << wordType->name();
+
         QDomElement typeDefinitionElement = m_domDoc.createElement( KVTML_WORDTYPEDEFINITION );
-        typeDefinitionElement.appendChild( newTextElement( KVTML_TYPENAME, mainTypeName ) );
+        typeDefinitionElement.appendChild( newTextElement( KVTML_TYPENAME, wordType->name() ) );
 
-        QString specialType = wt.specialType( mainTypeName );
-        if ( !specialType.isEmpty() ) {
-            // get the NOT localized version for the doc
-            if ( specialType == m_doc->wordTypes().specialTypeNoun() ) {
-                specialType = KVTML_SPECIALWORDTYPE_NOUN;
-            }
-            if ( specialType == m_doc->wordTypes().specialTypeVerb()) {
-                specialType =  KVTML_SPECIALWORDTYPE_VERB;
-            }
-            if ( specialType == m_doc->wordTypes().specialTypeAdverb()) {
-                specialType = KVTML_SPECIALWORDTYPE_ADVERB;
-            }
-            if ( specialType ==  m_doc->wordTypes().specialTypeAdjective()) {
-                specialType = KVTML_SPECIALWORDTYPE_ADJECTIVE;
-            }
-            typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, specialType ) );
+        switch (wordType->containerType()) {
+        case KEduVocLesson::WordTypeNounContainer:
+            typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_NOUN ) );
+            break;
+        case KEduVocLesson::WordTypeNounMaleContainer:
+            typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_NOUN_MALE ) );
+            break;
+        case KEduVocLesson::WordTypeNounFemaleContainer:
+            typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_NOUN_FEMALE ) );
+            break;
+        case KEduVocLesson::WordTypeNounNeutralContainer:
+            typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_NOUN_NEUTRAL ) );
+            break;
+        case KEduVocLesson::WordTypeVerbContainer:
+            typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_VERB ) );
+            break;
+        case KEduVocLesson::WordTypeAdjectiveContainer:
+            typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_ADJECTIVE ) );
+            break;
+        case KEduVocLesson::WordTypeAdverbContainer:
+            typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_ADVERB ) );
+            break;
+        default:
+            // no special type, no tag
+            break;
         }
 
-        // subtypes
-        foreach( QString subTypeName, wt.subTypeNameList( mainTypeName ) ) {
-            QDomElement subTypeDefinitionElement = m_domDoc.createElement( KVTML_SUBWORDTYPEDEFINITION );
-            subTypeDefinitionElement.appendChild( newTextElement( KVTML_SUBTYPENAME, subTypeName ) );
-            QString specialSubType = wt.specialSubType( mainTypeName, subTypeName );
-            if ( !specialSubType.isEmpty() ) {
-                if ( specialSubType == m_doc->wordTypes().specialTypeNounMale() ) {
-                    specialSubType = KVTML_SPECIALWORDTYPE_NOUN_MALE;
-                }
-                if ( specialSubType == m_doc->wordTypes().specialTypeNounFemale() ) {
-                    specialSubType = KVTML_SPECIALWORDTYPE_NOUN_FEMALE;
-                }
-                if ( specialSubType == m_doc->wordTypes().specialTypeNounNeutral() ) {
-                    specialSubType = KVTML_SPECIALWORDTYPE_NOUN_NEUTRAL;
-                }
-                subTypeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, specialSubType ) );
-            }
-            typeDefinitionElement.appendChild( subTypeDefinitionElement );
-        }
+        writeTypes( typeDefinitionElement, wordType );
+
         typesElement.appendChild( typeDefinitionElement );
     }
     return true;
@@ -359,22 +351,14 @@ bool KEduVocKvtml2Writer::writeTranslation( QDomElement &translationElement, KEd
 {
     // <text>Kniebeugen</text>
     translationElement.appendChild( newTextElement( KVTML_TEXT, translation->text() ) );
-
+kDebug() << "write tranlation:" << translation->text();
     // <wordtype></wordtype>
     if ( translation->wordType() ) {
+kDebug() << "word type" << translation->wordType()->name();
         QDomElement wordTypeElement = m_domDoc.createElement( KVTML_WORDTYPE );
         translationElement.appendChild( wordTypeElement );
         //<typename>noun</typename>
-
-        if(translation->wordType()->parent() == m_doc->wordTypeContainer()) {
-            wordTypeElement.appendChild( newTextElement( KVTML_TYPENAME, translation->wordType()->name() ) );
-        } else {
-            if(translation->wordType()->parent()->parent() == m_doc->wordTypeContainer()) {
-                wordTypeElement.appendChild( newTextElement( KVTML_TYPENAME, translation->wordType()->parent()->name() ) );
-            // <subwordtype>male</subwordtype>
-                wordTypeElement.appendChild( newTextElement( KVTML_SUBTYPENAME, translation->wordType()->name() ) );
-            }
-        }
+        wordTypeElement.appendChild( newTextElement( KVTML_TYPENAME, translation->wordType()->name() ) );
     }
 
     // <comment></comment>
index 8c32fc8a4d76f135fb46f6c4519db4195ccc026d..d1f186d362715d26a3c5bb5d7136f56edffcec71 100644 (file)
@@ -70,7 +70,7 @@ public:
     /** write types
      * @param typesElement QDomElement types to write to
      */
-    bool writeTypes( QDomElement &typesElement );
+    bool writeTypes( QDomElement &typesElement, KEduVocLesson* parentContainer );
 
     /** write tenses
      * @param tensesElement QDomElement tenses to write to
index a269b6faad03f28256a8931acd9ce9c504c1515d..0742664336f1960dbe69156efb43aa9419796566 100644 (file)
@@ -140,7 +140,9 @@ int KEduVocLesson::entryCount()
 void KEduVocLesson::addEntry(KEduVocExpression* entry)
 {
     d->m_entries.append( entry );
-    entry->addLesson(this);
+    if(d->m_type == LessonContainer) {
+        entry->addLesson(this);
+    }
 }
 
 void KEduVocLesson::removeEntry(KEduVocExpression* entry)
@@ -206,7 +208,10 @@ KEduVocLesson * KEduVocLesson::childLesson(const QString & name)
             return d->m_childLessons[i];
         }
     }
-    return 0;
+
+    KEduVocLesson* newLesson = new KEduVocLesson(name, this);
+    appendChildLesson(newLesson);
+    return newLesson;
 }
 
 void KEduVocLesson::setContainerType(KEduVocLesson::EnumContainerType type)
index 7497aacfdc586cc9e48e5a95fee55738d6a1fcc0..f3d2525b6fcfee212a9903d74863cd167f12122d 100644 (file)
@@ -52,6 +52,11 @@ public:
 
     QList<KEduVocLesson *> childLessons();
     KEduVocLesson *childLesson(int row);
+    /**
+     * Find a child lesson, creates a new lesson it if it does not exist!
+     * @param name 
+     * @return 
+     */
     KEduVocLesson *childLesson(const QString& name);
     int childLessonCount() const;
 
index 9547fa6dd4bad0b91818e5e223a6293e4a47c1af..c3f181742f95c1bf9e4cedf37c24e48cb123ebcf 100644 (file)
@@ -374,7 +374,7 @@ void KEduVocTranslation::setWordType(KEduVocLesson * wordType)
     }
     if ( wordType ) {
         wordType->addEntry(d->m_entry);
+        d->m_wordType = wordType;
     }
 }
 
-
index 04abd5f733f573cbde105375e6de70c3e8a7cccd..d3cea46ebc63ef559d06419f268dcbf236f541e1 100644 (file)
 // word types
 #define KVTML_WORDTYPEDEFINITIONS   "wordtypedefinitions"
 #define KVTML_WORDTYPEDEFINITION    "wordtypedefinition"
-#define KVTML_SUBWORDTYPEDEFINITION   "subwordtypedefinition"
 
 #define KVTML_WORDTYPE              "wordtype"
 #define KVTML_TYPENAME              "typename"
-#define KVTML_SUBTYPENAME           "subtypename"
 
 // these are necessary to enable practices based on word types. users can give types arbitrary names, but these few are hardcoded.
 #define KVTML_SPECIALWORDTYPE       "specialwordtype"
 #define KVTML_SPECIALWORDTYPE_NOUN        "noun"
-#define KVTML_SPECIALWORDTYPE_NOUN_MALE   "male"
-#define KVTML_SPECIALWORDTYPE_NOUN_FEMALE "female"
-#define KVTML_SPECIALWORDTYPE_NOUN_NEUTRAL "neutral"
+#define KVTML_SPECIALWORDTYPE_NOUN_MALE   "noun/male"
+#define KVTML_SPECIALWORDTYPE_NOUN_FEMALE "noun/female"
+#define KVTML_SPECIALWORDTYPE_NOUN_NEUTRAL "noun/neutral"
 #define KVTML_SPECIALWORDTYPE_VERB        "verb"
 #define KVTML_SPECIALWORDTYPE_ADJECTIVE   "adjective"
 #define KVTML_SPECIALWORDTYPE_ADVERB      "adverb"