Move some definitons into kvtmldefs.h from reader and writer.
svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=704797
QString m_querytrans;
QList<KEduVocExpression> m_vocabulary;
QList<int> m_lessonsInQuery;
- //QStringList m_lessonDescriptions;
-
- QStringList m_typeDescriptions;
QStringList m_tenseDescriptions;
QStringList m_usageDescriptions;
{
m_lessons.clear();
m_articles.clear();
- m_typeDescriptions.clear();
m_tenseDescriptions.clear();
m_identifiers.clear();
m_sortIdentifier.clear();
}
-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())
// *** 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 ***
#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)
#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)
{
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;
}
QString &pronunciation,
int &width,
QString &type,
+ QString &subType,
QString &faux_ami_f,
QString &faux_ami_t,
QString &synonym,
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);
int lesson = 0;
int width;
QString type;
+ QString subType;
QString faux_ami_f;
QString faux_ami_t;
QString synonym;
// 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;
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'
// 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)
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() )
{
m_doc->lesson(lesson)->addEntry(m_doc->entryCount());
}
-
+
return true;
}
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
QString &pronunciation,
int &width,
QString &type,
+ QString &subType,
QString &faux_ami_f,
QString &faux_ami_t,
QString &synonym,
QString m_errorMessage;
int m_cols;
int m_lines;
+ QStringList m_oldSelfDefinedTypes;
};
#endif
bool KEduVocKvtmlWriter::writeType(QDomDocument &domDoc, QDomElement &domElementParent)
{
+/** @todo port to new type handling
if (m_doc->typeDescriptions().count() == 0)
return true;
}
domElementParent.appendChild(domElementType);
+*/
return true;
}
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
*/
/// Map containing the word type name and its properties.
QList<wordType> m_wordTypeList;
+
+ QMap<QString, QString> m_oldMainTypeNames;
+ QMap<QString, QString> m_oldSubTypeNames;
};
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()
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;
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;
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"));
}
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() ) {
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;
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;
/// 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;
#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