filter: internalize shown_dives in DiveFilter class

one piece of global state removed!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-10-30 22:10:31 +01:00 committed by Dirk Hohndel
parent 51d0c42a5c
commit c53bab8965
4 changed files with 14 additions and 9 deletions

View file

@ -13,10 +13,8 @@
#include "qt-models/filtermodels.h"
#endif
int shown_dives = 0;
// Set filter status of dive and return whether it has been changed
static bool setFilterStatus(struct dive *d, bool shown)
bool DiveFilter::setFilterStatus(struct dive *d, bool shown) const
{
bool old_shown, changed;
if (!d)
@ -31,7 +29,7 @@ static bool setFilterStatus(struct dive *d, bool shown)
return changed;
}
static void updateDiveStatus(dive *d, bool newStatus, ShownChange &change)
void DiveFilter::updateDiveStatus(dive *d, bool newStatus, ShownChange &change) const
{
if (setFilterStatus(d, newStatus)) {
if (newStatus)
@ -201,6 +199,11 @@ QString DiveFilter::shownText() const
return gettextFromC::tr("%L1 dives").arg(dive_table.nr);
}
int DiveFilter::shownDives() const
{
return shown_dives;
}
void DiveFilter::setFilter(const FilterData &data)
{
filterData = data;

View file

@ -13,8 +13,6 @@ struct dive;
struct dive_trip;
struct dive_site;
extern int shown_dives;
// Structure describing changes of shown status upon applying the filter
struct ShownChange {
QVector<dive *> newShown;
@ -43,6 +41,7 @@ public:
void reset();
QString shownText() const;
int shownDives() const;
bool diveSiteMode() const; // returns true if we're filtering on dive site (on mobile always returns false)
#ifndef SUBSURFACE_MOBILE
const QVector<dive_site *> &filteredDiveSites() const;
@ -57,9 +56,12 @@ public:
private:
DiveFilter();
bool showDive(const struct dive *d) const; // Should that dive be shown?
bool setFilterStatus(struct dive *d, bool shown) const;
void updateDiveStatus(dive *d, bool newStatus, ShownChange &change) const;
QVector<dive_site *> dive_sites;
FilterData filterData;
mutable int shown_dives;
// 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