From 9e84fd935bd68ef667426d92f3c27b3aab58649a Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 30 Oct 2020 21:46:01 +0100 Subject: [PATCH] filter: keep track on shown_dive on dive removal in DiveFilter When removing dives, the UndoCommands would keep track of the shown dives. When adding, they were calling into the filter instead. Let's remove this asymmetry. Signed-off-by: Berthold Stoeger --- commands/command_divelist.cpp | 3 +-- core/divefilter.cpp | 6 ++++++ core/divefilter.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/commands/command_divelist.cpp b/commands/command_divelist.cpp index 262197214..36d4cdcf3 100644 --- a/commands/command_divelist.cpp +++ b/commands/command_divelist.cpp @@ -48,8 +48,7 @@ DiveToAdd DiveListBase::removeDive(struct dive *d, std::vector &t if (idx < 0) qWarning("Deletion of unknown dive!"); - if (!d->hidden_by_filter) - --shown_dives; + DiveFilter::instance()->diveRemoved(d); res.dive.reset(unregister_dive(idx)); // Remove dive from backend diff --git a/core/divefilter.cpp b/core/divefilter.cpp index 4c40869f5..cdf74a49f 100644 --- a/core/divefilter.cpp +++ b/core/divefilter.cpp @@ -101,6 +101,12 @@ DiveFilter::DiveFilter() : diveSiteRefCount(0) { } +void DiveFilter::diveRemoved(const dive *d) const +{ + if (!d->hidden_by_filter) + --shown_dives; +} + bool DiveFilter::showDive(const struct dive *d) const { if (d->invalid && !prefs.display_invalid_dives) diff --git a/core/divefilter.h b/core/divefilter.h index 608cf4843..84c9efee2 100644 --- a/core/divefilter.h +++ b/core/divefilter.h @@ -51,6 +51,7 @@ public: void setFilter(const FilterData &data); ShownChange update(const QVector &dives) const; // Update filter status of given dives and return dives whose status changed ShownChange updateAll() const; // Update filter status of all dives and return dives whose status changed + void diveRemoved(const dive *dive) const; // Dive was removed; update count accordingly private: DiveFilter(); bool showDive(const struct dive *d) const; // Should that dive be shown?