summaryrefslogtreecommitdiffstats
path: root/qt-models/filtermodels.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2017-11-26 10:42:22 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-11-26 18:50:40 -0800
commitf4bcdf46aa6498c449be8f63c052a7cbeaf8baa6 (patch)
treec13dce16fce00b4ee383e073aa0765bacd5bf99f /qt-models/filtermodels.cpp
parent2a0520d57d18d9e188d7633b0d39506b36e196ac (diff)
downloadsubsurface-f4bcdf46aa6498c449be8f63c052a7cbeaf8baa6.tar.gz
Inform LocationFilterModel of changed dive site name
Since commit 01d961086c1d175732c597dc9acdba7cc4cd2d26, the location filter list is updated if a dive site is edited. The problem is that if the name of a selected dive site is changed, the selection is lost. Therefore, before repopulating, inform the location filter that a dive site changed its name. The location filter then internally changes the name and can properly transfer the old selection on repopulate. This is performed via the new LocationInformationWidget::nameChanged signal, which is connected to the new LocationFilterModel::changeName slot. A special case to be handled is the following: [ ] Site 1 [x] Site 2 and "Site 2" being renamed to "Site 1", i.e. both sites being merged. Here, the merging is detected and "Site 1" will likewise be checked: [x] Site 1 [x] Site 1 No merging is performed, as the list will be repopulated anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/filtermodels.cpp')
-rw-r--r--qt-models/filtermodels.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp
index 51587edc8..568fcd9e2 100644
--- a/qt-models/filtermodels.cpp
+++ b/qt-models/filtermodels.cpp
@@ -315,6 +315,24 @@ void LocationFilterModel::repopulate()
updateList(list);
}
+void LocationFilterModel::changeName(const QString &oldName, const QString &newName)
+{
+ if (oldName.isEmpty() || newName.isEmpty() || oldName == newName)
+ return;
+ QStringList list = stringList();
+ int oldIndex = list.indexOf(oldName);
+ if (oldIndex < 0)
+ return;
+ int newIndex = list.indexOf(newName);
+ list[oldIndex] = newName;
+ setStringList(list);
+
+ // If there was already an entry with the new name, we are merging entries.
+ // Thus, if the old entry was selected, also select the new entry.
+ if (newIndex >= 0 && checkState[oldIndex])
+ checkState[newIndex] = true;
+}
+
MultiFilterSortModel::MultiFilterSortModel(QObject *parent) :
QSortFilterProxyModel(parent),
divesDisplayed(0),