From: Frederik Gladhorn Date: Tue, 27 Nov 2007 11:50:41 +0000 (+0000) Subject: Begin the port to new kvtml dtd and word type xml X-Git-Tag: v4.0.71~93^2~21 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=4e1d7e339c78a43e09aaceec6b1c73b16a5a436c;p=libqmvoc.git Begin the port to new kvtml dtd and word type xml svn path=/branches/work/kdeedu_parley/libkdeedu/; revision=742174 --- diff --git a/keduvocdocument/keduvockvtml2reader.cpp b/keduvocdocument/keduvockvtml2reader.cpp index 2415d24..05ceccf 100644 --- a/keduvocdocument/keduvockvtml2reader.cpp +++ b/keduvocdocument/keduvockvtml2reader.cpp @@ -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); + } } // @@ -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 - 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 ); diff --git a/keduvocdocument/keduvockvtml2writer.cpp b/keduvocdocument/keduvockvtml2writer.cpp index 5c8af09..d8fbffa 100644 --- a/keduvocdocument/keduvockvtml2writer.cpp +++ b/keduvocdocument/keduvockvtml2writer.cpp @@ -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 { // Kniebeugen translationElement.appendChild( newTextElement( KVTML_TEXT, translation->text() ) ); - +kDebug() << "write tranlation:" << translation->text(); // if ( translation->wordType() ) { +kDebug() << "word type" << translation->wordType()->name(); QDomElement wordTypeElement = m_domDoc.createElement( KVTML_WORDTYPE ); translationElement.appendChild( wordTypeElement ); //noun - - 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() ) ); - // male - wordTypeElement.appendChild( newTextElement( KVTML_SUBTYPENAME, translation->wordType()->name() ) ); - } - } + wordTypeElement.appendChild( newTextElement( KVTML_TYPENAME, translation->wordType()->name() ) ); } // diff --git a/keduvocdocument/keduvockvtml2writer.h b/keduvocdocument/keduvockvtml2writer.h index 8c32fc8..d1f186d 100644 --- a/keduvocdocument/keduvockvtml2writer.h +++ b/keduvocdocument/keduvockvtml2writer.h @@ -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 diff --git a/keduvocdocument/keduvoclesson.cpp b/keduvocdocument/keduvoclesson.cpp index a269b6f..0742664 100644 --- a/keduvocdocument/keduvoclesson.cpp +++ b/keduvocdocument/keduvoclesson.cpp @@ -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) diff --git a/keduvocdocument/keduvoclesson.h b/keduvocdocument/keduvoclesson.h index 7497aac..f3d2525 100644 --- a/keduvocdocument/keduvoclesson.h +++ b/keduvocdocument/keduvoclesson.h @@ -52,6 +52,11 @@ public: QList 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; diff --git a/keduvocdocument/keduvoctranslation.cpp b/keduvocdocument/keduvoctranslation.cpp index 9547fa6..c3f1817 100644 --- a/keduvocdocument/keduvoctranslation.cpp +++ b/keduvocdocument/keduvoctranslation.cpp @@ -374,7 +374,7 @@ void KEduVocTranslation::setWordType(KEduVocLesson * wordType) } if ( wordType ) { wordType->addEntry(d->m_entry); + d->m_wordType = wordType; } } - diff --git a/keduvocdocument/kvtml2defs.h b/keduvocdocument/kvtml2defs.h index 04abd5f..d3cea46 100644 --- a/keduvocdocument/kvtml2defs.h +++ b/keduvocdocument/kvtml2defs.h @@ -70,18 +70,16 @@ // 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"