From 2f81890f496a21c852513a26b728e04e03c4f01e Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 19 Oct 2018 13:33:35 +0200 Subject: [PATCH] Dive list: update trip headers on filter-finish On change of the filter, the headers of non-extended trips were not updated. Therefore, on filter-finish-event loop over all trips in DiveTripModel and signal data-changed. Signed-off-by: Berthold Stoeger --- qt-models/divetripmodel.cpp | 16 ++++++++++++++++ qt-models/divetripmodel.h | 1 + 2 files changed, 17 insertions(+) diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index ff96669a7..5f64b8741 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "qt-models/divetripmodel.h" +#include "qt-models/filtermodels.h" #include "core/gettextfromc.h" #include "core/metrics.h" #include "core/divelist.h" @@ -319,6 +320,9 @@ DiveTripModel::DiveTripModel(QObject *parent) : connect(&diveListNotifier, &DiveListNotifier::divesSelected, this, &DiveTripModel::divesSelected); connect(&diveListNotifier, &DiveListNotifier::divesDeselected, this, &DiveTripModel::divesDeselected); connect(&diveListNotifier, &DiveListNotifier::currentDiveChanged, this, &DiveTripModel::currentDiveChanged); + + // Update trip headers if filter finished + connect(MultiFilterSortModel::instance(), &MultiFilterSortModel::filterFinished, this, &DiveTripModel::filterFinished); } int DiveTripModel::columnCount(const QModelIndex&) const @@ -1095,3 +1099,15 @@ void DiveTripModel::currentDiveChanged() emit newCurrentDive(createIndex(diveIdx, 0, idx)); } } + +void DiveTripModel::filterFinished() +{ + // If the filter finished, update all trip items to show the correct number of displayed dives + // in each trip. Without doing this, only trip headers of expanded trips were updated. + if (currentLayout == LIST) + return; // No trips in list mode + for (int idx = 0; idx < (int)items.size(); ++idx) { + QModelIndex tripIndex = createIndex(idx, 0, noParent); + dataChanged(tripIndex, tripIndex); + } +} diff --git a/qt-models/divetripmodel.h b/qt-models/divetripmodel.h index d75926f9e..9ccad16dc 100644 --- a/qt-models/divetripmodel.h +++ b/qt-models/divetripmodel.h @@ -75,6 +75,7 @@ private slots: void divesSelected(dive_trip *trip, const QVector &dives); void divesDeselected(dive_trip *trip, const QVector &dives); void currentDiveChanged(); + void filterFinished(); private: // The model has up to 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"