From 7989d8ceca6d7b8294db4cb32bdc6daffbe03d1b Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Tue, 27 Nov 2007 21:33:35 +0000 Subject: [PATCH] Add a word type class derived from container. Make the layout of the word type widget better. Make the adjective/adverb buttons work. Save the changes to the comparison forms. svn path=/branches/work/kdeedu_parley/libkdeedu/; revision=742345 --- keduvocdocument/keduvoccontainer.cpp | 16 +- keduvocdocument/keduvoccontainer.h | 8 +- keduvocdocument/keduvocdocument.cpp | 16 +- keduvocdocument/keduvocdocument.h | 2 +- keduvocdocument/keduvocexpression.cpp | 1 + keduvocdocument/keduvockvtml2reader.cpp | 6 +- keduvocdocument/keduvockvtml2reader.h | 5 +- keduvocdocument/keduvockvtml2writer.cpp | 4 +- keduvocdocument/keduvockvtml2writer.h | 2 +- keduvocdocument/keduvoclesson.h | 3 - keduvocdocument/keduvoctranslation.cpp | 18 +- keduvocdocument/keduvoctranslation.h | 8 +- keduvocdocument/keduvocwordtype.cpp | 350 +++--------------------- keduvocdocument/keduvocwordtype.h | 140 +++------- 14 files changed, 119 insertions(+), 460 deletions(-) diff --git a/keduvocdocument/keduvoccontainer.cpp b/keduvocdocument/keduvoccontainer.cpp index 5086fb8..dfdcd29 100644 --- a/keduvocdocument/keduvoccontainer.cpp +++ b/keduvocdocument/keduvoccontainer.cpp @@ -50,7 +50,7 @@ KEduVocContainer::KEduVocContainer(const QString& name, EnumContainerType type, { d->m_parentContainer = parent; d->m_name = name; - d->m_inPractice = false; + d->m_inPractice = true; d->m_type = type; } @@ -188,4 +188,18 @@ void KEduVocContainer::setImageUrl(const KUrl &url) d->m_imageUrl = url; } +KEduVocContainer * KEduVocContainer::childOfType(KEduVocContainer::EnumContainerType type) +{ + if(containerType()==type) { + return this; + } + foreach(KEduVocContainer* child, childContainers()) { + KEduVocContainer* result = child->childOfType(type); + if(result) { + return result; + } + } + return 0; +} + diff --git a/keduvocdocument/keduvoccontainer.h b/keduvocdocument/keduvoccontainer.h index 377bdcb..3886b2f 100644 --- a/keduvocdocument/keduvoccontainer.h +++ b/keduvocdocument/keduvoccontainer.h @@ -62,13 +62,13 @@ public: int childContainerCount() const; int row() const; - KEduVocContainer *parent(); + virtual KEduVocContainer *parent(); /** copy constructor for d-pointer safe copying */ KEduVocContainer( const KEduVocContainer &other ); /** destructor */ - ~KEduVocContainer(); + virtual ~KEduVocContainer(); /** assignment operator */ KEduVocContainer& operator= ( const KEduVocContainer& ); @@ -83,6 +83,8 @@ public: /** get a list of all entries in the container */ virtual QList < KEduVocExpression* > entries() =0; + virtual int entryCount() =0; + virtual KEduVocExpression* entry(int row) =0; /** get a list of all entries in the container and its child containers */ QList < KEduVocExpression* > entriesRecursive(); @@ -112,6 +114,8 @@ public: */ void setContainerType(KEduVocContainer::EnumContainerType type); + KEduVocContainer* childOfType(KEduVocContainer::EnumContainerType type); + /** get the image url for this container if it exists */ KUrl imageUrl(); diff --git a/keduvocdocument/keduvocdocument.cpp b/keduvocdocument/keduvocdocument.cpp index c99a7eb..feb00b0 100644 --- a/keduvocdocument/keduvocdocument.cpp +++ b/keduvocdocument/keduvocdocument.cpp @@ -97,10 +97,9 @@ public: QString m_category; KEduVocLesson * m_lessonContainer; - KEduVocLesson * m_wordTypeContainer; + KEduVocWordType * m_wordTypeContainer; KEduVocLesson * m_leitnerContainer; - KEduVocWordType m_wordTypes; }; KEduVocDocument::KEduVocDocumentPrivate::~KEduVocDocumentPrivate() @@ -117,12 +116,10 @@ void KEduVocDocument::KEduVocDocumentPrivate::init() if ( m_wordTypeContainer ) { delete m_wordTypeContainer; } - m_wordTypeContainer = new KEduVocLesson(i18n( "Word types" )); - m_wordTypeContainer->setContainerType(KEduVocLesson::WordTypeContainer); + m_wordTypeContainer = new KEduVocWordType(i18n( "Word types" )); m_tenseDescriptions.clear(); m_identifiers.clear(); - m_wordTypes.clear(); m_extraSizeHints.clear(); m_sizeHints.clear(); m_dirty = false; @@ -726,7 +723,7 @@ KEduVocLesson * KEduVocDocument::lesson() return d->m_lessonContainer; } -KEduVocLesson * KEduVocDocument::wordTypeContainer() +KEduVocWordType * KEduVocDocument::wordTypeContainer() { return d->m_wordTypeContainer; } @@ -952,10 +949,5 @@ QString KEduVocDocument::errorDescription( int errorCode ) } } -KEduVocWordType& KEduVocDocument::wordTypes() -{ - return d->m_wordTypes; -} - - #include "keduvocdocument.moc" + diff --git a/keduvocdocument/keduvocdocument.h b/keduvocdocument/keduvocdocument.h index 4aa3c6c..f0eb2a5 100644 --- a/keduvocdocument/keduvocdocument.h +++ b/keduvocdocument/keduvocdocument.h @@ -340,7 +340,7 @@ public: */ KEduVocLesson * lesson(); - KEduVocLesson * wordTypeContainer(); + KEduVocWordType * wordTypeContainer(); KEduVocLesson * leitnerContainer(); diff --git a/keduvocdocument/keduvocexpression.cpp b/keduvocdocument/keduvocexpression.cpp index b30095c..3131c23 100644 --- a/keduvocdocument/keduvocexpression.cpp +++ b/keduvocdocument/keduvocexpression.cpp @@ -159,6 +159,7 @@ KEduVocTranslation* KEduVocExpression::translation( int index ) return d->m_translations[index]; } d->m_translations[index] = new KEduVocTranslation(this); + return d->m_translations[index]; } QList< int > KEduVocExpression::translationIndices() const diff --git a/keduvocdocument/keduvockvtml2reader.cpp b/keduvocdocument/keduvockvtml2reader.cpp index dd685a5..1e67a72 100644 --- a/keduvocdocument/keduvockvtml2reader.cpp +++ b/keduvocdocument/keduvockvtml2reader.cpp @@ -511,7 +511,7 @@ bool KEduVocKvtml2Reader::readArticle( QDomElement &articleElement, int identifi } -bool KEduVocKvtml2Reader::readChildWordTypes( KEduVocLesson* parentContainer, QDomElement &lessonElement ) +bool KEduVocKvtml2Reader::readChildWordTypes(KEduVocWordType* parentContainer, QDomElement &lessonElement) { QDomElement currentElement = lessonElement.firstChildElement( KVTML_CONTAINER ); while ( !currentElement.isNull() ) { @@ -521,13 +521,13 @@ bool KEduVocKvtml2Reader::readChildWordTypes( KEduVocLesson* parentContainer, QD return true; } -bool KEduVocKvtml2Reader::readWordType( KEduVocLesson* parentContainer, QDomElement &typeElement ) +bool KEduVocKvtml2Reader::readWordType( KEduVocWordType* parentContainer, QDomElement &typeElement ) { // set type and specialtype QString typeName = typeElement.firstChildElement( KVTML_NAME ).text(); - KEduVocLesson * wordTypeContainer = new KEduVocLesson(typeName, parentContainer); + KEduVocWordType * wordTypeContainer = new KEduVocWordType(typeName, parentContainer); parentContainer->appendChildContainer(wordTypeContainer); QString specialType = typeElement.firstChildElement( KVTML_SPECIALWORDTYPE ).text(); diff --git a/keduvocdocument/keduvockvtml2reader.h b/keduvocdocument/keduvockvtml2reader.h index 487ac7f..440dc3f 100644 --- a/keduvocdocument/keduvockvtml2reader.h +++ b/keduvocdocument/keduvockvtml2reader.h @@ -26,6 +26,7 @@ class QIODevice; class KEduVocDocument; +class KEduVocWordType; /** * @brief class to read kvtml2 data files into keduvocdocument @@ -91,7 +92,7 @@ private: * @param typesElement * @return */ - bool readWordType( KEduVocLesson* parentContainer, QDomElement &typesElement ); + bool readWordType( KEduVocWordType* parentContainer, QDomElement &typesElement ); /** * Read all tags within a word type definition. @@ -99,7 +100,7 @@ private: * @param lessonElement * @return */ - bool readChildWordTypes( KEduVocLesson* parentContainer, QDomElement &lessonElement ); + bool readChildWordTypes( KEduVocWordType* parentContainer, QDomElement &lessonElement ); /** read the tenses * @param tensesElement QDomElement for the tenses group diff --git a/keduvocdocument/keduvockvtml2writer.cpp b/keduvocdocument/keduvockvtml2writer.cpp index b877b57..9d34b42 100644 --- a/keduvocdocument/keduvockvtml2writer.cpp +++ b/keduvocdocument/keduvockvtml2writer.cpp @@ -265,10 +265,10 @@ bool KEduVocKvtml2Writer::writeArticle( QDomElement &articleElement, int article } -bool KEduVocKvtml2Writer::writeWordTypes( QDomElement &typesElement, KEduVocLesson* parentContainer ) +bool KEduVocKvtml2Writer::writeWordTypes( QDomElement &typesElement, KEduVocWordType* parentContainer ) { foreach( KEduVocContainer* container, parentContainer->childContainers() ) { - KEduVocLesson* wordType = static_cast(container); + KEduVocWordType* wordType = static_cast(container); kDebug() << "Writing type: " << wordType->name(); diff --git a/keduvocdocument/keduvockvtml2writer.h b/keduvocdocument/keduvockvtml2writer.h index ac998a2..a1f1cb3 100644 --- a/keduvocdocument/keduvockvtml2writer.h +++ b/keduvocdocument/keduvockvtml2writer.h @@ -70,7 +70,7 @@ public: /** write types * @param typesElement QDomElement types to write to */ - bool writeWordTypes( QDomElement &typesElement, KEduVocLesson* parentContainer ); + bool writeWordTypes( QDomElement &typesElement, KEduVocWordType* parentContainer ); /** write tenses * @param tensesElement QDomElement tenses to write to diff --git a/keduvocdocument/keduvoclesson.h b/keduvocdocument/keduvoclesson.h index b9a8b26..7115282 100644 --- a/keduvocdocument/keduvoclesson.h +++ b/keduvocdocument/keduvoclesson.h @@ -21,9 +21,6 @@ #include "keduvoccontainer.h" -#include -#include - class KEduVocExpression; /** class to store information about a lesson */ diff --git a/keduvocdocument/keduvoctranslation.cpp b/keduvocdocument/keduvoctranslation.cpp index c3f1817..727b380 100644 --- a/keduvocdocument/keduvoctranslation.cpp +++ b/keduvocdocument/keduvoctranslation.cpp @@ -22,7 +22,7 @@ #include "keduvocgrade.h" #include "keduvocdeclination.h" -#include "keduvoclesson.h" +#include "keduvocwordtype.h" class KEduVocTranslation::KEduVocTranslationPrivate { @@ -35,7 +35,7 @@ public: QString m_translation; /// Type of a word noun, verb, adjective etc - KEduVocLesson* m_wordType; + KEduVocWordType* m_wordType; /// A comment giving additional information. QString m_comment; @@ -97,7 +97,6 @@ KEduVocTranslation::KEduVocTranslation(KEduVocExpression* entry, const QString & KEduVocTranslation::KEduVocTranslation( const KEduVocTranslation &other ) : d( new KEduVocTranslationPrivate(other.d->m_entry) ) { -// d->m_entry = other.d->m_entry; d->m_translation = other.d->m_translation; d->m_wordType = other.d->m_wordType; d->m_usages = other.d->m_usages; @@ -362,19 +361,24 @@ void KEduVocTranslation::setImageUrl(const KUrl &url) d->m_imageUrl = url; } -KEduVocLesson * KEduVocTranslation::wordType() const +KEduVocWordType * KEduVocTranslation::wordType() const { return d->m_wordType; } -void KEduVocTranslation::setWordType(KEduVocLesson * wordType) +void KEduVocTranslation::setWordType(KEduVocWordType * wordType) { if ( d->m_wordType ) { - d->m_wordType->removeEntry(d->m_entry); + d->m_wordType->removeTranslation(this); } if ( wordType ) { - wordType->addEntry(d->m_entry); + wordType->addTranslation(this); d->m_wordType = wordType; } } +KEduVocExpression * KEduVocTranslation::entry() +{ + return d->m_entry; +} + diff --git a/keduvocdocument/keduvoctranslation.h b/keduvocdocument/keduvoctranslation.h index 827b5fe..c4d59d9 100644 --- a/keduvocdocument/keduvoctranslation.h +++ b/keduvocdocument/keduvoctranslation.h @@ -26,7 +26,7 @@ class KEduVocExpression; class KEduVocGrade; -class KEduVocLesson; +class KEduVocWordType; /** @author Frederik Gladhorn @@ -53,6 +53,8 @@ public: */ ~KEduVocTranslation(); + KEduVocExpression* entry(); + /** * The translation as string (the word itself) * @return the translation @@ -167,12 +169,12 @@ public: * * @return type or "" if no type available */ - KEduVocLesson* wordType() const; + KEduVocWordType* wordType() const; /** sets the word type of this expression * @param type type of this expression ("" = none) */ - void setWordType( KEduVocLesson* wordType ); + void setWordType( KEduVocWordType* wordType ); /** reset the grades for this translation */ diff --git a/keduvocdocument/keduvocwordtype.cpp b/keduvocdocument/keduvocwordtype.cpp index 2005b02..7cc324b 100644 --- a/keduvocdocument/keduvocwordtype.cpp +++ b/keduvocdocument/keduvocwordtype.cpp @@ -1,14 +1,7 @@ /*************************************************************************** - C++ Implementation: keduvocwordtype - - ----------------------------------------------------------------------- - - begin : Mi Aug 22 2007 - - copyright : (C) 2007 Frederik Gladhorn - - ----------------------------------------------------------------------- + Copyright 2007 Jeremy Whiting + Copyright 2007 Frederik Gladhorn ***************************************************************************/ @@ -23,348 +16,77 @@ #include "keduvocwordtype.h" -#include -#include +#include "keduvocexpression.h" + +#include +#include class KEduVocWordType::Private { public: - struct subWordType - { - QString m_subTypeName; - QString m_specialType; - bool operator== ( const subWordType& other ); - }; - struct wordType - { - QString m_typeName; - QString m_specialType; - QList m_subWordTypeList; - bool operator== ( const wordType& other ); - }; - - /// Map containing the word type name and its properties. - QList m_wordTypeList; - - static const QString WORDTYPE_SPECIAL_NOUN; - static const QString WORDTYPE_SPECIAL_NOUN_MALE; - static const QString WORDTYPE_SPECIAL_NOUN_FEMALE; - static const QString WORDTYPE_SPECIAL_NOUN_NEUTRAL; - - static const QString WORDTYPE_SPECIAL_VERB; - static const QString WORDTYPE_SPECIAL_VERB_REGULAR; - static const QString WORDTYPE_SPECIAL_VERB_IRREGULAR; - static const QString WORDTYPE_SPECIAL_ADJECTIVE; - static const QString WORDTYPE_SPECIAL_ADVERB; + // entries + QList m_translations; }; -const QString KEduVocWordType::Private::WORDTYPE_SPECIAL_NOUN = - QString( i18nc( "@item:inlistbox The grammatical type of a word", "Noun" ) ); -const QString KEduVocWordType::Private::WORDTYPE_SPECIAL_NOUN_MALE = - QString( i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Male" ) ); -const QString KEduVocWordType::Private::WORDTYPE_SPECIAL_NOUN_FEMALE = - QString( i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Female" ) ); -const QString KEduVocWordType::Private::WORDTYPE_SPECIAL_NOUN_NEUTRAL = - QString( i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Neutral" ) ); - -const QString KEduVocWordType::Private::WORDTYPE_SPECIAL_VERB = - QString( i18nc( "@item:inlistbox The grammatical type of a word", "Verb" ) ); -const QString KEduVocWordType::Private::WORDTYPE_SPECIAL_ADJECTIVE = - QString( i18nc( "@item:inlistbox The grammatical type of a word", "Adjective" ) ); -const QString KEduVocWordType::Private::WORDTYPE_SPECIAL_ADVERB = - QString( i18nc( "@item:inlistbox The grammatical type of a word", "Adverb" ) ); - - -bool KEduVocWordType::Private::wordType::operator ==(const wordType & other) -{ - return m_typeName == other.m_typeName && - m_specialType == other.m_specialType && - m_subWordTypeList == other.m_subWordTypeList; -} -bool KEduVocWordType::Private::subWordType::operator ==(const subWordType & other) +KEduVocWordType::KEduVocWordType(const QString& name, KEduVocWordType *parent) + : d( new Private ), KEduVocContainer(name, WordTypeContainer, parent) { - return m_subTypeName == other.m_subTypeName && - m_specialType == other.m_specialType; } -bool KEduVocWordType::operator ==(const KEduVocWordType & other) +KEduVocWordType::KEduVocWordType( const KEduVocWordType &other ) + : d( new Private ), KEduVocContainer(other) { - return d->m_wordTypeList == other.d->m_wordTypeList; + d->m_translations = other.d->m_translations; } -KEduVocWordType::KEduVocWordType() - : d( new Private ) -{} - KEduVocWordType::~KEduVocWordType() { delete d; } -KEduVocWordType & KEduVocWordType::operator = ( const KEduVocWordType & other ) -{ - d->m_wordTypeList = other.d->m_wordTypeList; - return *this; -} - -KEduVocWordType::KEduVocWordType( const KEduVocWordType & other ) - : d( new Private ) -{ - d->m_wordTypeList = other.d->m_wordTypeList; -} - -void KEduVocWordType::createDefaultWordTypes() +QList KEduVocWordType::entries() { - // first the special types - addType( d->WORDTYPE_SPECIAL_NOUN, d->WORDTYPE_SPECIAL_NOUN ); - - addSubType( d->WORDTYPE_SPECIAL_NOUN, - d->WORDTYPE_SPECIAL_NOUN_MALE, d->WORDTYPE_SPECIAL_NOUN_MALE ); - - addSubType( d->WORDTYPE_SPECIAL_NOUN, - d->WORDTYPE_SPECIAL_NOUN_FEMALE, d->WORDTYPE_SPECIAL_NOUN_FEMALE ); - - addSubType( d->WORDTYPE_SPECIAL_NOUN, - d->WORDTYPE_SPECIAL_NOUN_NEUTRAL, d->WORDTYPE_SPECIAL_NOUN_NEUTRAL ); - - addType( d->WORDTYPE_SPECIAL_VERB, d->WORDTYPE_SPECIAL_VERB ); - - addSubType( d->WORDTYPE_SPECIAL_VERB, - i18nc( "@item:inlistbox A subtype of the grammatical word type: Verb with regular conjugation","Regular" ) ); - - addSubType( d->WORDTYPE_SPECIAL_VERB, - i18nc( "@item:inlistbox A subtype of the grammatical word type: Verb with irregular conjugation","Irregular" ) ); - - addType( d->WORDTYPE_SPECIAL_ADJECTIVE, d->WORDTYPE_SPECIAL_ADJECTIVE ); - addType( d->WORDTYPE_SPECIAL_ADVERB, d->WORDTYPE_SPECIAL_ADVERB ); - - addType( i18nc( "@item:inlistbox The grammatical type of an entry", "Question" ) ); - addType( i18nc( "@item:inlistbox The grammatical type of a word", "Name" ) ); - addType( i18nc( "@item:inlistbox The grammatical type of a word", "Article" ) ); - addSubType( i18nc( "@item:inlistbox The grammatical type of a word", "Article" ), - i18nc( "@item:inlistbox A subtype of the grammatical word type: Article (the)","Definite" ) ); - addSubType( i18nc( "@item:inlistbox The grammatical type of a word", "Article" ), - i18nc( "@item:inlistbox A subtype of the grammatical word type: Article (a)","Indefinite" ) ); - - addType( i18nc( "@item:inlistbox The grammatical type of a word", "Pronoun" ) ); - addSubType( i18nc( "@item:inlistbox The grammatical type of a word", "Pronoun" ), - i18nc( "@item:inlistbox A subtype of the grammatical word type: Pronoun (my, your, his, her...)", "Possessive" ) ); - addSubType( i18nc( "@item:inlistbox The grammatical type of a word", "Pronoun" ), - i18nc( "@item:inlistbox A subtype of the grammatical word type: Pronoun (I, you, he...)", "Personal" ) ); - - addType( i18nc( "@item:inlistbox The grammatical type of an entry", "Phrase" ) ); - addType( i18nc( "@item:inlistbox The grammatical type of a word", "Numeral" ) ); - addSubType( i18nc( "@item:inlistbox The grammatical type of a word", "Numeral" ), - i18nc( "@item:inlistbox A subtype of the grammatical word type: Numeral Ordinal (one, two, three, ...)","Ordinal" ) ); - addSubType( i18nc( "@item:inlistbox The grammatical type of a word", "Numeral" ), - i18nc( "@item:inlistbox A subtype of the grammatical word type: Numeral Cardinal (first, second, third, ...)","Cardinal" ) ); - - addType( i18nc( "@item:inlistbox The grammatical type of a word", "Conjunction" ) ); - addType( i18nc( "@item:inlistbox The grammatical type of a word", "Preposition" ) ); -} - -QString KEduVocWordType::mainTypeName( int index ) const -{ - return d->m_wordTypeList[index].m_typeName; -} - -int KEduVocWordType::mainTypeIndex( const QString& name ) const -{ - for ( int i=0; i < d->m_wordTypeList.count(); i++ ) { - if ( d->m_wordTypeList.value( i ).m_typeName == name ) { - return i; - } + QSet entries; + foreach(KEduVocTranslation* translation, d->m_translations) { + entries.insert(translation->entry()); } - return -1; + return entries.toList(); } -QStringList KEduVocWordType::typeNameList() const +int KEduVocWordType::entryCount() { - QStringList list; - foreach( Private::wordType wt, d->m_wordTypeList ) { - list.append( wt.m_typeName ); - } - return list; + return entries().count(); } -QStringList KEduVocWordType::subTypeNameList( const QString & mainType ) const +void KEduVocWordType::addTranslation(KEduVocTranslation* translation) { - int mainIndex = mainTypeIndex( mainType ); - kDebug() << "Get subtypes for " << mainType << " = " << mainIndex; - QStringList list; - foreach( Private::subWordType wt, d->m_wordTypeList.value( mainIndex ).m_subWordTypeList ) { - list.append( wt.m_subTypeName ); - } - return list; + d->m_translations.append( translation ); } - -void KEduVocWordType::addType( const QString & typeName, const QString & specialType ) +void KEduVocWordType::removeTranslation(KEduVocTranslation* translation) { - if ( typeName.isEmpty() ) { - kDebug() << "Attempting to add empty type. When opening old kvtml documents this is ok."; - return; - } - if ( typeNameList().contains( typeName ) ) { - kDebug() << "Attempting to add type \"" << typeName << "\" twice."; - return; - } - d->m_wordTypeList.append( Private::wordType() ); - d->m_wordTypeList[d->m_wordTypeList.count()-1].m_typeName = typeName; - d->m_wordTypeList[d->m_wordTypeList.count()-1].m_specialType = specialType; + d->m_translations.removeAt( d->m_translations.indexOf(translation) ); } -void KEduVocWordType::addSubType( const QString & mainType, const QString & typeName, const QString & specialType ) +KEduVocTranslation * KEduVocWordType::translation(int row) { - int mt = mainTypeIndex( mainType ); - - d->m_wordTypeList[mt].m_subWordTypeList.append( Private::subWordType() ); - - d->m_wordTypeList[mt].m_subWordTypeList[d->m_wordTypeList[mt].m_subWordTypeList.count()-1].m_subTypeName = typeName; - d->m_wordTypeList[mt].m_subWordTypeList[d->m_wordTypeList[mt].m_subWordTypeList.count()-1].m_specialType = specialType; + return d->m_translations.value(row); } -void KEduVocWordType::renameType( const QString & oldTypeName, const QString & newTypeName ) -{ - int index = mainTypeIndex( oldTypeName ); - d->m_wordTypeList[index].m_typeName= newTypeName; -} +// KEduVocWordType * KEduVocWordType::parent() +// { +// if(KEduVocContainer::parent()) { +// ///@todo check if it is a word type container? +// return static_cast(KEduVocContainer::parent()); +// } +// return 0; +// } -void KEduVocWordType::renameSubType( const QString & mainTypeName, const QString & oldTypeName, const QString & newTypeName ) +KEduVocExpression * KEduVocWordType::entry(int row) { - kDebug() << "Rename subtype: " << mainTypeName << oldTypeName << newTypeName; - int mainIndex = mainTypeIndex( mainTypeName ); - if ( mainIndex < 0 ) { - kDebug() << "Renaming of subtype faild - parent not found"; - return; - } - int subIndex = subTypeIndex( mainTypeName, oldTypeName ); - if ( subIndex < 0 ) { - kDebug() << "Renaming of subtype faild - old subtype not found"; - return; - } - - d->m_wordTypeList[mainIndex].m_subWordTypeList[subIndex].m_subTypeName= newTypeName; + return entries().value(row); } -bool KEduVocWordType::removeType( const QString & typeName ) -{ - // only if NOT special type - int index = mainTypeIndex( typeName ); - if ( index < 0 ) { - return false; - } - d->m_wordTypeList.removeAt( index ); - return true; -} - -bool KEduVocWordType::removeSubType( const QString & mainTypeName, const QString & typeName ) -{ - int mainIndex = mainTypeIndex( mainTypeName ); - if ( mainIndex < 0 ) { - return false; - } - int subIndex = subTypeIndex( mainTypeName, typeName ); - if ( subIndex < 0 ) { - return false; - } - d->m_wordTypeList[mainIndex].m_subWordTypeList.removeAt( subIndex ); - return true; -} - -int KEduVocWordType::subTypeIndex( const QString & mainTypeName, const QString & subTypeName ) const -{ - int main = mainTypeIndex( mainTypeName ); - if ( main < 0 ) { - kDebug() << "Main word type not found (" << mainTypeName << ")"; - return -1; - } - for ( int i=0; i < d->m_wordTypeList[main].m_subWordTypeList.count(); i++ ) { - if ( d->m_wordTypeList[main].m_subWordTypeList.value( i ).m_subTypeName == subTypeName ) { - return i; - } - } - return -1; -} - -QString KEduVocWordType::specialType( const QString & typeName ) -{ - int index = mainTypeIndex( typeName ); - if ( index >= 0 ) { - return d->m_wordTypeList[index].m_specialType; - } - return QString(); -} - -QString KEduVocWordType::specialSubType( const QString & mainTypeName, const QString & subTypeName ) -{ - int mainIndex = mainTypeIndex( mainTypeName ); - if ( mainIndex >= 0 ) { - int subIndex = subTypeIndex( mainTypeName, subTypeName ); - if ( subIndex >= 0 ) { - return d->m_wordTypeList[mainIndex].m_subWordTypeList[subIndex].m_specialType; - } - } - return QString(); -} - - -QString KEduVocWordType::specialTypeNoun() const -{ - return d->WORDTYPE_SPECIAL_NOUN; -} -QString KEduVocWordType::specialTypeNounMale() const -{ - return d->WORDTYPE_SPECIAL_NOUN_MALE; -} -QString KEduVocWordType::specialTypeNounFemale() const -{ - return d->WORDTYPE_SPECIAL_NOUN_FEMALE; -} -QString KEduVocWordType::specialTypeNounNeutral() const -{ - return d->WORDTYPE_SPECIAL_NOUN_NEUTRAL; -} - - -QString KEduVocWordType::specialTypeVerb() const -{ - return d->WORDTYPE_SPECIAL_VERB; -} - -QString KEduVocWordType::specialTypeAdjective() const -{ - return d->WORDTYPE_SPECIAL_ADJECTIVE; -} - -QString KEduVocWordType::specialTypeAdverb() const -{ - return d->WORDTYPE_SPECIAL_ADVERB; -} - -void KEduVocWordType::setSpecialType(const QString & typeName, const QString & newSpecialType) -{ - int mainIndex = mainTypeIndex( typeName ); - if ( mainIndex >= 0 ) { - d->m_wordTypeList[mainIndex].m_specialType = newSpecialType; - } -} - -void KEduVocWordType::setSpecialSubType(const QString & mainTypeName, const QString & subTypeName, const QString & newSpecialType) -{ - int mainIndex = mainTypeIndex( mainTypeName ); - if ( mainIndex >= 0 ) { - int subIndex = subTypeIndex( mainTypeName, subTypeName ); - if ( subIndex >= 0 ) { - d->m_wordTypeList[mainIndex].m_subWordTypeList[subIndex].m_specialType = newSpecialType; - } - } -} - -void KEduVocWordType::clear() -{ - d->m_wordTypeList.clear(); -} diff --git a/keduvocdocument/keduvocwordtype.h b/keduvocdocument/keduvocwordtype.h index fbba117..4c8d511 100644 --- a/keduvocdocument/keduvocwordtype.h +++ b/keduvocdocument/keduvocwordtype.h @@ -1,14 +1,7 @@ /*************************************************************************** - C++ Interface: keduvocwordtype - - ----------------------------------------------------------------------- - - begin : Mi Aug 22 2007 - - copyright : (C) 2007 Frederik Gladhorn - - ----------------------------------------------------------------------- + Copyright 2007 Jeremy Whiting + Copyright 2007 Frederik Gladhorn ***************************************************************************/ @@ -26,128 +19,57 @@ #include "libkeduvocdocument_export.h" -#include -#include +#include "keduvoccontainer.h" -/** - Word type handling including subtypes (noun - male/female) etc. - Special types: To let KVocTrain decide which word type is a verb for example the - special tag is used. - @author Frederik Gladhorn -*/ -class KEDUVOCDOCUMENT_EXPORT KEduVocWordType -{ +#include +#include + +class KEduVocExpression; +class KEduVocTranslation; +/** class to store translation word types */ +class KEDUVOCDOCUMENT_EXPORT KEduVocWordType :public KEduVocContainer +{ public: /** default constructor */ - explicit KEduVocWordType(); + explicit KEduVocWordType(const QString& name, KEduVocWordType *parent = 0); /** copy constructor for d-pointer safe copying */ - KEduVocWordType( const KEduVocWordType& other ); + KEduVocWordType( const KEduVocWordType &other ); /** destructor */ ~KEduVocWordType(); /** assignment operator */ - KEduVocWordType& operator= ( const KEduVocWordType& other ); - bool operator== ( const KEduVocWordType& other ); + KEduVocWordType& operator= ( const KEduVocWordType& ); - void createDefaultWordTypes(); - - /** - * Create a new word type in the list of known types - * @param typeName Name of the word type - * @param specialType Name of the special type - this is used internally to identify which types are use for special queries - verb query needs special == "verb" for example. - */ - void addType( const QString& typeName, const QString& specialType = QString() ); + KEduVocTranslation * translation(int row); + /** get a list of all entries in the lesson */ + QList < KEduVocExpression* > entries(); - /** - * Same as addType but for a sub word type (male/female/nutral for noun for example) - * @param mainType The word type to which the subtype belongs. - * @param typeName Sub type name - * @param specialType See above - */ - void addSubType( const QString& mainType, const QString& typeName, const QString& specialType = QString() ); + KEduVocExpression* entry(int row); - /** - * Get a list of all known main word types. - * This can be for example: noun, verb, adjective... - * @return List of type names - */ - QStringList typeNameList() const; + /** get the number of entries in the lesson */ + int entryCount(); - /** - * Same as typeNameList for subtypes. - * Could be male, female, nutral for nouns. - * @param mainType The type whos subtypes are requested. - * @return The subtypes. - */ - QStringList subTypeNameList( const QString& mainType ) const; +// KEduVocWordType *parent(); - /** - * Rename a type. - * @param oldTypeName Old name - * @param newTypeName New name - */ - void renameType( const QString& oldTypeName, const QString& newTypeName ); - /** - * Rename a subtype. - * @param mainTypeName Main type - * @param oldTypeName Old name - * @param newTypeName New name - */ - void renameSubType( const QString& mainTypeName, const QString& oldTypeName, const QString& newTypeName ); +private: + class Private; + Private * const d; - /** - * Delete a type. - * Special types cannot be deleted. - * @param typeName name - * @return true if it was possible to delete the type + /** add an entry to the lesson + * @param entryid id of the entry to add */ - bool removeType( const QString& typeName ); - /** - * removeType for subtypes. - * @param mainTypeName main type - * @param typeName type name - * @return true if it was possible to delete the type - */ - bool removeSubType( const QString& mainTypeName, const QString& typeName ); + void addTranslation(KEduVocTranslation* translation); - /** - * Get the special type, if any. - * @param typeName Name whos special type is requested - * @return the special type or an empty string. - */ - QString specialType( const QString& typeName ); - void setSpecialType( const QString& typeName, const QString& newSpecialType ); - /** - * Same as above for a subtype - * @param typeName Main type name - * @param typeName Sub type name - * @return the special type or an empty string. + /** remove an entry from the lesson + * @param entryid id of the entry to remove */ - QString specialSubType( const QString& mainTypeName, const QString& subTypeName ); - void setSpecialSubType( const QString& mainTypeName, const QString& subTypeName, const QString& newSpecialType ); - - QString specialTypeNoun() const; - QString specialTypeNounMale() const; - QString specialTypeNounFemale() const; - QString specialTypeNounNeutral() const; + void removeTranslation(KEduVocTranslation* translation); - QString specialTypeVerb() const; - QString specialTypeAdjective() const; - QString specialTypeAdverb() const; - - void clear(); - -private: - QString mainTypeName( int index ) const; - int mainTypeIndex( const QString& name ) const; - int subTypeIndex( const QString& mainTypeName, const QString& subTypeName ) const; - - class Private; - Private * const d; + friend class KEduVocTranslation; }; #endif -- 2.47.3