mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-27 20:58:47 +00:00
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:
parent
51d0c42a5c
commit
c53bab8965
4 changed files with 14 additions and 9 deletions
|
@ -130,7 +130,7 @@ DivesAndTripsToAdd DiveListBase::removeDives(DivesAndSitesToRemove &divesAndSite
|
|||
sitesToAdd.reserve(divesAndSitesToDelete.sites.size());
|
||||
|
||||
// Remember old number of shown dives
|
||||
int oldShown = shown_dives;
|
||||
int oldShown = DiveFilter::instance()->shownDives();
|
||||
|
||||
// Make sure that the dive list is sorted. The added dives will be sent in a signal
|
||||
// and the recipients assume that the dives are sorted the same way as they are
|
||||
|
@ -164,7 +164,7 @@ DivesAndTripsToAdd DiveListBase::removeDives(DivesAndSitesToRemove &divesAndSite
|
|||
emit diveListNotifier.divesDeleted(trip, deleteTrip, divesInTrip);
|
||||
});
|
||||
|
||||
if (oldShown != shown_dives)
|
||||
if (oldShown != DiveFilter::instance()->shownDives())
|
||||
emit diveListNotifier.numShownChanged();
|
||||
|
||||
return { std::move(divesToAdd), std::move(tripsToAdd), std::move(sitesToAdd) };
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -58,7 +58,7 @@ QHash<int, QByteArray> MobileListModelBase::roleNames() const
|
|||
|
||||
int MobileListModel::shown() const
|
||||
{
|
||||
return shown_dives;
|
||||
return DiveFilter::instance()->shownDives();
|
||||
}
|
||||
|
||||
int MobileListModelBase::columnCount(const QModelIndex &parent) const
|
||||
|
|
Loading…
Reference in a new issue