From: Frederik Gladhorn Date: Sun, 26 Aug 2007 10:01:24 +0000 (+0000) Subject: Initial port of the kvtml1 reader. Types are read, but the list of predefined types... X-Git-Tag: v3.93.0~57 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=0e10310df69b146137a21514b1c1395487ccf836;p=libqmvoc.git Initial port of the kvtml1 reader. Types are read, but the list of predefined types still has to be created. Move some definitons into kvtmldefs.h from reader and writer. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=704797 --- diff --git a/keduvocdocument/keduvocdocument.cpp b/keduvocdocument/keduvocdocument.cpp index 9ad9d44..59de6be 100644 --- a/keduvocdocument/keduvocdocument.cpp +++ b/keduvocdocument/keduvocdocument.cpp @@ -74,9 +74,6 @@ public: QString m_querytrans; QList m_vocabulary; QList 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()) diff --git a/keduvocdocument/keduvocdocument.h b/keduvocdocument/keduvocdocument.h index 9a33b5c..04fc5b3 100644 --- a/keduvocdocument/keduvocdocument.h +++ b/keduvocdocument/keduvocdocument.h @@ -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 *** diff --git a/keduvocdocument/keduvockvtml2reader.cpp b/keduvocdocument/keduvockvtml2reader.cpp index 4bc49da..b9bd394 100644 --- a/keduvocdocument/keduvockvtml2reader.cpp +++ b/keduvocdocument/keduvockvtml2reader.cpp @@ -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) diff --git a/keduvocdocument/keduvockvtml2writer.cpp b/keduvocdocument/keduvockvtml2writer.cpp index b536103..f7dcbc0 100644 --- a/keduvocdocument/keduvockvtml2writer.cpp +++ b/keduvocdocument/keduvockvtml2writer.cpp @@ -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) diff --git a/keduvocdocument/keduvockvtmlreader.cpp b/keduvocdocument/keduvockvtmlreader.cpp index ecd6594..86c3660 100644 --- a/keduvocdocument/keduvockvtmlreader.cpp +++ b/keduvocdocument/keduvockvtmlreader.cpp @@ -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; } diff --git a/keduvocdocument/keduvockvtmlreader.h b/keduvocdocument/keduvockvtmlreader.h index 369584b..8679118 100644 --- a/keduvocdocument/keduvockvtmlreader.h +++ b/keduvocdocument/keduvockvtmlreader.h @@ -30,42 +30,6 @@ 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 diff --git a/keduvocdocument/keduvockvtmlwriter.cpp b/keduvocdocument/keduvockvtmlwriter.cpp index 4619377..b93d37c 100644 --- a/keduvocdocument/keduvockvtmlwriter.cpp +++ b/keduvocdocument/keduvockvtmlwriter.cpp @@ -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; } diff --git a/keduvocdocument/keduvockvtmlwriter.h b/keduvocdocument/keduvockvtmlwriter.h index c012822..d23c3a2 100644 --- a/keduvocdocument/keduvockvtmlwriter.h +++ b/keduvocdocument/keduvockvtmlwriter.h @@ -28,39 +28,6 @@ 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 */ diff --git a/keduvocdocument/keduvocwordtype.cpp b/keduvocdocument/keduvocwordtype.cpp index 7016179..16a6548 100644 --- a/keduvocdocument/keduvocwordtype.cpp +++ b/keduvocdocument/keduvocwordtype.cpp @@ -77,6 +77,9 @@ public: /// Map containing the word type name and its properties. QList m_wordTypeList; + + QMap m_oldMainTypeNames; + QMap 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; diff --git a/keduvocdocument/keduvocwordtype.h b/keduvocdocument/keduvocwordtype.h index 99a4d5d..5b95d8d 100644 --- a/keduvocdocument/keduvocwordtype.h +++ b/keduvocdocument/keduvocwordtype.h @@ -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 m_oldMainTypeNames; - QMap 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; diff --git a/keduvocdocument/kvtmldefs.h b/keduvocdocument/kvtmldefs.h index 73f0372..ac65d19 100644 --- a/keduvocdocument/kvtmldefs.h +++ b/keduvocdocument/kvtmldefs.h @@ -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