From 358fddd24e03d8f4522b108b28931a1227749831 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 9 Dec 2019 15:13:53 +0100 Subject: Filter: send filterReset via signal The old code called directly into the DiveListModel. Instead, send a signal and hook into the signal from the model. This will allow us to remove the DiveListModel::instance() function. This, in turn, is a step towards supporting multiple models at the same time. However, currently the model manually sets the hidden_by_filter flag in the core and therefore only one active model is supported at a time. Signed-off-by: Berthold Stoeger --- qt-models/divetripmodel.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'qt-models/divetripmodel.cpp') diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp index ee0620c5e..ae6dfe651 100644 --- a/qt-models/divetripmodel.cpp +++ b/qt-models/divetripmodel.cpp @@ -575,6 +575,7 @@ DiveTripModelTree::DiveTripModelTree(QObject *parent) : DiveTripModelBase(parent connect(&diveListNotifier, &DiveListNotifier::divesTimeChanged, this, &DiveTripModelTree::divesTimeChanged); connect(&diveListNotifier, &DiveListNotifier::divesSelected, this, &DiveTripModelTree::divesSelected); connect(&diveListNotifier, &DiveListNotifier::tripChanged, this, &DiveTripModelTree::tripChanged); + connect(&diveListNotifier, &DiveListNotifier::filterReset, this, &DiveTripModelTree::filterReset); // Fill model for (int i = 0; i < dive_table.nr ; ++i) { @@ -745,7 +746,11 @@ bool DiveTripModelTree::calculateFilterForTrip(const std::vector &dives, return showTrip; } -void DiveTripModelTree::recalculateFilter() +// This recalculates the filters and sends appropriate changed signals. +// Attention: Since this uses / modifies the hidden_by_filter flag of the +// core dive structure, only one DiveTripModel[Tree|List] must exist at +// a given time! +void DiveTripModelTree::filterReset() { // Collect the changes in a vector used later to send signals. // This could be solved more efficiently in one pass, but @@ -791,7 +796,6 @@ void DiveTripModelTree::recalculateFilter() } emit diveListNotifier.numShownChanged(); - emit diveListNotifier.filterReset(); } @@ -1291,6 +1295,7 @@ DiveTripModelList::DiveTripModelList(QObject *parent) : DiveTripModelBase(parent //connect(&diveListNotifier, &DiveListNotifier::divesMovedBetweenTrips, this, &DiveTripModelList::divesMovedBetweenTrips); connect(&diveListNotifier, &DiveListNotifier::divesTimeChanged, this, &DiveTripModelList::divesTimeChanged); connect(&diveListNotifier, &DiveListNotifier::divesSelected, this, &DiveTripModelList::divesSelected); + connect(&diveListNotifier, &DiveListNotifier::filterReset, this, &DiveTripModelList::filterReset); // Fill model items.reserve(dive_table.nr); @@ -1332,7 +1337,11 @@ dive *DiveTripModelList::diveOrNull(const QModelIndex &index) const return items[row]; } -void DiveTripModelList::recalculateFilter() +// This recalculates the filters and sends appropriate changed signals. +// Attention: Since this uses / modifies the hidden_by_filter flag of the +// core dive structure, only one DiveTripModel[Tree|List] must exist at +// a given time! +void DiveTripModelList::filterReset() { // Collect the changes in a vector used later to send signals. // This could be solved more efficiently in one pass, but @@ -1342,7 +1351,7 @@ void DiveTripModelList::recalculateFilter() changed.reserve(items.size()); { // This marker prevents the UI from getting notifications on selection changes. - // It is active until the end of the scope. See comment in DiveTripModelTree::recalculateFilter(). + // It is active until the end of the scope. See comment in DiveTripModelTree::filterReset(). auto marker = diveListNotifier.enterCommand(); DiveFilter *filter = DiveFilter::instance(); @@ -1356,7 +1365,6 @@ void DiveTripModelList::recalculateFilter() sendShownChangedSignals(changed, noParent); emit diveListNotifier.numShownChanged(); - emit diveListNotifier.filterReset(); } QVariant DiveTripModelList::data(const QModelIndex &index, int role) const -- cgit v1.2.3-70-g09d2