aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models/filtermodels.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-11-17 19:53:18 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-11-19 21:13:40 -0800
commit3003c6e1eed330978193d6859eca2f79ee68aa54 (patch)
tree1baeb54aeca0eda10d273779cf3704095a170d2e /qt-models/filtermodels.cpp
parent9ffafbc326b38bd2d0bb870fa4721b6c94280c28 (diff)
downloadsubsurface-3003c6e1eed330978193d6859eca2f79ee68aa54.tar.gz
Filter: move recalculation of filter from FilterModel to TripModel
The way this was accessed via Qt's model semantics was horrible. This gives arguably more readable code, since we don't have to shoehorn things through QVariants. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/filtermodels.cpp')
-rw-r--r--qt-models/filtermodels.cpp73
1 files changed, 1 insertions, 72 deletions
diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp
index 53b9e2e45..9c1e9d3b5 100644
--- a/qt-models/filtermodels.cpp
+++ b/qt-models/filtermodels.cpp
@@ -7,13 +7,6 @@
#include "core/subsurface-qt/DiveListNotifier.h"
#include "qt-models/divetripmodel.h"
-#if !defined(SUBSURFACE_MOBILE)
-#include "core/divefilter.h"
-#endif
-
-#include <QDebug>
-#include <algorithm>
-
MultiFilterSortModel *MultiFilterSortModel::instance()
{
static MultiFilterSortModel self;
@@ -22,6 +15,7 @@ MultiFilterSortModel *MultiFilterSortModel::instance()
MultiFilterSortModel::MultiFilterSortModel(QObject *parent) : QSortFilterProxyModel(parent)
{
+ connect(&diveListNotifier, &DiveListNotifier::filterReset, this, &MultiFilterSortModel::invalidateFilter);
setFilterKeyColumn(-1); // filter all columns
setFilterCaseSensitivity(Qt::CaseInsensitive);
}
@@ -41,73 +35,8 @@ bool MultiFilterSortModel::filterAcceptsRow(int source_row, const QModelIndex &s
return m->data(index0, DiveTripModelBase::SHOWN_ROLE).value<bool>();
}
-void MultiFilterSortModel::myInvalidate()
-{
- QAbstractItemModel *m = sourceModel();
- if (!m)
- return;
-
- {
- // This marker prevents the UI from getting notifications on selection changes.
- // It is active until the end of the scope.
- // This is actually meant for the undo-commands, so that they can do their work
- // without having the UI updated.
- // Here, it is used because invalidating the filter can generate numerous
- // selection changes, which do full ui reloads. Instead, do that all at once
- // as a consequence of the filterFinished signal right after the local scope.
- auto marker = diveListNotifier.enterCommand();
-
- DiveFilter *filter = DiveFilter::instance();
- for (int i = 0; i < m->rowCount(QModelIndex()); ++i) {
- QModelIndex idx = m->index(i, 0, QModelIndex());
-
- if (m->data(idx, DiveTripModelBase::IS_TRIP_ROLE).toBool()) {
- // This is a trip -> loop over all dives and see if any is selected
-
- bool showTrip = false;
- for (int j = 0; j < m->rowCount(idx); ++j) {
- QModelIndex idx2 = m->index(j, 0, idx);
- dive *d = m->data(idx2, DiveTripModelBase::DIVE_ROLE).value<dive *>();
- if (!d) {
- qWarning("MultiFilterSortModel::myInvalidate(): subitem not a dive!?");
- continue;
- }
- bool show = filter->showDive(d);
- if (show)
- showTrip = true;
- m->setData(idx2, show, DiveTripModelBase::SHOWN_ROLE);
- }
- m->setData(idx, showTrip, DiveTripModelBase::SHOWN_ROLE);
- } else {
- dive *d = m->data(idx, DiveTripModelBase::DIVE_ROLE).value<dive *>();
- bool show = (d != NULL) && filter->showDive(d);
- m->setData(idx, show, DiveTripModelBase::SHOWN_ROLE);
- }
- }
-
- invalidateFilter();
-
- // Tell the dive trip model to update the displayed-counts
- DiveTripModelBase::instance()->filterFinished();
- countsChanged();
- }
-
- emit filterFinished();
-}
-
-bool MultiFilterSortModel::updateDive(struct dive *d)
-{
- bool newStatus = DiveFilter::instance()->showDive(d);
- return filter_dive(d, newStatus);
-}
-
bool MultiFilterSortModel::lessThan(const QModelIndex &i1, const QModelIndex &i2) const
{
// Hand sorting down to the source model.
return DiveTripModelBase::instance()->lessThan(i1, i2);
}
-
-void MultiFilterSortModel::countsChanged()
-{
- updateWindowTitle();
-}