summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-05-05 12:30:54 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-05-11 12:06:19 -0700
commit83926213ea7a97624ae5b52ac0979d5075855c50 (patch)
tree910f8abde9ada8251a7a32814c468f68c1cdd7da
parent065423896dee0fe1cc6e2bd13e7e8d1b1cb3e181 (diff)
downloadsubsurface-83926213ea7a97624ae5b52ac0979d5075855c50.tar.gz
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 <bstoeger@mail.tuwien.ac.at>
-rw-r--r--qt-models/filtermodels.cpp16
1 files changed, 13 insertions, 3 deletions
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<dive_site *> 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<dive_site *> 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<dive_site *> &MultiFilterSortModel::filteredDiveSites() const
bool MultiFilterSortModel::diveSiteMode() const
{
- return !dive_sites.isEmpty();
+ return diveSiteRefCount > 0;
}
bool MultiFilterSortModel::lessThan(const QModelIndex &i1, const QModelIndex &i2) const