From 83926213ea7a97624ae5b52ac0979d5075855c50 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 5 May 2019 12:30:54 +0200 Subject: Filter: don't reload when dive sites are set to the same value When switching between the dive-site-table to the dive-site-edit tabs, the filter would be set to a dive site. Usually, this would be the same dive site as before. Nevertheless, this caused a full map-reload. Detect if the dive-sites to be filtered are the same and turn this operation into a no-op. Signed-off-by: Berthold Stoeger --- qt-models/filtermodels.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'qt-models/filtermodels.cpp') diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp index ce0d5ff42..331439bb4 100644 --- a/qt-models/filtermodels.cpp +++ b/qt-models/filtermodels.cpp @@ -270,8 +270,13 @@ void MultiFilterSortModel::clearFilter() void MultiFilterSortModel::startFilterDiveSites(QVector ds) { dive_sites = ds; - ++diveSiteRefCount; - myInvalidate(); + if (++diveSiteRefCount > 1) { + setFilterDiveSite(ds); + } else { + std::sort(ds.begin(), ds.end()); + dive_sites = ds; + myInvalidate(); + } } void MultiFilterSortModel::stopFilterDiveSites() @@ -284,6 +289,11 @@ void MultiFilterSortModel::stopFilterDiveSites() void MultiFilterSortModel::setFilterDiveSite(QVector ds) { + // If the filter didn't change, return early to avoid a full + // map reload. For a well-defined comparison, sort the vector first. + std::sort(ds.begin(), ds.end()); + if (ds == dive_sites) + return; dive_sites = ds; myInvalidate(); } @@ -295,7 +305,7 @@ const QVector &MultiFilterSortModel::filteredDiveSites() const bool MultiFilterSortModel::diveSiteMode() const { - return !dive_sites.isEmpty(); + return diveSiteRefCount > 0; } bool MultiFilterSortModel::lessThan(const QModelIndex &i1, const QModelIndex &i2) const -- cgit v1.2.3-70-g09d2