diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-02-13 23:39:44 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-02-22 15:18:31 -0800 |
commit | ee553e059d55f3376a7026a217e879f579b90e17 (patch) | |
tree | 6ee0db846caa3fb088a3cea85b03c746976c5b76 /commands | |
parent | a45c5faa8c7aab7d4263eb98d85d5e7cd589ef73 (diff) | |
download | subsurface-ee553e059d55f3376a7026a217e879f579b90e17.tar.gz |
Filter: move actual filtering loop to core/divefilter.cpp
The DiveFilter class defined the showDive() function to test
whether a dive should be filtered or not. This was used in
DiveTripModel to loop over all dives or all dives affected by
an editing action.
This restricts us in how we do filtering: We can't use indexes
that give us directly the result. To make the filtering more
flexible, move the actual loops that do the filtering to
the DiveFilter class.
The undo-commands likewise called directly the showDive()
function to check whether newly added dives are shown.
Use the new interface here as well.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/command_divelist.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/commands/command_divelist.cpp b/commands/command_divelist.cpp index eedac4b6e..908b366a6 100644 --- a/commands/command_divelist.cpp +++ b/commands/command_divelist.cpp @@ -68,11 +68,9 @@ dive *DiveListBase::addDive(DiveToAdd &d) } dive *res = d.dive.release(); // Give up ownership of dive - // Set the filter flag according to current filter settings - bool show = DiveFilter::instance()->showDive(res); - res->hidden_by_filter = !show; - if (show) - ++shown_dives; + // When we add dives, we start in hidden-by-filter status. Once all + // dives have been added, their status will be updated. + res->hidden_by_filter = true; int idx = dive_table_get_insertion_index(&dive_table, res); add_to_dive_table(&dive_table, idx, res); // Return ownership to backend @@ -185,19 +183,21 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd) [](const DiveToAdd &d, const DiveToAdd &d2) { return dive_less_than(d.dive.get(), d2.dive.get()); }); - // Remember old number of shown dives - int oldShown = shown_dives; - // Now, add the dives // Note: the idiomatic STL-way would be std::transform, but let's use a loop since // that is closer to classical C-style. auto it2 = res.rbegin(); + QVector<dive *> divesToFilter; + divesToFilter.reserve(toAdd.dives.size()); for (auto it = toAdd.dives.rbegin(); it != toAdd.dives.rend(); ++it, ++it2) { *it2 = addDive(*it); dives.push_back({ (*it2)->divetrip, *it2 }); + divesToFilter.push_back(*it2); } toAdd.dives.clear(); + ShownChange change = DiveFilter::instance()->update(divesToFilter); + // If the dives belong to new trips, add these as well. // Remember the pointers so that we can later check if a trip was newly added std::vector<dive_trip *> addedTrips; @@ -224,7 +224,7 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd) emit diveListNotifier.divesAdded(trip, createTrip, divesInTrip); }); - if (oldShown != shown_dives) + if (!change.newShown.empty() || !change.newHidden.empty()) emit diveListNotifier.numShownChanged(); return { res, sites }; |