diff options
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" |