From 3cc6576913b4063b88f510f22a063aee76fa5870 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 19 Nov 2019 21:03:24 +0100 Subject: Dive list model: move filtering of trip-items to own function Implementing proper model semantics (only sending a changed signal for items that actually changed) will be somewhat complicated. Therefore, move the filtering of trip-items to its own function to make the nesting a little bit less deep. Signed-off-by: Berthold Stoeger --- qt-models/divetripmodel.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'qt-models') diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index bcdf14377..1d4a9a2a0 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -691,6 +691,17 @@ dive *DiveTripModelTree::diveOrNull(const QModelIndex &index) const return tripOrDive(index).dive; } +static bool calculateFilterForTrip(const std::vector &dives, const DiveFilter *filter) +{ + bool showTrip = false; + for (dive *d: dives) { + bool shown = filter->showDive(d); + filter_dive(d, shown); + showTrip |= shown; + } + return showTrip; +} + void DiveTripModelTree::recalculateFilter() { { @@ -710,18 +721,11 @@ void DiveTripModelTree::recalculateFilter() filter_dive(d, item.shown); } else { // Trips are shown if any of the dives is shown - bool showTrip = false; - for (dive *d: item.dives) { - bool shown = filter->showDive(d); - filter_dive(d, shown); - showTrip |= shown; - } - item.shown = showTrip; + item.shown = calculateFilterForTrip(item.dives, filter); } } } - // Rerender all trip headers. TODO: be smarter about this and only rerender if the number // of shown dives changed. for (int idx = 0; idx < (int)items.size(); ++idx) { -- cgit v1.2.3-70-g09d2