From 51d0c42a5c826350ba189abaf0f57ef1b35381f3 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 30 Oct 2020 22:03:10 +0100 Subject: [PATCH] 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 --- core/divefilter.cpp | 23 +++++++++++++++++++++-- core/divefilter.h | 2 ++ core/divelist.c | 17 ----------------- core/divelist.h | 2 -- qt-models/mobilelistmodel.cpp | 2 +- 5 files changed, 24 insertions(+), 22 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 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); diff --git a/qt-models/mobilelistmodel.cpp b/qt-models/mobilelistmodel.cpp index cf1db1860..f660af2e6 100644 --- a/qt-models/mobilelistmodel.cpp +++ b/qt-models/mobilelistmodel.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "mobilelistmodel.h" -#include "core/divelist.h" // for shown_dives +#include "core/divefilter.h" // for shown_dives MobileListModelBase::MobileListModelBase(DiveTripModelBase *sourceIn) : source(sourceIn) {