]> Git trees. - libqmvoc.git/commitdiff
Make rename and remove of usages actually work.
authorFrederik Gladhorn <gladhorn@kde.org>
Mon, 27 Aug 2007 23:07:41 +0000 (23:07 +0000)
committerFrederik Gladhorn <gladhorn@kde.org>
Mon, 27 Aug 2007 23:07:41 +0000 (23:07 +0000)
Now the lib iterates over all translations to rename/remove the label.
Since these are rather uncommon events the cost of the iteration is ok.

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

keduvocdocument/keduvocdocument.cpp
keduvocdocument/keduvocdocument.h
keduvocdocument/keduvocexpression.cpp

index 9c6398440c0959ad068b6b10f4fcfbdc070dd562..fc4acf84f5f7eac871e5fc22c812a0563e19bcfa 100644 (file)
@@ -1400,11 +1400,29 @@ void KEduVocDocument::addUsage(const QString &usage){
 
 void KEduVocDocument::renameUsage(const QString &oldName, const QString &newName){
     d->m_usages[d->m_usages.indexOf(oldName)]=newName;
+
+    for ( int i = 0; i < d->m_vocabulary.count(); i++) {
+        foreach (int translationIndex, d->m_vocabulary[i].translationIndices()) {
+            int usageIndex = d->m_vocabulary[i].translation(translationIndex).usages().indexOf(oldName);
+            if ( usageIndex >= 0 ) {
+                d->m_vocabulary[i].translation(translationIndex).usages()[usageIndex] = newName;
+            }
+        }
+    }
 }
 
 
 void KEduVocDocument::removeUsage(const QString &name){
     d->m_usages.removeAt(d->m_usages.indexOf(name));
+
+    for ( int i = 0; i < d->m_vocabulary.count(); i++) {
+        foreach (int translationIndex, d->m_vocabulary[i].translationIndices()) {
+            int usageIndex = d->m_vocabulary[i].translation(translationIndex).usages().indexOf(name);
+            if ( usageIndex >= 0 ) {
+                d->m_vocabulary[i].translation(translationIndex).usages().removeAt(usageIndex);
+            }
+        }
+    }
 }
 
 
index 572bb4410f7431ba8a286db5dd38139babb3b236..f39b42d1fe0b435eda5765caad2706ff4a95acb0 100644 (file)
@@ -338,6 +338,7 @@ public:
 
   /**
    * Rename a usage label.
+   * Actually changes the label in the vocabulary as well.
    *
    * @param oldName    old name of the usage label
    * @param newName    new name of the usage label
@@ -346,6 +347,7 @@ public:
 
   /**
    * Remove a usage label.
+   * Also removes the label from all translations.
    *
    * @param name    new name of the usage label
    */
index 13e452a63d02197e2edc0f5e0be37d2430505b7d..3d4639a758ac6a43d83a3d7c802acd02c96dddab 100644 (file)
@@ -262,3 +262,8 @@ KEduVocTranslation & KEduVocExpression::translation(int index) const
     return d->m_translations[index];
 }
 
+QList< int > KEduVocExpression::translationIndices() const
+{
+    return d->m_translations.keys();
+}
+