]> Git trees. - libqmvoc.git/commitdiff
Rewrite of everything related to usages.
authorFrederik Gladhorn <gladhorn@kde.org>
Mon, 27 Aug 2007 22:30:09 +0000 (22:30 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Mon, 27 Aug 2007 22:30:09 +0000 (22:30 +0000)
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 <usage>tags.
Removal of usage label management classes.

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

keduvocdocument/keduvocdocument.cpp
keduvocdocument/keduvocdocument.h
keduvocdocument/keduvockvtml2reader.cpp
keduvocdocument/keduvockvtml2writer.cpp
keduvocdocument/keduvockvtmlreader.cpp
keduvocdocument/keduvockvtmlwriter.cpp
keduvocdocument/keduvoctranslation.cpp
keduvocdocument/keduvoctranslation.h
keduvocdocument/kvtml2.dtd

index d27d731a05bf8221d3242759046535b6758c7d35..9f7aa05522a92bad37f7d656800c45742e4af84f 100644 (file)
@@ -83,7 +83,7 @@ public:
   QList<int>                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"
index 0c53ed6669284f82fa216ec82d28c6ccfd230c52..ebd1880ef10689249346e105194ccd0a07d4e8b8 100644 (file)
@@ -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 ***
 
index a340955e9ef8755ea2731160faf643b9e4579c37..76772bcc0cc8561d5b8ac4b551a3e2465e31ff21 100644 (file)
@@ -426,11 +426,12 @@ bool KEduVocKvtml2Reader::readTranslation(QDomElement &translationElement,
     expr.translation(index).setExample(currentElement.text());
   }
 
-  //<usage></usage>
+  //<usage></usage> 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);
   }
 
   //<paraphrase></paraphrase>
@@ -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;
 }
 
index 3307a3a64c5490b5cb8cf13a8cdbb59a5c8230d0..f06b511247cfd6f44a847567c3dad7e1f77b9c4c 100644 (file)
@@ -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
   }
 
   // <usage></usage>
-  if (!translation.usageLabel().isEmpty())
+  foreach (QString usage, translation.usages())
   {
-    translationElement.appendChild(newTextElement(KVTML_USAGE, translation.usageLabel()));
+    translationElement.appendChild(newTextElement(KVTML_USAGE, usage));
   }
 
   // <paraphrase></paraphrase>
index 0bf23df59a9952b6cbe4470bca1d0296db823298..a3fc37cf9c6a83e0d99267c4475a36953b83061f 100644 (file)
@@ -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() )
index 21dadcf7d06e424797a83e55557b750ed6d93311..4b7129db8d0b7682d24358edfe53a5fb95618d1d 100644 (file)
@@ -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;
+*/
 }
 
 
index f23f82722bface716f53581cd91d151f40b5bb45..07c1cf9703cbcdf12b8d62a229ba8ad009a9b173 100644 (file)
@@ -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;
index 45c3b51a008fa0770400eeed69f7520d678922c9..569fce4d82216b4427072ebf72526c5f98746042 100644 (file)
@@ -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
index 8c69da99bc6fb305f5a9ab049664491aa8bcfecd..72885d6a945409eda5e2870ab3d12f4ae6c5dde1 100644 (file)
@@ -57,7 +57,7 @@
 <!ELEMENT inactive       EMPTY >
 <!ELEMENT inquery        EMPTY >
 
-<!ELEMENT translation    (text, wordtype?, inquery?, comment?, pronunciation?, falsfriend?, antonym?, synonym?, example?, usage?, paraphrase?, comparison?, conjugation*) >
+<!ELEMENT translation    (text, wordtype?, inquery?, comment?, pronunciation?, falsfriend?, antonym?, synonym?, example?, usage*, paraphrase?, comparison?, conjugation*) >
 <!ELEMENT text           (#PCDATA) >
 <!ELEMENT pronunciation  (#PCDATA) >
 <!ELEMENT falsefriend    (#PCDATA) >