From 9afea37e15db29f59048d1bc2553838943ca1b62 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 22 Mar 2019 20:55:05 +0100 Subject: Undo: update filter flag when dives change The filter code is strange: it actually only checks the dive->hidden_by_filter flag. Thus, before propagating the dive changed signal, this flag has to be updated. Do this in the DiveTripModel. Ultimately, this should be refactored. Moreover, if the filter-flag changed notify the frontend of a changed trip so that the trip is hidden / unhidden. Signed-off-by: Berthold Stoeger --- qt-models/divetripmodel.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'qt-models/divetripmodel.cpp') diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index 297dffc5d..d79290725 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -876,6 +876,12 @@ void DiveTripModelTree::divesDeleted(dive_trip *trip, bool deleteTrip, const QVe void DiveTripModelTree::divesChanged(dive_trip *trip, const QVector &dives) { + // Update filter flags. TODO: The filter should update the flag by itself when + // recieving the signals below. + bool diveChanged = false; + for (dive *d: dives) + diveChanged |= MultiFilterSortModel::instance()->updateDive(d); + if (!trip) { // This is outside of a trip. Process top-level items range-wise. @@ -910,6 +916,10 @@ void DiveTripModelTree::divesChanged(dive_trip *trip, const QVector &div // If necessary, move the trip topLevelChanged(idx); + + // If a dive changed, re-render the trip in the list [or actually make it (in)visible]. + if (diveChanged) + dataChanged(createIndex(idx, 0, noParent), createIndex(idx, 0, noParent)); } } @@ -1161,6 +1171,11 @@ void DiveTripModelList::divesDeleted(dive_trip *trip, bool deleteTrip, const QVe void DiveTripModelList::divesChanged(dive_trip *trip, const QVector &dives) { + // Update filter flags. TODO: The filter should update the flag by itself when + // recieving the signals below. + for (dive *d: dives) + MultiFilterSortModel::instance()->updateDive(d); + // Since we know that the dive list is sorted, we will only ever search for the first element // in dives as this must be the first that we encounter. Once we find a range, increase the // index accordingly. -- cgit v1.2.3-70-g09d2