]> Git trees. - libqmvoc.git/commitdiff
NOTE: Breaks binary compatibility. Make sure to make install after you make this.
authorDavid Capel <wot.narg@gmail.com>
Wed, 30 Jul 2008 08:07:53 +0000 (08:07 +0000)
committerDavid Capel <wot.narg@gmail.com>
Wed, 30 Jul 2008 08:07:53 +0000 (08:07 +0000)
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

keduvocdocument/CMakeLists.txt
keduvocdocument/keduvocarticle.cpp
keduvocdocument/keduvocarticle.h
keduvocdocument/keduvockvtml2reader.cpp
keduvocdocument/keduvockvtml2writer.cpp
keduvocdocument/keduvockvtmlcompability.cpp
keduvocdocument/keduvockvtmlwriter.cpp
keduvocdocument/keduvocwordflags.h [new file with mode: 0644]
keduvocdocument/keduvocwordtype.cpp
keduvocdocument/keduvocwordtype.h

index f3295c5211f416b0b8f884cdd0a2e39f2e577d90..05a3aa1e0fa358f7f9295fcedc8dd34353ea2607 100644 (file)
@@ -27,7 +27,8 @@ keduvocdocument.cpp
    keduvocvokabelnreader.cpp
    keduvocwqlreader.cpp
    keduvocxdxfreader.cpp
-   sharedkvtmlfiles.cpp )
+   sharedkvtmlfiles.cpp
+    )
 
 kde4_add_library(keduvocdocument SHARED ${keduvocdocument_LIB_SRCS})
 
index c84855bbc70c83ea5d3e8e2eb10f4d6c66670ff7..747d9a31e3f7b4d4092543beb2ae9c0f5b4976a7 100644 (file)
@@ -16,6 +16,7 @@
  ***************************************************************************/
 
 #include "keduvocarticle.h"
+#include "keduvocwordflags.h"
 
 #include <QtCore/QMap>
 #include <KDebug>
@@ -23,7 +24,7 @@
 class KEduVocArticle::Private
 {
 public:
-    QMap <int, QString>    m_articles;
+    QMap <KEduVocWordFlags, QString>    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
 {
index 359ef83b1c76686d0b9a795f274a660de961abd3..068ee3717a78bc6fc6ca6eef17de24a748ea1794 100644 (file)
@@ -22,6 +22,9 @@
 
 #include <QtCore/QStringList>
 
+#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;
 };
index 195c73a6c4036d690440a72e8a05d94956d917a7..ff95c569dd088faba6255041d975af63e71b2e8e 100644 (file)
@@ -470,19 +470,31 @@ bool KEduVocKvtml2Reader::readArticle( QDomElement &articleElement, int identifi
  </article>
 */
 {
-    // singular
-    for ( KEduVocArticle::ArticleNumber num = KEduVocArticle::Singular; num <= KEduVocArticle::Plural; num = KEduVocArticle::ArticleNumber(num+1) ) {
+    QMap<int, KEduVocWordFlag::Flags> numbers;
+    numbers[0] = KEduVocWordFlag::Singular;
+    numbers[1] = KEduVocWordFlag::Dual;
+    numbers[2] = KEduVocWordFlag::Plural;
+    QMap<int, KEduVocWordFlag::Flags> genders;
+    genders[0] = KEduVocWordFlag::Masculine;
+    genders[1] = KEduVocWordFlag::Feminine;
+    genders[2] = KEduVocWordFlag::Neuter;
+    QMap<int, KEduVocWordFlag::Flags> 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
 
index 354999e1a1faab782d835559998942047750592a..b5fdec666b1cdb93e4830750978bf7c1db4788f5 100644 (file)
@@ -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<int, KEduVocWordFlag::Flags> numbers;
+    numbers[0] = KEduVocWordFlag::Singular;
+    numbers[1] = KEduVocWordFlag::Dual;
+    numbers[2] = KEduVocWordFlag::Plural;
+    QMap<int, KEduVocWordFlag::Flags> genders;
+    genders[0] = KEduVocWordFlag::Masculine;
+    genders[1] = KEduVocWordFlag::Feminine;
+    genders[2] = KEduVocWordFlag::Neuter;
+    QMap<int, KEduVocWordFlag::Flags> 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
index 65501744f50854fedb37d3f30230a126a10cac0e..ead419f7631a25f482857888af71c6185741bd2f 100644 (file)
@@ -243,49 +243,56 @@ void KEduVocKvtmlCompability::setupWordTypes(KEduVocWordType * parent)
         parent->appendChildContainer(wordType);
         m_userdefinedTypeCounter++;
     }
-    static_cast<KEduVocWordType*>(parent->childContainer(4))->setWordType(KEduVocWordType::Adjective);
-    static_cast<KEduVocWordType*>(parent->childContainer(5))->setWordType(KEduVocWordType::Adverb);
+    static_cast<KEduVocWordType*>(parent->childContainer(4))->setWordType(KEduVocWordFlag::Adjective);
+    static_cast<KEduVocWordType*>(parent->childContainer(5))->setWordType(KEduVocWordFlag::Adverb);
 
     KEduVocWordType* numeral = static_cast<KEduVocWordType*>(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<KEduVocWordType*>(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<KEduVocWordType*>(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<KEduVocWordType*>(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<KEduVocWordType*>(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);
 }
 
index 9a698814b569cd59221179b99b1a856e4c820c84..b47f7b1a6e62bc261c8ef39ba51a6be86163fb91 100644 (file)
@@ -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 (file)
index 0000000..135e324
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// C++ Interface: keduvocwordflags
+//
+// Description:
+//
+//
+// Author: David Capel <wot.narg@gmail.com>, (C) 2008
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+
+#ifndef KEDUVOCWORDFLAGS_H
+#define KEDUVOCWORDFLAGS_H
+
+#include <QFlags>
+
+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
index 961a36fb130b27ed0d808364a86641db2f92550b..853d2269d54033a8a04c74eda470afbd86575374 100644 (file)
@@ -26,8 +26,8 @@
 class KEduVocWordType::Private
 {
 public:
-    EnumWordType m_wordType;
-    // cache the entries
+    // bitvector of word type flags
+    KEduVocWordFlags m_flags;
     QList<KEduVocExpression*> m_expressions;
     // list of translations
     QList<KEduVocTranslation*> 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<KEduVocWordType*>(child)->childOfType(type);
+        KEduVocWordType* result = static_cast<KEduVocWordType*>(child)->childOfType(flags);
         if(result) {
             return result;
         }
index 1cce8c9cda5e2d8763f3100c4403f80d3735e8cd..736fd5ae0a4d2450df64a5295f74f9ba16705033 100644 (file)
@@ -21,6 +21,8 @@
 
 #include "keduvoccontainer.h"
 
+#include "keduvocwordflags.h"
+
 #include <QtCore/QList>
 #include <QtCore/QString>
 
@@ -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);