summaryrefslogtreecommitdiffstats
path: root/qt-ui/filtermodels.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-16 18:22:35 +0000
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-16 18:36:42 +0000
commit05e02b939a70bac0078211a5c1a94e698b3b5c2b (patch)
tree8641aba88604470d6023e51dab49dbe85e7c4b89 /qt-ui/filtermodels.cpp
parentad603b6e9f0b03032ba0f04c6cec0a5e9b10514b (diff)
downloadsubsurface-05e02b939a70bac0078211a5c1a94e698b3b5c2b.tar.gz
Improve the filter logic
The MultiFilter itself should walk the dives in a trip. This way the logic (OR within a category, but AND between categories) is correctly applied and the flags in the dives are set correctly (which makes the overall counts for dives filtered work correctly. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/filtermodels.cpp')
-rw-r--r--qt-ui/filtermodels.cpp78
1 files changed, 8 insertions, 70 deletions
diff --git a/qt-ui/filtermodels.cpp b/qt-ui/filtermodels.cpp
index 6751a8cfe..c599a6578 100644
--- a/qt-ui/filtermodels.cpp
+++ b/qt-ui/filtermodels.cpp
@@ -81,14 +81,6 @@ bool SuitsFilterModel::doFilter(dive *d, QModelIndex &index0, QAbstractItemModel
return true;
}
- if (!d) { // It's a trip, only show the ones that have dives to be shown.
- for (int i = 0; i < sourceModel->rowCount(index0); i++) {
- if (filterRow(i, index0, sourceModel))
- return true;
- }
- return false;
- }
-
// Checked means 'Show', Unchecked means 'Hide'.
QString suit(d->suit);
// only show empty suit dives if the user checked that.
@@ -112,15 +104,6 @@ bool SuitsFilterModel::doFilter(dive *d, QModelIndex &index0, QAbstractItemModel
return false;
}
-bool SuitsFilterModel::filterRow(int source_row, const QModelIndex &source_parent, QAbstractItemModel *sourceModel) const
-{
- QModelIndex index0 = sourceModel->index(source_row, 0, source_parent);
- QVariant diveVariant = sourceModel->data(index0, DiveTripModel::DIVE_ROLE);
- struct dive *d = (struct dive *)diveVariant.value<void *>();
-
- return doFilter(d, index0, sourceModel);
-}
-
void SuitsFilterModel::repopulate()
{
QStringList list;
@@ -172,13 +155,6 @@ bool TagFilterModel::doFilter(dive *d, QModelIndex &index0, QAbstractItemModel *
if (!anyChecked) {
return true;
}
- if (!d) { // It's a trip, only show the ones that have dives to be shown.
- for (int i = 0; i < sourceModel->rowCount(index0); i++) {
- if (filterRow(i, index0, sourceModel))
- return true;
- }
- return false;
- }
// Checked means 'Show', Unchecked means 'Hide'.
struct tag_entry *head = d->tag_list;
@@ -204,17 +180,6 @@ bool TagFilterModel::doFilter(dive *d, QModelIndex &index0, QAbstractItemModel *
return false;
}
-bool TagFilterModel::filterRow(int source_row, const QModelIndex &source_parent, QAbstractItemModel *sourceModel) const
-{
- QModelIndex index0 = sourceModel->index(source_row, 0, source_parent);
- QVariant diveVariant = sourceModel->data(index0, DiveTripModel::DIVE_ROLE);
- struct dive *d = (struct dive *)diveVariant.value<void *>();
-
- bool show = doFilter(d, index0, sourceModel);
- filter_dive(d, show);
- return show;
-}
-
BuddyFilterModel::BuddyFilterModel(QObject *parent) : QStringListModel(parent)
{
}
@@ -225,14 +190,6 @@ bool BuddyFilterModel::doFilter(dive *d, QModelIndex &index0, QAbstractItemModel
if (!anyChecked) {
return true;
}
- if (!d) { // It's a trip, only show the ones that have dives to be shown.
- for (int i = 0; i < sourceModel->rowCount(index0); i++) {
- if (filterRow(i, index0, sourceModel))
- return true;
- }
- return false;
- }
-
// Checked means 'Show', Unchecked means 'Hide'.
QString diveBuddy(d->buddy);
QString divemaster(d->divemaster);
@@ -257,15 +214,6 @@ bool BuddyFilterModel::doFilter(dive *d, QModelIndex &index0, QAbstractItemModel
return false;
}
-bool BuddyFilterModel::filterRow(int source_row, const QModelIndex &source_parent, QAbstractItemModel *sourceModel) const
-{
- QModelIndex index0 = sourceModel->index(source_row, 0, source_parent);
- QVariant diveVariant = sourceModel->data(index0, DiveTripModel::DIVE_ROLE);
- struct dive *d = (struct dive *)diveVariant.value<void *>();
-
- return doFilter(d, index0, sourceModel);
-}
-
void BuddyFilterModel::repopulate()
{
QStringList list;
@@ -299,15 +247,6 @@ bool LocationFilterModel::doFilter(struct dive *d, QModelIndex &index0, QAbstrac
if (!anyChecked) {
return true;
}
-
- if (!d) { // It's a trip, only show the ones that have dives to be shown.
- for (int i = 0; i < sourceModel->rowCount(index0); i++) {
- if (filterRow(i, index0, sourceModel))
- return true;
- }
- return false;
- }
-
// Checked means 'Show', Unchecked means 'Hide'.
QString location(d->location);
// only show empty location dives if the user checked that.
@@ -331,15 +270,6 @@ bool LocationFilterModel::doFilter(struct dive *d, QModelIndex &index0, QAbstrac
return false;
}
-bool LocationFilterModel::filterRow(int source_row, const QModelIndex &source_parent, QAbstractItemModel *sourceModel) const
-{
- QModelIndex index0 = sourceModel->index(source_row, 0, source_parent);
- QVariant diveVariant = sourceModel->data(index0, DiveTripModel::DIVE_ROLE);
- struct dive *d = (struct dive *)diveVariant.value<void *>();
-
- return doFilter(d, index0, sourceModel);
-}
-
void LocationFilterModel::repopulate()
{
QStringList list;
@@ -375,6 +305,14 @@ bool MultiFilterSortModel::filterAcceptsRow(int source_row, const QModelIndex &s
QVariant diveVariant = sourceModel()->data(index0, DiveTripModel::DIVE_ROLE);
struct dive *d = (struct dive *)diveVariant.value<void *>();
+ if (!d) { // It's a trip, only show the ones that have dives to be shown.
+ bool showTrip = false;
+ for (int i = 0; i < sourceModel()->rowCount(index0); i++) {
+ if (filterAcceptsRow(i, index0))
+ showTrip = true; // do not shortcircuit the loop or the counts will be wrong
+ }
+ return showTrip;
+ }
Q_FOREACH (MultiFilterInterface *model, models) {
if (!model->doFilter(d, index0, sourceModel()))
shouldShow = false;