aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-11-19 21:03:24 +0100
committerGravatar bstoeger <32835590+bstoeger@users.noreply.github.com>2019-12-04 13:00:23 +0100
commit3cc6576913b4063b88f510f22a063aee76fa5870 (patch)
treecf623b208fe39b7940cc540c741b14447d008090
parent569e532f5c63f25abb81eec92937caec20f38d77 (diff)
downloadsubsurface-3cc6576913b4063b88f510f22a063aee76fa5870.tar.gz
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 <bstoeger@mail.tuwien.ac.at>
-rw-r--r--qt-models/divetripmodel.cpp20
1 files changed, 12 insertions, 8 deletions
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<dive *> &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) {