diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-11-19 21:54:18 +0100 |
---|---|---|
committer | bstoeger <32835590+bstoeger@users.noreply.github.com> | 2019-12-04 13:00:23 +0100 |
commit | c54e58e078f656222478ba62d736967fb1370cc8 (patch) | |
tree | d1bcfeeb8baa14022da06ca9acc886d1e842b4d5 /qt-models | |
parent | 4ca65894c842a042b0d21a5449355be475f6fe7c (diff) | |
download | subsurface-c54e58e078f656222478ba62d736967fb1370cc8.tar.gz |
Dive trip model: send changed signals for top-level items
Send signals if the shown-status of top level items changed.
Do this in two passes to be able to use the previously created
function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r-- | qt-models/divetripmodel.cpp | 15 | ||||
-rw-r--r-- | qt-models/divetripmodel.h | 2 |
2 files changed, 15 insertions, 2 deletions
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index 55ba37a5c..5ecee7855 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -714,7 +714,7 @@ void DiveTripModelBase::sendShownChangedSignals(const std::vector<char> &changed // which will then be hidden and all the dives will be hidden implicitly as well. // Thus, do this in two passes: collect changed dives and only if any dive is visible, // send the signals. -bool DiveTripModelTree::calculateFilterForTrip(const std::vector<dive *> &dives, const DiveFilter *filter, int parentIndex) +bool DiveTripModelTree::calculateFilterForTrip(const std::vector<dive *> &dives, const DiveFilter *filter, quintptr parentIndex) { bool showTrip = false; std::vector<char> changed; @@ -733,6 +733,13 @@ bool DiveTripModelTree::calculateFilterForTrip(const std::vector<dive *> &dives, void DiveTripModelTree::recalculateFilter() { + // Collect the changes in a vector used later to send signals. + // This could be solved more efficiently in one pass, but + // doing it in two passes allows us to use a common function without + // resorting to co-routines, lambdas or similar techniques. + std::vector<char> changed; + changed.reserve(items.size()); + { // This marker prevents the UI from getting notifications on selection changes. // It is active until the end of the scope. @@ -743,8 +750,10 @@ void DiveTripModelTree::recalculateFilter() // as a consequence of the filterReset signal right after the local scope. auto marker = diveListNotifier.enterCommand(); DiveFilter *filter = DiveFilter::instance(); + for (size_t i = 0; i < items.size(); ++i) { Item &item = items[i]; + bool oldShown = item.shown; if (item.d_or_t.dive) { dive *d = item.d_or_t.dive; item.shown = filter->showDive(item.d_or_t.dive); @@ -753,9 +762,13 @@ void DiveTripModelTree::recalculateFilter() // Trips are shown if any of the dives is shown item.shown = calculateFilterForTrip(item.dives, filter, i); } + changed.push_back(item.shown != oldShown); } } + // Send the data-changed signals if some items changed visibility. + sendShownChangedSignals(changed, noParent); + // 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) { diff --git a/qt-models/divetripmodel.h b/qt-models/divetripmodel.h index 5952fa558..9ed2189a0 100644 --- a/qt-models/divetripmodel.h +++ b/qt-models/divetripmodel.h @@ -133,7 +133,7 @@ private: void recalculateFilter(); void divesChangedTrip(dive_trip *trip, const QVector<dive *> &dives); void divesTimeChangedTrip(dive_trip *trip, timestamp_t delta, const QVector<dive *> &dives); - bool calculateFilterForTrip(const std::vector<dive *> &dives, const DiveFilter *filter, int parentIndex); + bool calculateFilterForTrip(const std::vector<dive *> &dives, const DiveFilter *filter, quintptr parentIndex); // The tree model has two levels. At the top level, we have either trips or dives // that do not belong to trips. Such a top-level item is represented by the "Item" |