From: Frederik Gladhorn Date: Thu, 22 Nov 2007 23:53:10 +0000 (+0000) Subject: Add words to their word type container when reading them. Not written correctly yet. X-Git-Tag: v4.0.71~93^2~24 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=0337bf91a3420497203765d7b7662921244921cb;p=libqmvoc.git Add words to their word type container when reading them. Not written correctly yet. svn path=/branches/work/kdeedu_parley/libkdeedu/; revision=740313 --- diff --git a/keduvocdocument/keduvocdocument.cpp b/keduvocdocument/keduvocdocument.cpp index 043762f..217ad54 100644 --- a/keduvocdocument/keduvocdocument.cpp +++ b/keduvocdocument/keduvocdocument.cpp @@ -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(); diff --git a/keduvocdocument/keduvockvtml2reader.cpp b/keduvocdocument/keduvockvtml2reader.cpp index e27079a..2415d24 100644 --- a/keduvocdocument/keduvockvtml2reader.cpp +++ b/keduvocdocument/keduvockvtml2reader.cpp @@ -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); +} + } // @@ -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 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 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 ); diff --git a/keduvocdocument/keduvockvtml2reader.h b/keduvocdocument/keduvockvtml2reader.h index e6368cc..4c39acb 100644 --- a/keduvocdocument/keduvockvtml2reader.h +++ b/keduvocdocument/keduvockvtml2reader.h @@ -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 diff --git a/keduvocdocument/keduvoclesson.cpp b/keduvocdocument/keduvoclesson.cpp index f0f40df..1176565 100644 --- a/keduvocdocument/keduvoclesson.cpp +++ b/keduvocdocument/keduvoclesson.cpp @@ -40,6 +40,8 @@ public: // entries QList 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; im_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; +} + diff --git a/keduvocdocument/keduvoclesson.h b/keduvocdocument/keduvoclesson.h index 296267b..7497aac 100644 --- a/keduvocdocument/keduvoclesson.h +++ b/keduvocdocument/keduvoclesson.h @@ -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 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 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; diff --git a/keduvocdocument/keduvoctranslation.cpp b/keduvocdocument/keduvoctranslation.cpp index e84cfe6..d28a4fa 100644 --- a/keduvocdocument/keduvoctranslation.cpp +++ b/keduvocdocument/keduvoctranslation.cpp @@ -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); + } }