From: David Capel Date: Wed, 30 Jul 2008 08:07:53 +0000 (+0000) Subject: NOTE: Breaks binary compatibility. Make sure to make install after you make this. X-Git-Tag: v4.1.80~36 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=8ce4e5df8c9cc7b86b550ab9528a88d8c0d6d0f6;p=libqmvoc.git NOTE: Breaks binary compatibility. Make sure to make install after you make this. This consolidates various enums of word properties into one: KEduVocWordFlags This stores the following sets of properties: Number Part of Speech Gender Definiteness Regularity Phrase (if it is actually a phrase and not a word) Others may come later, but those work for now. Instead of having functions accept multiple parameters for each type (gender, number, etc), they accept one KEduVocWordFlags parameter. You can pass as many flags as you want by bitwise ORing (a|b) them together, similar to how Qt accepts various flags. QFlags is a handy helper class that does this magic for us. This implementation has the following benefits over the previous one: (The previous had multiple enums floating around in various classes, new combinations were frequently made by making a new enum entry.) * All the flags are in one place, instead of scattered and duplicated. * You only need to set the flags you care about -- no dummy parameter-filling flags needed. * We can extend the flags without breaking binary compatibility. * It allows optional extra flags like verb regularity. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=839519 --- diff --git a/keduvocdocument/CMakeLists.txt b/keduvocdocument/CMakeLists.txt index f3295c5..05a3aa1 100644 --- a/keduvocdocument/CMakeLists.txt +++ b/keduvocdocument/CMakeLists.txt @@ -27,7 +27,8 @@ keduvocdocument.cpp keduvocvokabelnreader.cpp keduvocwqlreader.cpp keduvocxdxfreader.cpp - sharedkvtmlfiles.cpp ) + sharedkvtmlfiles.cpp + ) kde4_add_library(keduvocdocument SHARED ${keduvocdocument_LIB_SRCS}) diff --git a/keduvocdocument/keduvocarticle.cpp b/keduvocdocument/keduvocarticle.cpp index c84855b..747d9a3 100644 --- a/keduvocdocument/keduvocarticle.cpp +++ b/keduvocdocument/keduvocarticle.cpp @@ -16,6 +16,7 @@ ***************************************************************************/ #include "keduvocarticle.h" +#include "keduvocwordflags.h" #include #include @@ -23,7 +24,7 @@ class KEduVocArticle::Private { public: - QMap m_articles; + QMap m_articles; }; KEduVocArticle::KEduVocArticle() @@ -45,13 +46,13 @@ KEduVocArticle &KEduVocArticle::operator= ( const KEduVocArticle& other ) KEduVocArticle::KEduVocArticle( const QString &fem_def, const QString &fem_indef, const QString &mal_def, const QString &mal_indef, const QString &neu_def, const QString &neu_indef ) :d( new Private ) { - setArticle( mal_def, Singular, Definite, Masculine ); - setArticle( fem_def, Singular, Definite, Feminine ); - setArticle( neu_def, Singular, Definite, Neutral ); + setArticle( mal_def, KEduVocWordFlag::Singular | KEduVocWordFlag::Definite | KEduVocWordFlag::Masculine ); + setArticle( fem_def, KEduVocWordFlag::Singular | KEduVocWordFlag::Definite | KEduVocWordFlag::Feminine ); + setArticle( neu_def, KEduVocWordFlag::Singular | KEduVocWordFlag::Definite | KEduVocWordFlag::Neuter ); - setArticle( mal_indef, Singular, Indefinite, Masculine ); - setArticle( fem_indef, Singular, Indefinite, Feminine ); - setArticle( neu_indef, Singular, Indefinite, Neutral ); + setArticle( mal_indef, KEduVocWordFlag::Singular | KEduVocWordFlag::Indefinite | KEduVocWordFlag::Masculine ); + setArticle( fem_indef, KEduVocWordFlag::Singular | KEduVocWordFlag::Indefinite | KEduVocWordFlag::Feminine ); + setArticle( neu_indef, KEduVocWordFlag::Singular | KEduVocWordFlag::Indefinite | KEduVocWordFlag::Neuter ); } KEduVocArticle::~KEduVocArticle() @@ -60,28 +61,16 @@ KEduVocArticle::~KEduVocArticle() } -QString KEduVocArticle::article(ArticleNumber number, ArticleDefiniteness definite, ArticleGender gender) +QString KEduVocArticle::article(const KEduVocWordFlags& flags) { - if ( d->m_articles.contains( indexOf(number, definite, gender) ) ) { - return d->m_articles.value( indexOf(number, definite, gender) ); - } - return QString(); + return d->m_articles.value(flags); } -void KEduVocArticle::setArticle(const QString & article, ArticleNumber number, ArticleDefiniteness definite, ArticleGender gender) +void KEduVocArticle::setArticle(const QString & article, const KEduVocWordFlags& flags) { - setArticle(article, indexOf(number, definite, gender)); + d->m_articles[flags] = article; } -void KEduVocArticle::setArticle(const QString & article, int index) -{ - d->m_articles[index] = article; -} - -int KEduVocArticle::indexOf(ArticleNumber number, ArticleDefiniteness definite, ArticleGender gender) -{ - return number + (definite * (Plural+1)) + (gender * (Plural+1) * (Indefinite+1)); -} bool KEduVocArticle::isArticle(const QString & article) const { diff --git a/keduvocdocument/keduvocarticle.h b/keduvocdocument/keduvocarticle.h index 359ef83..068ee37 100644 --- a/keduvocdocument/keduvocarticle.h +++ b/keduvocdocument/keduvocarticle.h @@ -22,6 +22,9 @@ #include +#include "keduvocwordflags.h" + +class KEduVocWordType; /** * Class representing the articles of a language * @@ -31,22 +34,6 @@ class KEDUVOCDOCUMENT_EXPORT KEduVocArticle { public: - enum ArticleNumber { - Singular, - Dual, - Plural - }; - - enum ArticleGender { - Masculine, - Feminine, - Neutral - }; - - enum ArticleDefiniteness { - Definite, - Indefinite - }; /** @@ -80,19 +67,14 @@ public: */ KEduVocArticle &operator= ( const KEduVocArticle& other ); + QString article(const KEduVocWordFlags&); - QString article(ArticleNumber number, ArticleDefiniteness definite, ArticleGender gender); - - void setArticle(const QString& article, ArticleNumber number, ArticleDefiniteness definite, ArticleGender gender); - - void setArticle(const QString& article, int index); + void setArticle(const QString& article, const KEduVocWordFlags&); bool isArticle(const QString& article) const; bool isEmpty(); - static int indexOf(ArticleNumber number, ArticleDefiniteness definite, ArticleGender gender); - class Private; Private * const d; }; diff --git a/keduvocdocument/keduvockvtml2reader.cpp b/keduvocdocument/keduvockvtml2reader.cpp index 195c73a..ff95c56 100644 --- a/keduvocdocument/keduvockvtml2reader.cpp +++ b/keduvocdocument/keduvockvtml2reader.cpp @@ -470,19 +470,31 @@ bool KEduVocKvtml2Reader::readArticle( QDomElement &articleElement, int identifi */ { - // singular - for ( KEduVocArticle::ArticleNumber num = KEduVocArticle::Singular; num <= KEduVocArticle::Plural; num = KEduVocArticle::ArticleNumber(num+1) ) { + QMap numbers; + numbers[0] = KEduVocWordFlag::Singular; + numbers[1] = KEduVocWordFlag::Dual; + numbers[2] = KEduVocWordFlag::Plural; + QMap genders; + genders[0] = KEduVocWordFlag::Masculine; + genders[1] = KEduVocWordFlag::Feminine; + genders[2] = KEduVocWordFlag::Neuter; + QMap defs; + defs[0] = KEduVocWordFlag::Definite; + defs[1] = KEduVocWordFlag::Indefinite; + + + for ( int num = 0; num <= 2; ++num) { QDomElement numberElement = articleElement.firstChildElement( KVTML_GRAMMATICAL_NUMBER[num] ); if (!numberElement.isNull()) { // definite - for ( KEduVocArticle::ArticleDefiniteness def = KEduVocArticle::Definite; def <= KEduVocArticle::Indefinite; def = KEduVocArticle::ArticleDefiniteness(def+1) ) { + for ( int def = 0; def <= 1; ++def ) { QDomElement defElement = numberElement.firstChildElement( KVTML_GRAMMATICAL_DEFINITENESS[def] ); if (!defElement.isNull()) { // male - for ( KEduVocArticle::ArticleGender gen = KEduVocArticle::Masculine; gen <= KEduVocArticle::Neutral; gen = KEduVocArticle::ArticleGender(gen+1) ) { + for ( int gen = 0; gen <= 2; ++gen ) { QDomElement genderElement = defElement.firstChildElement( KVTML_GRAMMATICAL_GENDER[gen] ); if (!genderElement.isNull()) { - m_doc->identifier(identifierNum).article().setArticle( genderElement.text(), KEduVocArticle::indexOf(num, def, gen) ); + m_doc->identifier(identifierNum).article().setArticle( genderElement.text(), numbers[num] | defs[def] | genders[gen]); } } } @@ -546,25 +558,25 @@ bool KEduVocKvtml2Reader::readWordType( KEduVocWordType* parentContainer, QDomEl if ( !specialType.isEmpty() ) { // get the localized version if ( specialType == KVTML_SPECIALWORDTYPE_NOUN ) { - wordTypeContainer->setWordType(KEduVocWordType::Noun); + wordTypeContainer->setWordType(KEduVocWordFlag::Noun); } if ( specialType == KVTML_SPECIALWORDTYPE_VERB ) { - wordTypeContainer->setWordType(KEduVocWordType::Verb); + wordTypeContainer->setWordType(KEduVocWordFlag::Verb); } if ( specialType == KVTML_SPECIALWORDTYPE_ADVERB ) { - wordTypeContainer->setWordType(KEduVocWordType::Adverb); + wordTypeContainer->setWordType(KEduVocWordFlag::Adverb); } if ( specialType == KVTML_SPECIALWORDTYPE_ADJECTIVE ) { - wordTypeContainer->setWordType(KEduVocWordType::Adjective); + wordTypeContainer->setWordType(KEduVocWordFlag::Adjective); } if ( specialType == KVTML_SPECIALWORDTYPE_NOUN_MALE ) { - wordTypeContainer->setWordType(KEduVocWordType::NounMale); + wordTypeContainer->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Masculine); } if ( specialType == KVTML_SPECIALWORDTYPE_NOUN_FEMALE ) { - wordTypeContainer->setWordType(KEduVocWordType::NounFemale); + wordTypeContainer->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Feminine); } if ( specialType == KVTML_SPECIALWORDTYPE_NOUN_NEUTRAL ) { - wordTypeContainer->setWordType(KEduVocWordType::NounNeutral); + wordTypeContainer->setWordType(KEduVocWordFlag::Noun| KEduVocWordFlag::Neuter); } } // special type diff --git a/keduvocdocument/keduvockvtml2writer.cpp b/keduvocdocument/keduvockvtml2writer.cpp index 354999e..b5fdec6 100644 --- a/keduvocdocument/keduvockvtml2writer.cpp +++ b/keduvocdocument/keduvockvtml2writer.cpp @@ -334,16 +334,28 @@ bool KEduVocKvtml2Writer::writeRelated(QDomElement & parentElement, QList< KEduV bool KEduVocKvtml2Writer::writeArticle( QDomElement &articleElement, int language ) { ///@todo only write if not empty - for (int num = KEduVocArticle::Singular; num <= KEduVocArticle::Plural; num++) + QMap numbers; + numbers[0] = KEduVocWordFlag::Singular; + numbers[1] = KEduVocWordFlag::Dual; + numbers[2] = KEduVocWordFlag::Plural; + QMap genders; + genders[0] = KEduVocWordFlag::Masculine; + genders[1] = KEduVocWordFlag::Feminine; + genders[2] = KEduVocWordFlag::Neuter; + QMap defs; + defs[0] = KEduVocWordFlag::Definite; + defs[1] = KEduVocWordFlag::Indefinite; + + for (int num = 0; num <= 2; num++) { QDomElement numberElement = m_domDoc.createElement( KVTML_GRAMMATICAL_NUMBER[num] ); - for (int def = KEduVocArticle::Definite; def <= KEduVocArticle::Indefinite; def++) { + for (int def = 0; def <= 1; def++) { QDomElement defElement = m_domDoc.createElement( KVTML_GRAMMATICAL_DEFINITENESS[def] ); - for (int gen = KEduVocArticle::Masculine; gen <= KEduVocArticle::Neutral; gen++) + for (int gen = 0; gen <= 2; gen++) { - QString articleString = m_doc->identifier(language).article().article( KEduVocArticle::ArticleNumber(num), KEduVocArticle::ArticleDefiniteness(def), KEduVocArticle::ArticleGender(gen) ); + QString articleString = m_doc->identifier(language).article().article(numbers[num] | genders[gen] | defs[def]); if ( !articleString.isEmpty() ) { defElement.appendChild( newTextElement( KVTML_GRAMMATICAL_GENDER[gen], articleString ) ); } @@ -368,32 +380,27 @@ bool KEduVocKvtml2Writer::writeWordTypes( QDomElement &typesElement, KEduVocWord QDomElement typeDefinitionElement = m_domDoc.createElement( KVTML_CONTAINER ); typeDefinitionElement.appendChild( newTextElement( KVTML_NAME, wordType->name() ) ); - switch (wordType->wordType()) { - case KEduVocWordType::Noun: - typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_NOUN ) ); - break; - case KEduVocWordType::NounMale: - typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_NOUN_MALE ) ); - break; - case KEduVocWordType::NounFemale: - typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_NOUN_FEMALE ) ); - break; - case KEduVocWordType::NounNeutral: - typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_NOUN_NEUTRAL ) ); - break; - case KEduVocWordType::Verb: + if (wordType->wordType().testFlag(KEduVocWordFlag::Noun)) + { + if (wordType->wordType().testFlag(KEduVocWordFlag::Masculine)) + typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_NOUN_MALE ) ); + + else if (wordType->wordType().testFlag(KEduVocWordFlag::Feminine)) + typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_NOUN_FEMALE ) ); + + else if (wordType->wordType().testFlag(KEduVocWordFlag::Neuter)) + typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_NOUN_NEUTRAL ) ); + else + typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_NOUN ) ); + } + else if (wordType->wordType().testFlag(KEduVocWordFlag::Verb)) typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_VERB ) ); - break; - case KEduVocWordType::Adjective: + + else if (wordType->wordType().testFlag(KEduVocWordFlag::Adjective)) typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_ADJECTIVE ) ); - break; - case KEduVocWordType::Adverb: + + else if (wordType->wordType().testFlag(KEduVocWordFlag::Adverb)) typeDefinitionElement.appendChild( newTextElement( KVTML_SPECIALWORDTYPE, KVTML_SPECIALWORDTYPE_ADVERB ) ); - break; - default: - // no special type, no tag - break; - } // child entries diff --git a/keduvocdocument/keduvockvtmlcompability.cpp b/keduvocdocument/keduvockvtmlcompability.cpp index 6550174..ead419f 100644 --- a/keduvocdocument/keduvockvtmlcompability.cpp +++ b/keduvocdocument/keduvockvtmlcompability.cpp @@ -243,49 +243,56 @@ void KEduVocKvtmlCompability::setupWordTypes(KEduVocWordType * parent) parent->appendChildContainer(wordType); m_userdefinedTypeCounter++; } - static_cast(parent->childContainer(4))->setWordType(KEduVocWordType::Adjective); - static_cast(parent->childContainer(5))->setWordType(KEduVocWordType::Adverb); + static_cast(parent->childContainer(4))->setWordType(KEduVocWordFlag::Adjective); + static_cast(parent->childContainer(5))->setWordType(KEduVocWordFlag::Adverb); KEduVocWordType* numeral = static_cast(parent->childContainer(8)); KEduVocWordType* wordType = new KEduVocWordType( i18nc( "@item:inlistbox A subtype of the grammatical word type: Numeral Ordinal (first, second, third, ...)","Ordinal" ), numeral); + wordType->setWordType(KEduVocWordFlag::Adjective); numeral->appendChildContainer(wordType); wordType = new KEduVocWordType( i18nc( "@item:inlistbox A subtype of the grammatical word type: Numeral Cardinal (one, two, three, ...)","Cardinal" ), numeral); + + wordType->setWordType(KEduVocWordFlag::Adjective); numeral->appendChildContainer(wordType); KEduVocWordType* article = static_cast(parent->childContainer(3)); wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Article (the)","Definite" ), article); + wordType->setWordType(KEduVocWordFlag::Article | KEduVocWordFlag::Definite); article->appendChildContainer(wordType); wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Article (a)","Indefinite" ), article); + wordType->setWordType(KEduVocWordFlag::Article | KEduVocWordFlag::Indefinite); article->appendChildContainer(wordType); KEduVocWordType* verb = static_cast(parent->childContainer(0)); - verb->setWordType(KEduVocWordType::Verb); + verb->setWordType(KEduVocWordFlag::Verb); wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Verb with regular conjugation","Regular" ), verb); - wordType->setWordType(KEduVocWordType::Verb); + wordType->setWordType(KEduVocWordFlag::Verb | KEduVocWordFlag::Regular); verb->appendChildContainer(wordType); wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Verb with irregular conjugation","Irregular" ), verb); verb->appendChildContainer(wordType); - wordType->setWordType(KEduVocWordType::Verb); + wordType->setWordType(KEduVocWordFlag::Verb | KEduVocWordFlag::Irregular); KEduVocWordType* noun = static_cast(parent->childContainer(1)); - noun->setWordType(KEduVocWordType::Noun); + noun->setWordType(KEduVocWordFlag::Noun); wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Male" ), noun); noun->appendChildContainer(wordType); - wordType->setWordType(KEduVocWordType::NounMale); + wordType->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Masculine); wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Female" ), noun); noun->appendChildContainer(wordType); - wordType->setWordType(KEduVocWordType::NounFemale); + wordType->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Feminine); wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Noun", "Neutral" ), noun); noun->appendChildContainer(wordType); - wordType->setWordType(KEduVocWordType::NounNeutral); + wordType->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Neuter); KEduVocWordType* pronoun = static_cast(parent->childContainer(6)); wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Pronoun (my, your, his, her...)", "Possessive" ), pronoun); + wordType->setWordType(KEduVocWordFlag::Pronoun); pronoun->appendChildContainer(wordType); wordType = new KEduVocWordType(i18nc( "@item:inlistbox A subtype of the grammatical word type: Pronoun (I, you, he...)", "Personal" ), pronoun); + wordType->setWordType(KEduVocWordFlag::Pronoun); pronoun->appendChildContainer(wordType); } diff --git a/keduvocdocument/keduvockvtmlwriter.cpp b/keduvocdocument/keduvockvtmlwriter.cpp index 9a69881..b47f7b1 100644 --- a/keduvocdocument/keduvockvtmlwriter.cpp +++ b/keduvocdocument/keduvockvtmlwriter.cpp @@ -347,7 +347,7 @@ bool KEduVocKvtmlWriter::writeArticle( QDomElement &domElementParent ) QString articleString; // female - articleString = m_doc->identifier(i).article().article( KEduVocArticle::Singular, KEduVocArticle::Definite, KEduVocArticle::Feminine ); + articleString = m_doc->identifier(i).article().article( KEduVocWordFlag::Singular, KEduVocWordFlag::Definite, KEduVocWordFlag::Feminine ); if ( !articleString.isEmpty() ) { QDomElement domElementFD = m_domDoc.createElement( KV_ART_FD ); QDomText domTextFD = m_domDoc.createTextNode( articleString ); @@ -355,7 +355,7 @@ bool KEduVocKvtmlWriter::writeArticle( QDomElement &domElementParent ) domElementFD.appendChild( domTextFD ); domElementEntry.appendChild( domElementFD ); } - articleString = m_doc->identifier(i).article().article( KEduVocArticle::Singular, KEduVocArticle::Indefinite, KEduVocArticle::Feminine ); + articleString = m_doc->identifier(i).article().article( KEduVocWordFlag::Singular, KEduVocWordFlag::Indefinite, KEduVocWordFlag::Feminine ); if ( !articleString.isEmpty() ) { QDomElement domElementFI = m_domDoc.createElement( KV_ART_FI ); QDomText domTextFI = m_domDoc.createTextNode( articleString ); @@ -366,7 +366,7 @@ bool KEduVocKvtmlWriter::writeArticle( QDomElement &domElementParent ) // male - articleString = m_doc->identifier(i).article().article( KEduVocArticle::Singular, KEduVocArticle::Definite, KEduVocArticle::Masculine ); + articleString = m_doc->identifier(i).article().article( KEduVocWordFlag::Singular, KEduVocWordFlag::Definite, KEduVocWordFlag::Masculine ); if ( !articleString.isEmpty() ) { QDomElement domElementMD = m_domDoc.createElement( KV_ART_MD ); QDomText domTextMD = m_domDoc.createTextNode( articleString ); @@ -374,7 +374,7 @@ bool KEduVocKvtmlWriter::writeArticle( QDomElement &domElementParent ) domElementMD.appendChild( domTextMD ); domElementEntry.appendChild( domElementMD ); } - articleString = m_doc->identifier(i).article().article( KEduVocArticle::Singular, KEduVocArticle::Indefinite, KEduVocArticle::Masculine ); + articleString = m_doc->identifier(i).article().article( KEduVocWordFlag::Singular, KEduVocWordFlag::Indefinite, KEduVocWordFlag::Masculine ); if ( !articleString.isEmpty() ) { QDomElement domElementMI = m_domDoc.createElement( KV_ART_MI ); QDomText domTextMI = m_domDoc.createTextNode( articleString ); @@ -384,7 +384,7 @@ bool KEduVocKvtmlWriter::writeArticle( QDomElement &domElementParent ) } // neutral - articleString = m_doc->identifier(i).article().article( KEduVocArticle::Singular, KEduVocArticle::Definite, KEduVocArticle::Neutral ); + articleString = m_doc->identifier(i).article().article( KEduVocWordFlag::Singular, KEduVocWordFlag::Definite, KEduVocWordFlag::Neutral ); if ( !articleString.isEmpty() ) { QDomElement domElementND = m_domDoc.createElement( KV_ART_ND ); QDomText domTextND = m_domDoc.createTextNode( articleString ); @@ -392,7 +392,7 @@ bool KEduVocKvtmlWriter::writeArticle( QDomElement &domElementParent ) domElementND.appendChild( domTextND ); domElementEntry.appendChild( domElementND ); } - articleString = m_doc->identifier(i).article().article( KEduVocArticle::Singular, KEduVocArticle::Indefinite, KEduVocArticle::Neutral ); + articleString = m_doc->identifier(i).article().article( KEduVocWordFlag::Singular, KEduVocWordFlag::Indefinite, KEduVocWordFlag::Neutral ); if ( !articleString.isEmpty() ) { QDomElement domElementNI = m_domDoc.createElement( KV_ART_NI ); QDomText domTextNI = m_domDoc.createTextNode( articleString ); diff --git a/keduvocdocument/keduvocwordflags.h b/keduvocdocument/keduvocwordflags.h new file mode 100644 index 0000000..135e324 --- /dev/null +++ b/keduvocdocument/keduvocwordflags.h @@ -0,0 +1,63 @@ +// +// C++ Interface: keduvocwordflags +// +// Description: +// +// +// Author: David Capel , (C) 2008 +// +// Copyright: See COPYING file that comes with this distribution +// +// + +#ifndef KEDUVOCWORDFLAGS_H +#define KEDUVOCWORDFLAGS_H + +#include + +class KEduVocWordFlag +{ +public: + enum Flags + { + // This is used for both empty flags and to denote no flags of the correct type were set. + NoInformation = 0x0, + + // Gender + Masculine = 0x1, + Feminine = 0x2, + Neuter = 0x4, + + // Plurality + Singular = 0x10, + Dual = 0x20, + Plural = 0x40, + + // Part of Speech + Verb = 0x100, + Noun = 0x200, + Pronoun = 0x400, + Adjective = 0x800, + Adverb = 0x1000, + Article = 0x2000, + Conjunction = 0x4000, + OtherPartOfSpeech = 0x8000, + + // Other assorted flags + Regular = 0x10000, // Regular verb conjugation + Irregular = 0x20000, // Irregular verb conjugation + Phrase = 0x40000, // The 'word' is actually a phrase + Definite = 0x80000, // The article is definite + Indefinite = 0x100000, // The article is indefinite + }; + + static const Flags genders = (Flags)(Masculine | Feminine | Neuter); + static const Flags partsOfSpeech =(Flags)(Noun | Verb | Article | Pronoun | Adjective | Adverb | Conjunction | OtherPartOfSpeech); + static const Flags numbers = (Flags)(Singular | Plural | Dual); +}; + +Q_DECLARE_FLAGS(KEduVocWordFlags, KEduVocWordFlag::Flags); +Q_DECLARE_OPERATORS_FOR_FLAGS(KEduVocWordFlags); + + +#endif diff --git a/keduvocdocument/keduvocwordtype.cpp b/keduvocdocument/keduvocwordtype.cpp index 961a36f..853d226 100644 --- a/keduvocdocument/keduvocwordtype.cpp +++ b/keduvocdocument/keduvocwordtype.cpp @@ -26,8 +26,8 @@ class KEduVocWordType::Private { public: - EnumWordType m_wordType; - // cache the entries + // bitvector of word type flags + KEduVocWordFlags m_flags; QList m_expressions; // list of translations QList m_translations; @@ -35,9 +35,7 @@ public: KEduVocWordType::KEduVocWordType(const QString& name, KEduVocWordType *parent) : KEduVocContainer(name, WordType, parent), d( new Private ) -{ - d->m_wordType = General; -} +{} KEduVocWordType::~KEduVocWordType() { @@ -122,23 +120,23 @@ KEduVocExpression * KEduVocWordType::entry(int row, EnumEntriesRecursive recursi return entries().value(row); } -void KEduVocWordType::setWordType(EnumWordType type) +KEduVocWordFlags KEduVocWordType::wordType() const { - d->m_wordType = type; + return d->m_flags; } -KEduVocWordType::EnumWordType KEduVocWordType::wordType() const +void KEduVocWordType::setWordType(KEduVocWordFlags flags) { - return d->m_wordType; + d->m_flags = flags; } -KEduVocWordType* KEduVocWordType::childOfType(KEduVocWordType::EnumWordType type) +KEduVocWordType* KEduVocWordType::childOfType(const KEduVocWordFlags& flags) { - if(wordType()==type) { + if(d->m_flags == flags) { return this; } foreach(KEduVocContainer* child, childContainers()) { - KEduVocWordType* result = static_cast(child)->childOfType(type); + KEduVocWordType* result = static_cast(child)->childOfType(flags); if(result) { return result; } diff --git a/keduvocdocument/keduvocwordtype.h b/keduvocdocument/keduvocwordtype.h index 1cce8c9..736fd5a 100644 --- a/keduvocdocument/keduvocwordtype.h +++ b/keduvocdocument/keduvocwordtype.h @@ -21,6 +21,8 @@ #include "keduvoccontainer.h" +#include "keduvocwordflags.h" + #include #include @@ -32,17 +34,6 @@ class KEDUVOCDOCUMENT_EXPORT KEduVocWordType :public KEduVocContainer { public: - enum EnumWordType { - General, - Noun, - NounMale, - NounFemale, - NounNeutral, - Verb, - Adjective, - Adverb - }; - /** default constructor */ explicit KEduVocWordType(const QString& name, KEduVocWordType *parent = 0); @@ -55,34 +46,34 @@ public: /** * Internally (different from the name) the class can have one of the preset word types. These are used to determine special properties (verbs have conjugations available for example). - * @param type + * @param type */ - void setWordType(EnumWordType type); + void setWordType(KEduVocWordFlags flags); /** - * Return the meta word type for this class. - * @return + * Return the raw WordTypeFlags. Returns NoInformation if no flags are set. + * @return WordTypeFlags */ - KEduVocWordType::EnumWordType wordType() const; + KEduVocWordFlags wordType() const; /** * Return a child class (or this class) that is of the specified type. Returns 0 if no class of that type is found. - * @param type - * @return + * @param type + * @return */ - KEduVocWordType* childOfType(KEduVocWordType::EnumWordType type); + KEduVocWordType* childOfType(const KEduVocWordFlags& flags); /** * The word type class does keep track of individual translations, because for one entry, the translations can have different word types (eg. genders of nouns tend to be different in different langues). - * @param row - * @return + * @param row + * @return */ KEduVocTranslation * translation(int row); /** * get a list of all entries in the lesson * @param recursive include entries in sublessons - * @return + * @return */ QList < KEduVocExpression* > entries(EnumEntriesRecursive recursive = NotRecursive);