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 /qt-models/divetripmodel.cpp | |
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 'qt-models/divetripmodel.cpp')
-rw-r--r-- | qt-models/divetripmodel.cpp | 31 |
1 files changed, 2 insertions, 29 deletions
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index e3b8266cf..ce4206cfb 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -432,41 +432,18 @@ bool DiveTripModelBase::setData(const QModelIndex &index, const QVariant &value, return true; } -// Structure describing changes of shown status -struct ShownChange { - QVector<dive *> newShown; - QVector<dive *> newHidden; - bool currentChanged; - void filterDive(dive *d, const DiveFilter *filter); -}; - -void ShownChange::filterDive(dive *d, const DiveFilter *filter) -{ - bool newStatus = filter->showDive(d); - if (filter_dive(d, newStatus)) { - if (newStatus) - newShown.push_back(d); - else - newHidden.push_back(d); - } -} - // Update visibility status of dive and return dives whose visibility changed. // Attention: the changed dives are removed from the original vector! static ShownChange updateShown(QVector<dive *> &dives) { DiveFilter *filter = DiveFilter::instance(); - dive *old_current = current_dive; - ShownChange res; - for (dive *d: dives) - res.filterDive(d, filter); + ShownChange res = filter->update(dives); if (!res.newShown.empty() || !res.newHidden.empty()) emit diveListNotifier.numShownChanged(); for (dive *d: res.newHidden) dives.removeAll(d); for (dive *d: res.newShown) dives.removeAll(d); - res.currentChanged = old_current != current_dive; return res; } @@ -474,13 +451,9 @@ static ShownChange updateShown(QVector<dive *> &dives) static ShownChange updateShownAll() { DiveFilter *filter = DiveFilter::instance(); - dive *old_current = current_dive; - ShownChange res; - for (int i = 0; i < dive_table.nr; ++i) - res.filterDive(get_dive(i), filter); + ShownChange res = filter->updateAll(); if (!res.newShown.empty() || !res.newHidden.empty()) emit diveListNotifier.numShownChanged(); - res.currentChanged = old_current != current_dive; return res; } |