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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-05-05 12:18:04 +02:00 committed by Dirk Hohndel
parent cd5489e08d
commit 065423896d
4 changed files with 29 additions and 4 deletions

View file

@ -70,6 +70,7 @@ slots:
void myInvalidate();
void clearFilter();
void startFilterDiveSites(QVector<dive_site *> ds);
void setFilterDiveSite(QVector<dive_site *> ds);
void stopFilterDiveSites();
void filterChanged(const QModelIndex &from, const QModelIndex &to, const QVector<int> &roles);
void resetModel(DiveTripModelBase::Layout layout);
@ -86,6 +87,14 @@ private:
QVector<dive_site *> dive_sites;
void countsChanged();
FilterData filterData;
// We use ref-counting for the dive site mode. The reason is that when switching
// between two tabs that both need dive site mode, the following course of
// events may happen:
// 1) The new tab appears -> enter dive site mode.
// 2) The old tab gets its hide() signal -> exit dive site mode.
// The filter is now not in dive site mode, even if it should
int diveSiteRefCount;
};
#endif