From c7e31ed4a539ad54af432e1f036c9bea190a2848 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Mon, 27 Aug 2007 22:30:09 +0000 Subject: [PATCH] Rewrite of everything related to usages. A usage is now simply a QStringList. Translations can contain as many usage QStrings as they want (also QStringList). Another dtd update: A translation can contain multiple tags. Removal of usage label management classes. svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=705421 --- keduvocdocument/keduvocdocument.cpp | 63 ++++++++++++------------- keduvocdocument/keduvocdocument.h | 32 ++++--------- keduvocdocument/keduvockvtml2reader.cpp | 10 ++-- keduvocdocument/keduvockvtml2writer.cpp | 11 ++--- keduvocdocument/keduvockvtmlreader.cpp | 11 +++-- keduvocdocument/keduvockvtmlwriter.cpp | 13 +++-- keduvocdocument/keduvoctranslation.cpp | 18 +++---- keduvocdocument/keduvoctranslation.h | 14 +++--- keduvocdocument/kvtml2.dtd | 2 +- 9 files changed, 85 insertions(+), 89 deletions(-) diff --git a/keduvocdocument/keduvocdocument.cpp b/keduvocdocument/keduvocdocument.cpp index d27d731..9f7aa05 100644 --- a/keduvocdocument/keduvocdocument.cpp +++ b/keduvocdocument/keduvocdocument.cpp @@ -83,7 +83,7 @@ public: QList m_lessonsInQuery; QStringList m_tenseDescriptions; - QStringList m_usageDescriptions; + QStringList m_usages; QString m_title; QString m_author; QString m_license; @@ -680,37 +680,6 @@ void KEduVocDocument::setTenseDescriptions(const QStringList &names) } -QString KEduVocDocument::usageName(int index) const -{ - if (index >= d->m_usageDescriptions.size()) - return ""; - else - return d->m_usageDescriptions[index]; -} - - -void KEduVocDocument::setUsageName(int idx, QString &id) -{ - if (idx >= d->m_usageDescriptions.size()) - for (int i = d->m_usageDescriptions.size(); i <= idx; i++) - d->m_usageDescriptions.append (""); - - d->m_usageDescriptions[idx] = id; -} - - -QStringList KEduVocDocument::usageDescriptions() const -{ - return d->m_usageDescriptions; -} - - -void KEduVocDocument::setUsageDescriptions(const QStringList &names) -{ - d->m_usageDescriptions = names; -} - - void KEduVocDocument::setConjugation(int idx, const KEduVocConjugation &con) { if ( idx < 0) return; @@ -1411,4 +1380,34 @@ KEduVocWordType* KEduVocDocument::wordTypes() { return d->m_wordTypes; } + +QStringList KEduVocDocument::usages(){ + return d->m_usages; +} + + +/* +void KEduVocDocument::setUsageDescriptions(const QStringList &names) +{ + d->m_usageDescriptions = names; +}*/ + + +void KEduVocDocument::addUsage(const QString &usage){ + d->m_usages.append(usage); +} + + +QString KEduVocDocument::renameUsage(const QString &oldName, const QString &newName){ + d->m_usages[d->m_usages.indexOf(oldName)]=newName; +} + + +void KEduVocDocument::removeUsage(const QString &name){ + d->m_usages.removeAt(d->m_usages.indexOf(name)); +} + + + + #include "keduvocdocument.moc" diff --git a/keduvocdocument/keduvocdocument.h b/keduvocdocument/keduvocdocument.h index 0c53ed6..ebd1880 100644 --- a/keduvocdocument/keduvocdocument.h +++ b/keduvocdocument/keduvocdocument.h @@ -322,33 +322,21 @@ public: // *** usage methods *** - /** - * Sets usage string - * - * @param index number of usage - * @param str name of usage - */ - void setUsageName(int index, QString &str); - - /** - * Returns usage string - * - * @param index number of usage - * @returns string - */ - QString usageName(int index) const; - - /** - * Sets the descriptions of the usages - */ - void setUsageDescriptions(const QStringList &names); - /** * Gets the descriptions of the usages. * Usages are context information in a dictionary you may find [biol.] * [am.] and the like to hint at the context in which the word is usually used. */ - QStringList usageDescriptions() const; + QStringList usages(); + + + void addUsage(const QString &usage); + + + QString renameUsage(const QString &oldName, const QString &newName); + + + void removeUsage(const QString &name); // *** grade methods *** diff --git a/keduvocdocument/keduvockvtml2reader.cpp b/keduvocdocument/keduvockvtml2reader.cpp index a340955..76772bc 100644 --- a/keduvocdocument/keduvockvtml2reader.cpp +++ b/keduvocdocument/keduvockvtml2reader.cpp @@ -426,11 +426,12 @@ bool KEduVocKvtml2Reader::readTranslation(QDomElement &translationElement, expr.translation(index).setExample(currentElement.text()); } - // + // can be as often as there are usage labels currentElement = translationElement.firstChildElement(KVTML_USAGE); - if (!currentElement.isNull()) + while (!currentElement.isNull()) { - expr.translation(index).setUsageLabel(currentElement.text()); + expr.translation(index).usages().append(currentElement.text()); + currentElement = currentElement.nextSiblingElement(KVTML_USAGE); } // @@ -882,11 +883,10 @@ bool KEduVocKvtml2Reader::readUsages(QDomElement &usagesElement) QDomElement currentElement = usageNodes.item(i).toElement(); if (currentElement.parentNode() == usagesElement) { - usages.append(currentElement.text()); + m_doc->addUsage(currentElement.text()); } } - m_doc->setUsageDescriptions(usages); return true; } diff --git a/keduvocdocument/keduvockvtml2writer.cpp b/keduvocdocument/keduvockvtml2writer.cpp index 3307a3a..f06b511 100644 --- a/keduvocdocument/keduvockvtml2writer.cpp +++ b/keduvocdocument/keduvockvtml2writer.cpp @@ -550,12 +550,9 @@ bool KEduVocKvtml2Writer::writeTenses(QDomElement &tensesElement) bool KEduVocKvtml2Writer::writeUsages(QDomElement &usagesElement) { - foreach(QString usage, m_doc->usageDescriptions()) + foreach(QString usage, m_doc->usages()) { - if (!(usage.isNull())) - { - usagesElement.appendChild(newTextElement(KVTML_USAGE, usage)); - } + usagesElement.appendChild(newTextElement(KVTML_USAGE, usage)); } return true; @@ -666,9 +663,9 @@ bool KEduVocKvtml2Writer::writeTranslation(QDomElement &translationElement, KEdu } // - if (!translation.usageLabel().isEmpty()) + foreach (QString usage, translation.usages()) { - translationElement.appendChild(newTextElement(KVTML_USAGE, translation.usageLabel())); + translationElement.appendChild(newTextElement(KVTML_USAGE, usage)); } // diff --git a/keduvocdocument/keduvockvtmlreader.cpp b/keduvocdocument/keduvockvtmlreader.cpp index 0bf23df..a3fc37c 100644 --- a/keduvocdocument/keduvockvtmlreader.cpp +++ b/keduvocdocument/keduvockvtmlreader.cpp @@ -690,7 +690,6 @@ bool KEduVocKvtmlReader::readUsage(QDomElement &domElementParent) if (entryList.length() <= 0) return false; - descriptions.clear(); for (int i = 0; i < entryList.count(); ++i) { currentElement = entryList.item(i).toElement(); @@ -704,11 +703,10 @@ bool KEduVocKvtmlReader::readUsage(QDomElement &domElementParent) s = currentElement.text(); if (s.isNull()) s = ""; - descriptions.append(s); + m_doc->addUsage(s); } } - m_doc->setUsageDescriptions(descriptions); return true; } @@ -929,6 +927,8 @@ bool KEduVocKvtmlReader::readExpressionChildAttributes( QDomElement &domElementE if (!attribute.isNull()) example = attribute.value(); +///@todo usages +/* usage = ""; attribute = domElementExpressionChild.attributeNode(KV_USAGE); if (!attribute.isNull()) @@ -951,7 +951,7 @@ bool KEduVocKvtmlReader::readExpressionChildAttributes( QDomElement &domElementE m_doc->setUsageDescriptions(sl); } } - } + }*/ paraphrase = ""; attribute = domElementExpressionChild.attributeNode(KV_PARAPHRASE); @@ -1257,8 +1257,11 @@ bool KEduVocKvtmlReader::readExpression(QDomElement &domElementParent) expr.translation(i).setSynonym (synonym); if (!example.isEmpty() ) expr.translation(i).setExample (example); +///@todo enable reading of usages into a qstringlist +/* if (!usage.isEmpty() ) expr.translation(i).setUsageLabel (usage); +*/ if (!paraphrase.isEmpty() ) expr.translation(i).setParaphrase (paraphrase); if (!antonym.isEmpty() ) diff --git a/keduvocdocument/keduvockvtmlwriter.cpp b/keduvocdocument/keduvockvtmlwriter.cpp index 21dadcf..4b7129d 100644 --- a/keduvocdocument/keduvockvtmlwriter.cpp +++ b/keduvocdocument/keduvockvtmlwriter.cpp @@ -148,10 +148,11 @@ bool KEduVocKvtmlWriter::writeDoc(KEduVocDocument *doc, const QString &generator if (!entry->translation(0).example().isEmpty() ) domElementOriginal.setAttribute(KV_EXAMPLE, entry->translation(0).example()); - +///@todo enable writing of usages into a qstringlist +/* if (!entry->translation(0).usageLabel().isEmpty() ) domElementOriginal.setAttribute(KV_USAGE, entry->translation(0).usageLabel()); - +*/ if (!entry->translation(0).paraphrase().isEmpty() ) domElementOriginal.setAttribute(KV_PARAPHRASE, entry->translation(0).paraphrase()); @@ -242,9 +243,11 @@ bool KEduVocKvtmlWriter::writeDoc(KEduVocDocument *doc, const QString &generator if (!entry->translation(trans).example().isEmpty() ) domElementTranslation.setAttribute(KV_EXAMPLE, entry->translation(trans).example()); +///@todo enable writing of usages in old format +/* if (!entry->translation(trans).usageLabel().isEmpty() ) domElementTranslation.setAttribute(KV_USAGE, entry->translation(trans).usageLabel()); - +*/ if (!entry->translation(trans).paraphrase().isEmpty() ) domElementTranslation.setAttribute(KV_PARAPHRASE, entry->translation(trans).paraphrase()); @@ -508,6 +511,9 @@ bool KEduVocKvtmlWriter::writeTense(QDomDocument &domDoc, QDomElement &domElemen bool KEduVocKvtmlWriter::writeUsage(QDomDocument &domDoc, QDomElement &domElementParent) { + +///@todo usages +/* if (m_doc->usageDescriptions().count() == 0) return true; @@ -530,6 +536,7 @@ bool KEduVocKvtmlWriter::writeUsage(QDomDocument &domDoc, QDomElement &domElemen domElementParent.appendChild(domElementUsage); return true; +*/ } diff --git a/keduvocdocument/keduvoctranslation.cpp b/keduvocdocument/keduvoctranslation.cpp index f23f827..07c1cf9 100644 --- a/keduvocdocument/keduvoctranslation.cpp +++ b/keduvocdocument/keduvoctranslation.cpp @@ -44,7 +44,7 @@ public: /// noun:male etc (language dependent) QString m_type; QString m_subType; - QString m_usageLabel; + QStringList m_usages; QString m_comment; QString m_paraphrase; QString m_synonym; @@ -82,7 +82,7 @@ bool KEduVocTranslation::KEduVocTranslationPrivate::operator== ( const KEduVocTr return m_translation == other.m_translation && m_type == other.m_type && m_subType == other.m_subType && - m_usageLabel == other.m_usageLabel && + m_usages == other.m_usages && m_comment == other.m_comment && m_paraphrase == other.m_paraphrase && m_synonym == other.m_synonym && @@ -114,7 +114,7 @@ KEduVocTranslation::KEduVocTranslation( const KEduVocTranslation &other) : d ( n d->m_translation = other.d->m_translation; d->m_type = other.d->m_type; d->m_subType = other.d->m_subType; - d->m_usageLabel = other.d->m_usageLabel; + d->m_usages = other.d->m_usages; d->m_comment = other.d->m_comment; d->m_paraphrase = other.d->m_paraphrase; d->m_synonym = other.d->m_synonym; @@ -198,15 +198,15 @@ QString KEduVocTranslation::example ( ) const } -void KEduVocTranslation::setUsageLabel ( const QString & usage ) +void KEduVocTranslation::setUsages ( const QStringList & usages ) { - d->m_usageLabel = usage; + d->m_usages = usages; } -QString KEduVocTranslation::usageLabel () const +QStringList& KEduVocTranslation::usages () { - return d->m_usageLabel; + return d->m_usages; } @@ -319,7 +319,7 @@ bool KEduVocTranslation::operator ==(const KEduVocTranslation & translation) con return d->m_translation == translation.d->m_translation && d->m_type == translation.d->m_type && d->m_subType == translation.d->m_subType && - d->m_usageLabel == translation.d->m_usageLabel && + d->m_usages == translation.d->m_usages && d->m_comment == translation.d->m_comment && d->m_paraphrase == translation.d->m_paraphrase && d->m_synonym == translation.d->m_synonym && @@ -340,7 +340,7 @@ KEduVocTranslation & KEduVocTranslation::operator =(const KEduVocTranslation & t d->m_translation = translation.d->m_translation; d->m_type = translation.d->m_type; d->m_subType = translation.d->m_subType; - d->m_usageLabel = translation.d->m_usageLabel; + d->m_usages = translation.d->m_usages; d->m_comment = translation.d->m_comment; d->m_paraphrase = translation.d->m_paraphrase; d->m_synonym = translation.d->m_synonym; diff --git a/keduvocdocument/keduvoctranslation.h b/keduvocdocument/keduvoctranslation.h index 45c3b51..569fce4 100644 --- a/keduvocdocument/keduvoctranslation.h +++ b/keduvocdocument/keduvoctranslation.h @@ -116,15 +116,17 @@ public: */ QString example() const; - /** sets usage label this expression - * @param usage usage label of this index + + /** sets usages this expression + * @param usage usage labels of this index */ - void setUsageLabel( const QString & usage); + void setUsages( const QStringList & usage); + - /** returns usage label of this expression - * @return usage or "" if no string available + /** returns usages of this expression + * @return usages */ - QString usageLabel() const; + QStringList& usages(); /** sets paraphrase of this expression * @param expression paraphrase of this index diff --git a/keduvocdocument/kvtml2.dtd b/keduvocdocument/kvtml2.dtd index 8c69da9..72885d6 100644 --- a/keduvocdocument/kvtml2.dtd +++ b/keduvocdocument/kvtml2.dtd @@ -57,7 +57,7 @@ - + -- 2.47.3