From dcc5914681e6b2fd473970bb33240c8bf5fae5f8 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Mon, 27 Aug 2007 23:07:41 +0000 Subject: [PATCH] Make rename and remove of usages actually work. 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 | 18 ++++++++++++++++++ keduvocdocument/keduvocdocument.h | 2 ++ keduvocdocument/keduvocexpression.cpp | 5 +++++ 3 files changed, 25 insertions(+) diff --git a/keduvocdocument/keduvocdocument.cpp b/keduvocdocument/keduvocdocument.cpp index 9c63984..fc4acf8 100644 --- a/keduvocdocument/keduvocdocument.cpp +++ b/keduvocdocument/keduvocdocument.cpp @@ -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); + } + } + } } diff --git a/keduvocdocument/keduvocdocument.h b/keduvocdocument/keduvocdocument.h index 572bb44..f39b42d 100644 --- a/keduvocdocument/keduvocdocument.h +++ b/keduvocdocument/keduvocdocument.h @@ -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 */ diff --git a/keduvocdocument/keduvocexpression.cpp b/keduvocdocument/keduvocexpression.cpp index 13e452a..3d4639a 100644 --- a/keduvocdocument/keduvocexpression.cpp +++ b/keduvocdocument/keduvocexpression.cpp @@ -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(); +} + -- 2.47.3