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>
This commit is contained in:
Berthold Stoeger 2019-11-19 21:03:24 +01:00 committed by bstoeger
parent 569e532f5c
commit 3cc6576913

View file

@ -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) {