diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-10-30 22:03:10 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-12-29 08:34:09 -0800 |
commit | 51d0c42a5c826350ba189abaf0f57ef1b35381f3 (patch) | |
tree | d7fdb9745661a78e8324d91b90b0a13dc028bdca /core | |
parent | 9e84fd935bd68ef667426d92f3c27b3aab58649a (diff) | |
download | subsurface-51d0c42a5c826350ba189abaf0f57ef1b35381f3.tar.gz |
filter: move shown_dive from divelist.c to divefilter.cpp
Arguably, the number of filtered dives is a matter of the divefilter.
Let's move it there.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/divefilter.cpp | 23 | ||||
-rw-r--r-- | core/divefilter.h | 2 | ||||
-rw-r--r-- | core/divelist.c | 17 | ||||
-rw-r--r-- | core/divelist.h | 2 |
4 files changed, 23 insertions, 21 deletions
diff --git a/core/divefilter.cpp b/core/divefilter.cpp index cdf74a49f..1af1a0b9d 100644 --- a/core/divefilter.cpp +++ b/core/divefilter.cpp @@ -1,9 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 #include "divefilter.h" -#include "divelist.h" // for filter_dive +#include "divelist.h" #include "gettextfromc.h" #include "qthelper.h" +#include "selection.h" #include "subsurface-qt/divelistnotifier.h" #if !defined(SUBSURFACE_MOBILE) && !defined(SUBSURFACE_DOWNLOADER) #include "desktop-widgets/mapwidget.h" @@ -12,9 +13,27 @@ #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 old_shown, changed; + if (!d) + return false; + old_shown = !d->hidden_by_filter; + d->hidden_by_filter = !shown; + if (!shown && d->selected) + deselect_dive(d); + changed = old_shown != shown; + if (changed) + shown_dives += shown - old_shown; + return changed; +} + static void updateDiveStatus(dive *d, bool newStatus, ShownChange &change) { - if (filter_dive(d, newStatus)) { + if (setFilterStatus(d, newStatus)) { if (newStatus) change.newShown.push_back(d); else diff --git a/core/divefilter.h b/core/divefilter.h index 84c9efee2..d4342871b 100644 --- a/core/divefilter.h +++ b/core/divefilter.h @@ -13,6 +13,8 @@ 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; diff --git a/core/divelist.c b/core/divelist.c index 9e67e55c2..c68ba2b79 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -786,22 +786,6 @@ void delete_single_dive(int idx) delete_dive_from_table(&dive_table, idx); } -int shown_dives = 0; -bool filter_dive(struct dive *d, bool shown) -{ - bool old_shown, changed; - if (!d) - return false; - old_shown = !d->hidden_by_filter; - d->hidden_by_filter = !shown; - if (!shown && d->selected) - deselect_dive(d); - changed = old_shown != shown; - if (changed) - shown_dives += shown - old_shown; - return changed; -} - void process_loaded_dives() { int i; @@ -1375,7 +1359,6 @@ void clear_dive_file_data() while (dive_table.nr) delete_single_dive(0); current_dive = NULL; - shown_dives = 0; while (dive_site_table.nr) delete_dive_site(get_dive_site(0, &dive_site_table), &dive_site_table); if (trip_table.nr != 0) { diff --git a/core/divelist.h b/core/divelist.h index 8f58cda69..1a19a3e2a 100644 --- a/core/divelist.h +++ b/core/divelist.h @@ -13,7 +13,6 @@ struct trip_table; struct dive_site_table; struct device_table; struct deco_state; -extern int shown_dives; struct dive_table { int nr, allocated; @@ -53,7 +52,6 @@ extern void insert_dive(struct dive_table *table, struct dive *d); extern void get_dive_gas(const struct dive *dive, int *o2_p, int *he_p, int *o2low_p); extern int get_divenr(const struct dive *dive); extern int remove_dive(const struct dive *dive, struct dive_table *table); -extern bool filter_dive(struct dive *d, bool shown); /* returns true if status changed */ extern int get_dive_nr_at_idx(int idx); extern void set_dive_nr_for_current_dive(); extern timestamp_t get_surface_interval(timestamp_t when); |