]> Git trees. - libqmvoc.git/commitdiff
Add a word type class derived from container.
authorFrederik Gladhorn <gladhorn@kde.org>
Tue, 27 Nov 2007 21:33:35 +0000 (21:33 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Tue, 27 Nov 2007 21:33:35 +0000 (21:33 +0000)
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

14 files changed:
keduvocdocument/keduvoccontainer.cpp
keduvocdocument/keduvoccontainer.h
keduvocdocument/keduvocdocument.cpp
keduvocdocument/keduvocdocument.h
keduvocdocument/keduvocexpression.cpp
keduvocdocument/keduvockvtml2reader.cpp
keduvocdocument/keduvockvtml2reader.h
keduvocdocument/keduvockvtml2writer.cpp
keduvocdocument/keduvockvtml2writer.h
keduvocdocument/keduvoclesson.h
keduvocdocument/keduvoctranslation.cpp
keduvocdocument/keduvoctranslation.h
keduvocdocument/keduvocwordtype.cpp
keduvocdocument/keduvocwordtype.h

index 5086fb8ec42a1bc5375f7c63f5ca539ce5d7fdee..dfdcd29ee062f801e120ec3c4070cbdb0f046d15 100644 (file)
@@ -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;
+}
+
 
index 377bdcbb4e9afd46368bfc9faf123f1aea9270bb..3886b2f9ac86c1870a9a7ce0215badd7b2e5ffbf 100644 (file)
@@ -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();
 
index c99a7eb32f1be874ee1e8a65c85497bf06aedc6d..feb00b0299cf0521afe1b5de82e4bd39a418327a 100644 (file)
@@ -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"
+
index 4aa3c6cd361fd982504b49d1bc5e75807082f7e0..f0eb2a5312d9f8e3bac3aa702beb28b336066d8a 100644 (file)
@@ -340,7 +340,7 @@ public:
      */
     KEduVocLesson * lesson();
 
-    KEduVocLesson * wordTypeContainer();
+    KEduVocWordType * wordTypeContainer();
 
     KEduVocLesson * leitnerContainer();
 
index b30095c290d1ae4dff50944fcb36780f5e82a59f..3131c23acd17861b2117fec356ae4e00f4ebf07a 100644 (file)
@@ -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
index dd685a58faec5e4a64676d1cd398f4c3cc29efde..1e67a72c6f1ee689b912456a80d8c13942d1eb57 100644 (file)
@@ -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();
index 487ac7fe20927c94e8c54ab077edf05cf015ad73..440dc3fbd62568de59307dc5ca33589eab89010b 100644 (file)
@@ -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 <container> 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
index b877b570c42031c01049c8b9c6b90467f5bf16cc..9d34b42e6bcae645979becd6a0ec78468b8316d5 100644 (file)
@@ -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<KEduVocLesson*>(container);
+        KEduVocWordType* wordType = static_cast<KEduVocWordType*>(container);
 
         kDebug() << "Writing type: " << wordType->name();
 
index ac998a20f969353fe289558e22b4e9504ff8f4df..a1f1cb394843742ffb7c83bb3ce9ee9955b78aaa 100644 (file)
@@ -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
index b9a8b262c28e53be59536d5d50e80fded2ffd2be..7115282d7d92ffefa081147c3a53ab9926fdcf92 100644 (file)
@@ -21,9 +21,6 @@
 
 #include "keduvoccontainer.h"
 
-#include <QtCore/QList>
-#include <QtCore/QString>
-
 class KEduVocExpression;
 
 /** class to store information about a lesson */
index c3f181742f95c1bf9e4cedf37c24e48cb123ebcf..727b3805fa40c8fd4eeeac7d70e07bd1f0420f5b 100644 (file)
@@ -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;
+}
+
index 827b5fee6d0024f4c96f49704416653d445313f4..c4d59d9aeb6a86b33d1ba64a9f4bc03f84c5ddb7 100644 (file)
@@ -26,7 +26,7 @@
 
 class KEduVocExpression;
 class KEduVocGrade;
-class KEduVocLesson;
+class KEduVocWordType;
 
 /**
  @author Frederik Gladhorn <frederik.gladhorn@kdemail.net>
@@ -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 */
index 2005b02d2fd47c8f85739ec9282f006b65dc3aca..7cc324b121d906a881d956dbe88208002c600484 100644 (file)
@@ -1,14 +1,7 @@
 /***************************************************************************
 
-    C++ Implementation: keduvocwordtype
-
-    -----------------------------------------------------------------------
-
-    begin         : Mi Aug 22 2007
-
-    copyright     : (C) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
-
-    -----------------------------------------------------------------------
+    Copyright 2007 Jeremy Whiting <jeremywhiting@scitools.com>
+    Copyright 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
 
  ***************************************************************************/
 
 
 #include "keduvocwordtype.h"
 
-#include <KLocale>
-#include <kdebug.h>
+#include "keduvocexpression.h"
+
+#include <QtCore/QList>
+#include <QtCore/QSet>
 
 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<subWordType> m_subWordTypeList;
-        bool operator== ( const wordType& other );
-    };
-
-    /// Map containing the word type name and its properties.
-    QList<wordType> 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<KEduVocTranslation*> 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<KEduVocExpression*> 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<KEduVocExpression*> 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<KEduVocWordType*>(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();
-}
 
index fbba117ddebae8e0b6beb1db3473b745614fbebe..4c8d511d555c34d4fe26e15d8a57fe623506e0e0 100644 (file)
@@ -1,14 +1,7 @@
 /***************************************************************************
 
-    C++ Interface: keduvocwordtype
-
-    -----------------------------------------------------------------------
-
-    begin         : Mi Aug 22 2007
-
-    copyright     : (C) 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
-
-    -----------------------------------------------------------------------
+    Copyright 2007 Jeremy Whiting <jeremywhiting@scitools.com>
+    Copyright 2007 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
 
  ***************************************************************************/
 
 
 #include "libkeduvocdocument_export.h"
 
-#include <QtCore/QStringList>
-#include <QtCore/QMap>
+#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 <frederik.gladhorn@kdemail.net>
-*/
-class KEDUVOCDOCUMENT_EXPORT KEduVocWordType
-{
+#include <QtCore/QList>
+#include <QtCore/QString>
+
+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 KEduVocWordTypeother );
+    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