]> Git trees. - libqmvoc.git/commitdiff
Initial port of the kvtml1 reader. Types are read, but the list of predefined types...
authorFrederik Gladhorn <gladhorn@kde.org>
Sun, 26 Aug 2007 10:01:24 +0000 (10:01 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Sun, 26 Aug 2007 10:01:24 +0000 (10:01 +0000)
Move some definitons into kvtmldefs.h from reader and writer.

svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=704797

keduvocdocument/keduvocdocument.cpp
keduvocdocument/keduvocdocument.h
keduvocdocument/keduvockvtml2reader.cpp
keduvocdocument/keduvockvtml2writer.cpp
keduvocdocument/keduvockvtmlreader.cpp
keduvocdocument/keduvockvtmlreader.h
keduvocdocument/keduvockvtmlwriter.cpp
keduvocdocument/keduvockvtmlwriter.h
keduvocdocument/keduvocwordtype.cpp
keduvocdocument/keduvocwordtype.h
keduvocdocument/kvtmldefs.h

index 9ad9d4450496747be26a491f84720424cea1f175..59de6beb35833df462ea19cb8651e5024d454516 100644 (file)
@@ -74,9 +74,6 @@ public:
   QString                   m_querytrans;
   QList<KEduVocExpression>  m_vocabulary;
   QList<int>                m_lessonsInQuery;
-  //QStringList               m_lessonDescriptions;
-
-  QStringList               m_typeDescriptions;
 
   QStringList               m_tenseDescriptions;
   QStringList               m_usageDescriptions;
@@ -104,7 +101,6 @@ void KEduVocDocument::KEduVocDocumentPrivate::init()
 {
   m_lessons.clear();
   m_articles.clear();
-  m_typeDescriptions.clear();
   m_tenseDescriptions.clear();
   m_identifiers.clear();
   m_sortIdentifier.clear();
@@ -646,37 +642,6 @@ void KEduVocDocument::setIdentifier(int idx, const QString &id)
 }
 
 
-QString KEduVocDocument::typeName (int index) const
-{
-  if (index >= d->m_typeDescriptions.count())
-    return "";
-  else
-    return d->m_typeDescriptions[index];
-}
-
-
-void KEduVocDocument::setTypeName(int idx, QString &id)
-{
-  if (idx >= d->m_typeDescriptions.size())
-    for (int i = d->m_typeDescriptions.size(); i <= idx; i++)
-      d->m_typeDescriptions.append ("");
-
-  d->m_typeDescriptions[idx] = id;
-}
-
-
-QStringList KEduVocDocument::typeDescriptions() const
-{
-  return d->m_typeDescriptions;
-}
-
-
-void KEduVocDocument::setTypeDescriptions(const QStringList &names)
-{
-  d->m_typeDescriptions = names;
-}
-
-
 QString KEduVocDocument::tenseName(int index) const
 {
   if (index >= d->m_tenseDescriptions.size())
index 9a33b5c89eb3e50fcff476ffbd71e1c1335149f8..04fc5b3dcc2aef163b21a2c059bfcac8699e0791 100644 (file)
@@ -290,35 +290,13 @@ public:
 
   // *** type methods ***
 
-  KEduVocWordType* wordTypes();
-
-
-///@todo delete the type methods below
-  /**
-   * Sets attribute string
-   *
-   * @param index            number of attribute
-   * @param str              name of attribute
-   */
-  void setTypeName(int index, QString &str);
-
   /**
-   * Returns the attribute string
+   * Returns the type handling class. See KEduVocWordType.
    *
-   * @param index            number of attribute
-   * @returns                string
-   */
-  QString typeName(int index) const;
-
-  /**
-   * Sets the descriptions of the types
+   * @returns the KEduVocWordType* type handling class
    */
-  void setTypeDescriptions(const QStringList &names);
+  KEduVocWordType* wordTypes();
 
-  /**
-   * Gets the descriptions of the types
-   */
-  QStringList typeDescriptions() const;
 
   // *** tense methods ***
 
index 4bc49dafa0b4bb57669b60007119f965cc1cd69f..b9bd394da774b539266357d6f11709a46dbaecc6 100644 (file)
@@ -27,7 +27,7 @@
 #include "keduvocdocument.h"
 #include "keduvoclesson.h"
 #include "kvtml2defs.h"
-#include "kvtmldefs.h"
+// should no longer be needed: #include "kvtmldefs.h"
 #include "keduvockvtmlreader.h"
 
 KEduVocKvtml2Reader::KEduVocKvtml2Reader(QIODevice *file)
index b536103caa3f81ea14952d59bfc3a1a5eea8e3a9..f7dcbc05bb1a73420a94c01a6d57cd8abc26c631 100644 (file)
@@ -23,7 +23,7 @@
 #include "keduvocdocument.h"
 #include "keduvocexpression.h"
 #include "keduvoclesson.h"
-#include "kvtmldefs.h"
+// should no longer be needed: #include "kvtmldefs.h"
 #include "kvtml2defs.h"
 
 KEduVocKvtml2Writer::KEduVocKvtml2Writer(QFile *file)
index ecd65947e1d14f09e16b56f4b7d504edb10ac81e..86c3660da94dc4550d2aab52c6d5e68aef0f89b2 100644 (file)
@@ -618,31 +618,26 @@ bool KEduVocKvtmlReader::readType(QDomElement &domElementParent)
 {
   QString s;
   QDomElement currentElement;
-  QStringList descriptions;
 
   QDomNodeList entryList = domElementParent.elementsByTagName(KV_TYPE_DESC);
   if (entryList.length() <= 0)
     return false;
 
-  descriptions.clear();
-
   for (int i = 0; i < entryList.count(); ++i) {
     currentElement = entryList.item(i).toElement();
     if (currentElement.parentNode() == domElementParent) {
-      int no = 0;
+      // We need to even add empty elements since the old system relied on
+      // the order. So "type1" "" "type2" should be just like that.
 
-      QDomAttr attribute = currentElement.attributeNode(KV_TYPE_NO);
-      if (!attribute.isNull())
-        no = attribute.value().toInt();
+      kDebug() << "Adding old self defined type: " << currentElement.text();
+      // add the type to the list of available types
+      m_doc->wordTypes()->addType(currentElement.text());
 
-      s = currentElement.text();
-      if (s.isNull())
-        s = "";
-      descriptions.append(s);
+      // from this the #1 are transformed to something sensible again
+      m_oldSelfDefinedTypes.append(currentElement.text());
     }
   }
 
-  m_doc->setTypeDescriptions(descriptions);
   return true;
 }
 
@@ -816,6 +811,7 @@ bool KEduVocKvtmlReader::readExpressionChildAttributes( QDomElement &domElementE
                                                         QString &pronunciation,
                                                         int &width,
                                                         QString &type,
+                                                        QString &subType,
                                                         QString &faux_ami_f,
                                                         QString &faux_ami_t,
                                                         QString &synonym,
@@ -962,35 +958,39 @@ bool KEduVocKvtmlReader::readExpressionChildAttributes( QDomElement &domElementE
   if (!attribute.isNull())
     antonym = attribute.value();
 
-  attribute = domElementExpressionChild.attributeNode(KV_EXPRTYPE);
-  if (!attribute.isNull())
-  {
-    type = attribute.value();
-    if (type == "1")
-      type = QM_VERB;
-    else if (type == "2")  // convert from pre-0.5 versions
-      type = QM_NOUN;
-    else if (type == "3")
-      type = QM_NAME;
-
-    if (type.length() != 0 && type.left(1) == QM_USER_TYPE)
+    // this is all done by reference - so we have to care about "type" :(
+    attribute = domElementExpressionChild.attributeNode(KV_EXPRTYPE);
+    if (!attribute.isNull())
     {
-      int num = qMin(type.mid (1, 40).toInt(), 1000); // paranoia check
-      if (num > m_doc->typeDescriptions().count())
-      {
-        // description missing ?
-        QString s;
-        QStringList sl = m_doc->typeDescriptions();
-        for (int i = m_doc->typeDescriptions().count(); i < num; i++)
+        QString oldType = attribute.value();
+
+        if (oldType.length() >= 2 && type.left(1) == QM_USER_TYPE)
         {
-          s.setNum(i + 1);
-          s.prepend("#");  // invent descr according to number
-          sl.append(s);
-        }
-        m_doc->setTypeDescriptions(sl);
-      }
+            // they started counting at 1
+            int selfDefinedTypeIndex = oldType.right(type.count()-1).toInt() -1;
+            // append invented types (do we not trust our own writer?)
+            if ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() )
+            {
+                while (selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count()) {
+                    m_oldSelfDefinedTypes.append( i18n("User defined word type %1", m_oldSelfDefinedTypes.count() - 1) );
+                }
+            }
+            type = m_oldSelfDefinedTypes.value(selfDefinedTypeIndex);
+        } else { // not user defined - preset types
+                // convert from pre-0.5 versions (I guess we can just leave that in here.
+            // I seriously doubt that any such documents exist...
+            if (oldType == "1")
+                oldType = QM_VERB;
+            else if (oldType == "2")
+                oldType = QM_NOUN;
+            else if (oldType == "3")
+                oldType = QM_NAME;
+
+            type = m_doc->wordTypes()->mainTypeFromOldFormat(oldType);
+            subType = m_doc->wordTypes()->subTypeFromOldFormat(oldType);
+
+        } // not user defined - preset types
     }
-  }
 
   pronunciation = "";
   attribute = domElementExpressionChild.attributeNode(KV_PRONUNCE);
@@ -1029,6 +1029,7 @@ bool KEduVocKvtmlReader::readExpression(QDomElement &domElementParent)
   int                       lesson = 0;
   int                       width;
   QString                   type;
+  QString                   subType;
   QString                   faux_ami_f;
   QString                   faux_ami_t;
   QString                   synonym;
@@ -1061,7 +1062,7 @@ bool KEduVocKvtmlReader::readExpression(QDomElement &domElementParent)
     // so make sure this lesson is in the document
     m_doc->addLesson(QString("#") + QString::number(lesson), lesson);
   }
-  
+
   attribute = domElementParent.attributeNode(KV_SELECTED);
   if (!attribute.isNull())
     inquery = attribute.value() == "1" ? true : false;
@@ -1074,35 +1075,40 @@ bool KEduVocKvtmlReader::readExpression(QDomElement &domElementParent)
   else
     active = true;
 
-  attribute = domElementParent.attributeNode(KV_EXPRTYPE);
-  if (!attribute.isNull())
-  {
-    exprtype = attribute.value();
-    if (exprtype == "1")
-      exprtype = QM_VERB;
-    else if (exprtype == "2")  // convert from pre-0.5 versions
-      exprtype = QM_NOUN;
-    else if (exprtype == "3")
-      exprtype = QM_NAME;
-
-    if (exprtype.length() != 0 && exprtype.left(1) == QM_USER_TYPE)
+    // this is all done by reference - so we have to care about "type" :(
+    attribute = domElementParent.attributeNode(KV_EXPRTYPE);
+    if (!attribute.isNull())
     {
-      int num = qMin(exprtype.mid(1, 40).toInt(), 1000); // paranoia check
-      if (num > m_doc->typeDescriptions().count())
-      {
-        // description missing ?
-        QString s;
-        QStringList sl = m_doc->typeDescriptions();
-        for (int i = m_doc->typeDescriptions().count(); i < num; i++)
+        QString oldType = attribute.value();
+
+        if (oldType.length() >= 2 && type.left(1) == QM_USER_TYPE)
         {
-          s.setNum(i + 1);
-          s.prepend("#");  // invent descr according to number
-          sl.append(s);
-        }
-        m_doc->setTypeDescriptions(sl);
-      }
+            // they started counting at 1
+            int selfDefinedTypeIndex = oldType.right(type.count()-1).toInt() -1;
+            // append invented types (do we not trust our own writer?)
+            if ( selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count() )
+            {
+                while (selfDefinedTypeIndex >= m_oldSelfDefinedTypes.count()) {
+                    m_oldSelfDefinedTypes.append( i18n("User defined word type %1", m_oldSelfDefinedTypes.count() - 1) );
+                }
+            }
+            type = m_oldSelfDefinedTypes.value(selfDefinedTypeIndex);
+        } else { // not user defined - preset types
+                // convert from pre-0.5 versions (I guess we can just leave that in here.
+            // I seriously doubt that any such documents exist...
+            if (oldType == "1")
+                oldType = QM_VERB;
+            else if (oldType == "2")
+                oldType = QM_NOUN;
+            else if (oldType == "3")
+                oldType = QM_NAME;
+
+            type = m_doc->wordTypes()->mainTypeFromOldFormat(oldType);
+            subType = m_doc->wordTypes()->subTypeFromOldFormat(oldType);
+
+        } // not user defined - preset types
     }
-  }
+
 
   //-------------------------------------------------------------------------
   // Children 'Translation'
@@ -1129,11 +1135,11 @@ bool KEduVocKvtmlReader::readExpression(QDomElement &domElementParent)
 
       // read attributes - the order of the query grades is interchanged!
       if (i == 0 && !readExpressionChildAttributes( currentElement, lang, grade, r_grade, qcount, r_qcount, qdate, r_qdate, remark, bcount, r_bcount, query_id,
-                                          pronunciation, width, type, faux_ami_t, faux_ami_f, synonym, example, antonym, usage, paraphrase))
+                                          pronunciation, width, type, subType, faux_ami_t, faux_ami_f, synonym, example, antonym, usage, paraphrase))
         return false;
 
       if (i != 0 && !readExpressionChildAttributes( currentElement, lang, grade, r_grade, qcount, r_qcount, qdate, r_qdate, remark, bcount, r_bcount, query_id,
-                                          pronunciation, width, type, faux_ami_f, faux_ami_t, synonym, example, antonym, usage, paraphrase))
+                                          pronunciation, width, type, subType, faux_ami_f, faux_ami_t, synonym, example, antonym, usage, paraphrase))
         return false;
 
       if (m_doc->entryCount() == 0)
@@ -1231,8 +1237,10 @@ bool KEduVocKvtmlReader::readExpression(QDomElement &domElementParent)
         expr.translation(i).setMultipleChoice(mc);
         mc.clear();
       }
-      if (!type.isEmpty() )
-        expr.translation(i).setType (type);
+
+      expr.translation(i).setType(type);
+      expr.translation(i).setType(subType);
+
       if (!remark.isEmpty() )
         expr.translation(i).setComment (remark);
       if (!pronunciation.isEmpty() )
@@ -1277,7 +1285,7 @@ bool KEduVocKvtmlReader::readExpression(QDomElement &domElementParent)
   {
        m_doc->lesson(lesson)->addEntry(m_doc->entryCount());
   }
-  
+
   return true;
 }
 
index 369584b9fa183e7c9b4cf99e3fdce45e0353ed4f..8679118f54874be3b16ca0c30883489a499d749b 100644 (file)
 class QIODevice;
 class KEduVocDocument;
 
-// internal types, indented are subtypes
-
-#define QM_VERB           "v"    // go
-#define   QM_VERB_IRR     "ir"
-#define   QM_VERB_REG     "re"
-#define QM_NOUN           "n"    // table, coffee
-#define   QM_NOUN_F       "f"
-#define   QM_NOUN_M       "m"
-#define   QM_NOUN_S       "s"
-#define QM_NAME           "nm"
-#define QM_ART            "ar"   // article
-#define   QM_ART_DEF      "def"  // definite    a/an
-#define   QM_ART_IND      "ind"  // indefinite  the
-#define QM_ADJ            "aj"   // adjective   expensive, good
-#define QM_ADV            "av"   // adverb      today, strongly
-#define QM_PRON           "pr"   // pronoun     you, she
-#define   QM_PRON_POS     "pos"  // possessive  my, your
-#define   QM_PRON_PER     "per"  // personal
-#define QM_PHRASE         "ph"
-#define QM_NUM            "num"  // numeral
-#define   QM_NUM_ORD      "ord"  // ordinal     first, second
-#define   QM_NUM_CARD     "crd"  // cardinal    one, two
-#define QM_INFORMAL       "ifm"
-#define QM_FIG            "fig"
-#define QM_CON            "con"  // conjuncton  and, but
-#define QM_PREP           "pre"  // preposition behind, between
-#define QM_QUEST          "qu"   // question    who, what
-
-// type delimiters
-
-#define QM_USER_TYPE  "#"   // designates number of user type
-#define QM_TYPE_DIV   ":"   // divide main from subtype
-
-// usage delimiters (also declared in UsageManager.h)
-
-#define UL_USER_USAGE  "#"   // designates number of user type
 
 /**
 @author Eric Pignet
@@ -98,6 +62,7 @@ public:
                                      QString &pronunciation,
                                      int &width,
                                      QString &type,
+                                     QString &subType,
                                      QString &faux_ami_f,
                                      QString &faux_ami_t,
                                      QString &synonym,
@@ -116,6 +81,7 @@ private:
   QString m_errorMessage;
   int m_cols;
   int m_lines;
+  QStringList m_oldSelfDefinedTypes;
 };
 
 #endif
index 461937793e2162ef8e6b59dfaa1f8722d96cb7dc..b93d37c7826f36a2b4aa97ef9facb781cf68177d 100644 (file)
@@ -450,6 +450,7 @@ bool KEduVocKvtmlWriter::writeOption(QDomDocument &domDoc, QDomElement &domEleme
 
 bool KEduVocKvtmlWriter::writeType(QDomDocument &domDoc, QDomElement &domElementParent)
 {
+/** @todo port to new type handling
   if (m_doc->typeDescriptions().count() == 0)
     return true;
 
@@ -471,6 +472,7 @@ bool KEduVocKvtmlWriter::writeType(QDomDocument &domDoc, QDomElement &domElement
   }
 
   domElementParent.appendChild(domElementType);
+*/
   return true;
 }
 
index c012822093a929984c70e7851ab8f38aec13bade..d23c3a2d5e92abf6ce17942b2cc59b53e08cb34e 100644 (file)
 
 class KEduVocDocument;
 
-// internal types, indented are subtypes
-
-#define QM_VERB           "v"    // go
-#define   QM_VERB_IRR     "ir"
-#define   QM_VERB_REG     "re"
-#define QM_NOUN           "n"    // table, coffee
-#define   QM_NOUN_F       "f"
-#define   QM_NOUN_M       "m"
-#define   QM_NOUN_S       "s"
-#define QM_NAME           "nm"
-#define QM_ART            "ar"   // article
-#define   QM_ART_DEF      "def"  // definite    a/an
-#define   QM_ART_IND      "ind"  // indefinite  the
-#define QM_ADJ            "aj"   // adjective   expensive, good
-#define QM_ADV            "av"   // adverb      today, strongly
-#define QM_PRON           "pr"   // pronoun     you, she
-#define   QM_PRON_POS     "pos"  // possessive  my, your
-#define   QM_PRON_PER     "per"  // personal
-#define QM_PHRASE         "ph"
-#define QM_NUM            "num"  // numeral
-#define   QM_NUM_ORD      "ord"  // ordinal     first, second
-#define   QM_NUM_CARD     "crd"  // cardinal    one, two
-#define QM_INFORMAL       "ifm"
-#define QM_FIG            "fig"
-#define QM_CON            "con"  // conjuncton  and, but
-#define QM_PREP           "pre"  // preposition behind, between
-#define QM_QUEST          "qu"   // question    who, what
-
-// type delimiters
-
-#define QM_USER_TYPE  "#"   // designates number of user type
-#define QM_TYPE_DIV   ":"   // divide main from subtype
-
 /**
 @author Eric Pignet
 */
index 7016179292d599720dffa2eccafb84e526d41fed..16a6548b340b501e29de340a45e17e7e3fa4f184 100644 (file)
@@ -77,6 +77,9 @@ public:
 
     /// Map containing the word type name and its properties.
     QList<wordType> m_wordTypeList;
+
+    QMap<QString, QString> m_oldMainTypeNames;
+    QMap<QString, QString> m_oldSubTypeNames;
 };
 
 
@@ -85,6 +88,16 @@ public:
 KEduVocWordType::KEduVocWordType()
 : d(new Private)
 {
+    // this should go into the old reader/writer
+    initOldTypeLists();
+}
+
+KEduVocWordType::KEduVocWordType(const KEduVocWordType & other)
+: d(new Private)
+{
+    d->m_wordTypeList = other.d->m_wordTypeList;
+    d->m_oldMainTypeNames = other.d->m_oldMainTypeNames;
+    d->m_oldSubTypeNames = other.d->m_oldSubTypeNames;
 }
 
 KEduVocWordType::~KEduVocWordType()
@@ -99,15 +112,7 @@ KEduVocWordType & KEduVocWordType::operator =(const KEduVocWordType & other)
     return *this;
 }
 
-KEduVocWordType::KEduVocWordType(const KEduVocWordType & other)
-: d(new Private)
-{
-    d->m_wordTypeList = other.d->m_wordTypeList;
-}
-
-
 
-/*
 QString KEduVocWordType::mainTypeFromOldFormat(const QString & typeSubtypeString) const
 {
     QString mainType;
@@ -118,16 +123,7 @@ QString KEduVocWordType::mainTypeFromOldFormat(const QString & typeSubtypeString
     else
         mainType = typeSubtypeString;
 
-    if ( mainType.startsWith(KVTML_1_TYPE_USER) ) {
-        mainType.remove(0, 1);
-        i = mainType.toInt()-1;
-        if (i >= 0 && i < m_userTypeDescriptions.count())
-            return m_userTypeDescriptions[i];
-        else
-            return QString();
-    }
-
-    QString wt = m_oldMainTypeNames.value( mainType );
+    QString wt = d->m_oldMainTypeNames.value( mainType );
     if ( wt == QString() ) {
         kDebug() << "Unknown old maintype: " << typeSubtypeString;
         return typeSubtypeString;
@@ -146,46 +142,45 @@ QString KEduVocWordType::subTypeFromOldFormat(const QString & typeSubtypeString)
         return QString();
     }
 
-    QString wt = m_oldSubTypeNames.value( t );
+    QString wt = d->m_oldSubTypeNames.value( t );
     if ( wt == QString() ) {
         kDebug() << "Unknown old maintype: " << typeSubtypeString;
         return typeSubtypeString;
     }
     return wt;
 }
-*/
 
 
 void KEduVocWordType::initOldTypeLists()
 {
-    m_oldMainTypeNames.clear();
-    m_oldMainTypeNames.insert("v", i18n("Verb"));
-    m_oldMainTypeNames.insert("n", i18n("Noun"));
-    m_oldMainTypeNames.insert("nm", i18n("Name"));
-    m_oldMainTypeNames.insert("ar", i18n("Article"));
-    m_oldMainTypeNames.insert("aj", i18n("Adjective"));
-    m_oldMainTypeNames.insert("av", i18n("Adverb"));
-    m_oldMainTypeNames.insert("pr", i18n("Pronoun"));
-    m_oldMainTypeNames.insert("ph", i18n("Phrase"));
-    m_oldMainTypeNames.insert("num", i18n("Numeral"));
-    m_oldMainTypeNames.insert("con", i18n("Conjunction"));
-    m_oldMainTypeNames.insert("pre", i18n("Preposition"));
-    m_oldMainTypeNames.insert("qu", i18n("Question"));
-    m_oldMainTypeNames.insert("ifm", i18n("Informal"));
-    m_oldMainTypeNames.insert("fig", i18n("Figuratively"));
-
-    m_oldSubTypeNames.clear();
-    m_oldSubTypeNames.insert("ord", i18n("Numeral Ordinal"));
-    m_oldSubTypeNames.insert("crd", i18n("Numeral Cardinal"));
-    m_oldSubTypeNames.insert("def", i18n("Article Definite"));
-    m_oldSubTypeNames.insert("ind", i18n("Article Indefinite"));
-    m_oldSubTypeNames.insert("re", i18n("Verb Regular"));
-    m_oldSubTypeNames.insert("ir", i18n("Verb Irregular"));
-    m_oldSubTypeNames.insert("pos", i18n("Pronoun Possessive"));
-    m_oldSubTypeNames.insert("per", i18n("Pronoun Personal"));
-    m_oldSubTypeNames.insert("m", i18n("Noun Male"));
-    m_oldSubTypeNames.insert("f", i18n("Noun Female"));
-    m_oldSubTypeNames.insert("s", i18n("Noun Neutral"));
+    d->m_oldMainTypeNames.clear();
+    d->m_oldMainTypeNames.insert("v", i18n("Verb"));
+    d->m_oldMainTypeNames.insert("n", i18n("Noun"));
+    d->m_oldMainTypeNames.insert("nm", i18n("Name"));
+    d->m_oldMainTypeNames.insert("ar", i18n("Article"));
+    d->m_oldMainTypeNames.insert("aj", i18n("Adjective"));
+    d->m_oldMainTypeNames.insert("av", i18n("Adverb"));
+    d->m_oldMainTypeNames.insert("pr", i18n("Pronoun"));
+    d->m_oldMainTypeNames.insert("ph", i18n("Phrase"));
+    d->m_oldMainTypeNames.insert("num", i18n("Numeral"));
+    d->m_oldMainTypeNames.insert("con", i18n("Conjunction"));
+    d->m_oldMainTypeNames.insert("pre", i18n("Preposition"));
+    d->m_oldMainTypeNames.insert("qu", i18n("Question"));
+    d->m_oldMainTypeNames.insert("ifm", i18n("Informal"));
+    d->m_oldMainTypeNames.insert("fig", i18n("Figuratively"));
+
+    d->m_oldSubTypeNames.clear();
+    d->m_oldSubTypeNames.insert("ord", i18n("Numeral Ordinal"));
+    d->m_oldSubTypeNames.insert("crd", i18n("Numeral Cardinal"));
+    d->m_oldSubTypeNames.insert("def", i18n("Article Definite"));
+    d->m_oldSubTypeNames.insert("ind", i18n("Article Indefinite"));
+    d->m_oldSubTypeNames.insert("re", i18n("Verb Regular"));
+    d->m_oldSubTypeNames.insert("ir", i18n("Verb Irregular"));
+    d->m_oldSubTypeNames.insert("pos", i18n("Pronoun Possessive"));
+    d->m_oldSubTypeNames.insert("per", i18n("Pronoun Personal"));
+    d->m_oldSubTypeNames.insert("m", i18n("Noun Male"));
+    d->m_oldSubTypeNames.insert("f", i18n("Noun Female"));
+    d->m_oldSubTypeNames.insert("s", i18n("Noun Neutral"));
 
 }
 
@@ -208,10 +203,10 @@ QStringList KEduVocWordType::mainTypeList() const
 QString KEduVocWordType::oldType(const QString & mainType, const QString & subType) const
 {
     QString oldType;
-    oldType = m_oldMainTypeNames.key(mainType);
+    oldType = d->m_oldMainTypeNames.key(mainType);
     if ( subType != QString() ) {
         oldType.append(KVTML_1_TYPE_DIV);
-        oldType.append(m_oldSubTypeNames.key(subType));
+        oldType.append(d->m_oldSubTypeNames.key(subType));
     }
 
     if ( oldType.isEmpty() ) {
@@ -308,6 +303,14 @@ kDebug() << "Get subtypes for " << mainType << " = " << mainIndex;
 
 void KEduVocWordType::addType(const QString & typeName, const QString & specialType, const QString & specialTypeExplanation)
 {
+    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;
index 99a4d5d5fe377a38a58e513d0d0f49d7cb9b0b1c..5b95d8ddead7f40be016559bb5b326c947ef4f9d 100644 (file)
@@ -101,6 +101,10 @@ public:
 
     void printDebugWordTypes();
 
+    // these should move into the old writer/reader
+    QString mainTypeFromOldFormat(const QString& typeSubtypeString) const;
+    QString subTypeFromOldFormat(const QString& typeSubtypeString) const;
+
 private:
     static const QString KVTML_1_TYPE_USER;
     static const QString KVTML_1_TYPE_DIV;
@@ -109,19 +113,13 @@ private:
 
 
     /// user defined types of old documents
-    QStringList m_userTypeDescriptions;
-
-    QMap<QString, QString> m_oldMainTypeNames;
-    QMap<QString, QString> m_oldSubTypeNames;
-
+//     QStringList m_userTypeDescriptions;
 
 
     QString mainTypeName(int index) const;
     int mainTypeIndex(const QString& name) const;
     int subTypeIndex( const QString& mainTypeName, const QString& subTypeName ) const;
 
-    QString mainTypeFromOldFormat(const QString& typeSubtypeString) const;
-    QString subTypeFromOldFormat(const QString& typeSubtypeString) const;
     QString oldType(const QString& mainType, const QString& subType) const;
 
     class Private;
index 73f037230abbce07bc8a87f102e5bfdb87ae1bfb..ac65d193f15f314ee150d633c23b45e20a1a71f4 100644 (file)
@@ -217,4 +217,43 @@ static const QLatin1String KV_ART_ENTRY("e");  // article entry
 #define KV_CONJ_COMMON "common"      // female contains common for all three
 
 
+// internal types, indented are subtypes
+
+#define QM_VERB           "v"    // go
+#define   QM_VERB_IRR     "ir"
+#define   QM_VERB_REG     "re"
+#define QM_NOUN           "n"    // table, coffee
+#define   QM_NOUN_F       "f"
+#define   QM_NOUN_M       "m"
+#define   QM_NOUN_S       "s"
+#define QM_NAME           "nm"
+#define QM_ART            "ar"   // article
+#define   QM_ART_DEF      "def"  // definite    a/an
+#define   QM_ART_IND      "ind"  // indefinite  the
+#define QM_ADJ            "aj"   // adjective   expensive, good
+#define QM_ADV            "av"   // adverb      today, strongly
+#define QM_PRON           "pr"   // pronoun     you, she
+#define   QM_PRON_POS     "pos"  // possessive  my, your
+#define   QM_PRON_PER     "per"  // personal
+#define QM_PHRASE         "ph"
+#define QM_NUM            "num"  // numeral
+#define   QM_NUM_ORD      "ord"  // ordinal     first, second
+#define   QM_NUM_CARD     "crd"  // cardinal    one, two
+#define QM_INFORMAL       "ifm"
+#define QM_FIG            "fig"
+#define QM_CON            "con"  // conjuncton  and, but
+#define QM_PREP           "pre"  // preposition behind, between
+#define QM_QUEST          "qu"   // question    who, what
+
+// type delimiters
+
+#define QM_USER_TYPE  "#"   // designates number of user type
+#define QM_TYPE_DIV   ":"   // divide main from subtype
+
+// usage delimiters (also declared in UsageManager.h)
+
+#define UL_USER_USAGE  "#"   // designates number of user type
+
+
+
 #endif // KVTMLDEFS_H