aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/divetripmodel.cpp15
-rw-r--r--qt-models/filtermodels.cpp12
-rw-r--r--qt-models/filtermodels.h1
3 files changed, 28 insertions, 0 deletions
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<dive *> &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<dive *> &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<dive *> &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.
diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp
index 5fd9ed1f7..a0c910244 100644
--- a/qt-models/filtermodels.cpp
+++ b/qt-models/filtermodels.cpp
@@ -249,6 +249,18 @@ void MultiFilterSortModel::myInvalidate()
#endif
}
+bool MultiFilterSortModel::updateDive(struct dive *d)
+{
+ bool oldStatus = !d->hidden_by_filter;
+ bool newStatus = showDive(d);
+ bool changed = oldStatus != newStatus;
+ if (changed) {
+ filter_dive(d, newStatus);
+ divesDisplayed += newStatus - oldStatus;
+ }
+ return changed;
+}
+
void MultiFilterSortModel::clearFilter()
{
myInvalidate();
diff --git a/qt-models/filtermodels.h b/qt-models/filtermodels.h
index 3b3e14abc..6513788f2 100644
--- a/qt-models/filtermodels.h
+++ b/qt-models/filtermodels.h
@@ -60,6 +60,7 @@ public:
static MultiFilterSortModel *instance();
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
bool showDive(const struct dive *d) const;
+ bool updateDive(struct dive *d); // returns true if visibility status changed
int divesDisplayed;
bool lessThan(const QModelIndex &, const QModelIndex &) const override;
public