From 065423896dee0fe1cc6e2bd13e7e8d1b1cb3e181 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 5 May 2019 12:18:04 +0200 Subject: Filter: add reference counting for dive-site mode The dive-site-edit and dive-site-table tabs both put the filter into a special dive-site mode. When switching between both, it could happen that the one got its show befor the other got its hide event. Thus, the first would start dive-site filtering and the second stop it. Now the app was not in filter mode even though it should. To solve this problem, add reference counting for the filter's dive-site mode. In both tabs call the enter/exit functions on show/hide. In the dive-site-table tab, when the selection changes, use a set function that doesn't modify the reference count. Signed-off-by: Berthold Stoeger --- qt-models/filtermodels.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'qt-models/filtermodels.cpp') diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp index bcadce613..ce0d5ff42 100644 --- a/qt-models/filtermodels.cpp +++ b/qt-models/filtermodels.cpp @@ -105,7 +105,8 @@ MultiFilterSortModel *MultiFilterSortModel::instance() } MultiFilterSortModel::MultiFilterSortModel(QObject *parent) : QSortFilterProxyModel(parent), - divesDisplayed(0) + divesDisplayed(0), + diveSiteRefCount(0) { setFilterKeyColumn(-1); // filter all columns setFilterCaseSensitivity(Qt::CaseInsensitive); @@ -269,15 +270,24 @@ void MultiFilterSortModel::clearFilter() void MultiFilterSortModel::startFilterDiveSites(QVector ds) { dive_sites = ds; + ++diveSiteRefCount; myInvalidate(); } void MultiFilterSortModel::stopFilterDiveSites() { + if (--diveSiteRefCount > 0) + return; dive_sites.clear(); myInvalidate(); } +void MultiFilterSortModel::setFilterDiveSite(QVector ds) +{ + dive_sites = ds; + myInvalidate(); +} + const QVector &MultiFilterSortModel::filteredDiveSites() const { return dive_sites; -- cgit v1.2.3-70-g09d2