summaryrefslogtreecommitdiffstats
path: root/qt-models/divetripmodel.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-12-09 15:13:53 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-12-10 18:45:30 -0800
commit358fddd24e03d8f4522b108b28931a1227749831 (patch)
treec56c32441def8a844428fe2b51fff9330ccd8bbd /qt-models/divetripmodel.cpp
parent71307bce42af3070c9f2ff32f52e289cb6c3a64d (diff)
downloadsubsurface-358fddd24e03d8f4522b108b28931a1227749831.tar.gz
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 <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/divetripmodel.cpp')
-rw-r--r--qt-models/divetripmodel.cpp18
1 files changed, 13 insertions, 5 deletions
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<dive *> &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