From 24c72cb359e98eb22418789f397bd72e0a29919b Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 26 Nov 2017 22:21:58 +0100 Subject: Inform LocationFilterModel of added dive site name If the user implicitly adds a dive site by editing a dive, and a location filter is active, check the new dive site in the location filter. This is done by informing the LocationFilterModel of the new dive site name prior to repopulation. The LocationFilterModel then adds a corresponding entry and marks it as checked. Signed-off-by: Berthold Stoeger --- qt-models/filtermodels.cpp | 14 ++++++++++++++ qt-models/filtermodels.h | 1 + 2 files changed, 15 insertions(+) (limited to 'qt-models') diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp index 568fcd9e2..07ec1a250 100644 --- a/qt-models/filtermodels.cpp +++ b/qt-models/filtermodels.cpp @@ -333,6 +333,20 @@ void LocationFilterModel::changeName(const QString &oldName, const QString &newN checkState[newIndex] = true; } +void LocationFilterModel::addName(const QString &newName) +{ + // If any item is checked and a new location is added, add the name + // of the new location in front of the list and mark it as checked. + // Thus, on subsequent repopulation of the list, the new entry will + // be registered as already checked. + QStringList list = stringList(); + if (!anyChecked || newName.isEmpty() || list.indexOf(newName) >= 0) + return; + list.prepend(newName); + setStringList(list); + checkState.insert(checkState.begin(), true); +} + MultiFilterSortModel::MultiFilterSortModel(QObject *parent) : QSortFilterProxyModel(parent), divesDisplayed(0), diff --git a/qt-models/filtermodels.h b/qt-models/filtermodels.h index 45f820984..671ac1d19 100644 --- a/qt-models/filtermodels.h +++ b/qt-models/filtermodels.h @@ -69,6 +69,7 @@ public slots: void repopulate(); void changeName(const QString &oldName, const QString &newName); + void addName(const QString &newName); private: explicit LocationFilterModel(QObject *parent = 0); -- cgit v1.2.3-70-g09d2