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>
This commit is contained in:
Berthold Stoeger 2019-05-05 12:30:54 +02:00 committed by Dirk Hohndel
parent 065423896d
commit 83926213ea

View file

@ -270,8 +270,13 @@ void MultiFilterSortModel::clearFilter()
void MultiFilterSortModel::startFilterDiveSites(QVector<dive_site *> ds) void MultiFilterSortModel::startFilterDiveSites(QVector<dive_site *> ds)
{ {
dive_sites = ds; dive_sites = ds;
++diveSiteRefCount; if (++diveSiteRefCount > 1) {
myInvalidate(); setFilterDiveSite(ds);
} else {
std::sort(ds.begin(), ds.end());
dive_sites = ds;
myInvalidate();
}
} }
void MultiFilterSortModel::stopFilterDiveSites() void MultiFilterSortModel::stopFilterDiveSites()
@ -284,6 +289,11 @@ void MultiFilterSortModel::stopFilterDiveSites()
void MultiFilterSortModel::setFilterDiveSite(QVector<dive_site *> ds) 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; dive_sites = ds;
myInvalidate(); myInvalidate();
} }
@ -295,7 +305,7 @@ const QVector<dive_site *> &MultiFilterSortModel::filteredDiveSites() const
bool MultiFilterSortModel::diveSiteMode() const bool MultiFilterSortModel::diveSiteMode() const
{ {
return !dive_sites.isEmpty(); return diveSiteRefCount > 0;
} }
bool MultiFilterSortModel::lessThan(const QModelIndex &i1, const QModelIndex &i2) const bool MultiFilterSortModel::lessThan(const QModelIndex &i1, const QModelIndex &i2) const