diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-11-11 13:34:12 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-11-11 13:34:12 -0800 |
commit | 19ca90f1a0ab8bad7488bf03e6248c8a8c8ff7e0 (patch) | |
tree | 95a9bc80e3db55d011d13498c0afad6359506edf /qt-ui | |
parent | d5ffc16c362ce8f2f353f3c4880ecd689c9ea7ee (diff) | |
download | subsurface-19ca90f1a0ab8bad7488bf03e6248c8a8c8ff7e0.tar.gz |
Embed the information whether a dive is hidden by a filter in the dive
This way other parts of the code can act on the "hidden_by_filter" state.
This also cleans up the way we track if a dive is hidden - do it in the
multi filter instead of the individual filters.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/models.cpp | 110 | ||||
-rw-r--r-- | qt-ui/models.h | 4 |
2 files changed, 68 insertions, 46 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 04611977f..5ad1c79c7 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -2317,17 +2317,12 @@ bool TagFilterModel::setData(const QModelIndex &index, const QVariant &value, in return false; } -bool TagFilterModel::filterRow(int source_row, const QModelIndex &source_parent, QAbstractItemModel *sourceModel) const +bool TagFilterModel::doFilter(dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const { - // If there's nothing checked, this should show everythin. + // If there's nothing checked, this should show everything if (!anyChecked) { return true; } - - 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 *>(); - 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)) @@ -2340,12 +2335,7 @@ bool TagFilterModel::filterRow(int source_row, const QModelIndex &source_parent, if (!head) { // last tag means "Show empty tags"; if (rowCount() > 0) - if (checkState[rowCount() - 1]) { - return true; - } else { - deselect_dive(get_idx_by_uniq_id(d->id)); - return false; - } + return checkState[rowCount() - 1]; else return true; } @@ -2362,10 +2352,23 @@ bool TagFilterModel::filterRow(int source_row, const QModelIndex &source_parent, head = head->next; } } - deselect_dive(get_idx_by_uniq_id(d->id)); return false; } +bool TagFilterModel::filterRow(int source_row, const QModelIndex &source_parent, QAbstractItemModel *sourceModel) const +{ + // If there's nothing checked, this should show everything + if (!anyChecked) { + return true; + } + + 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); +} + BuddyFilterModel::BuddyFilterModel(QObject *parent) : QStringListModel(parent) { } @@ -2376,17 +2379,12 @@ BuddyFilterModel *BuddyFilterModel::instance() return self; } -bool BuddyFilterModel::filterRow(int source_row, const QModelIndex &source_parent, QAbstractItemModel *sourceModel) const +bool BuddyFilterModel::doFilter(dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const { - // If there's nothing checked, this should show everythin. + // If there's nothing checked, this should show everything if (!anyChecked) { return true; } - - 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 *>(); - 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)) @@ -2401,12 +2399,7 @@ bool BuddyFilterModel::filterRow(int source_row, const QModelIndex &source_paren // only show empty buddie dives if the user checked that. if (diveBuddy.isEmpty() && divemaster.isEmpty()) { if (rowCount() > 0) - if (checkState[rowCount() - 1]) { - return true; - } else { - deselect_dive(get_idx_by_uniq_id(d->id)); - return false; - } + return checkState[rowCount() - 1]; else return true; } @@ -2421,10 +2414,23 @@ bool BuddyFilterModel::filterRow(int source_row, const QModelIndex &source_paren } } } - deselect_dive(get_idx_by_uniq_id(d->id)); return false; } +bool BuddyFilterModel::filterRow(int source_row, const QModelIndex &source_parent, QAbstractItemModel *sourceModel) const +{ + // If there's nothing checked, this should show everything + if (!anyChecked) { + return true; + } + + 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); +} + Qt::ItemFlags BuddyFilterModel::flags(const QModelIndex &index) const { return QStringListModel::flags(index) | Qt::ItemIsUserCheckable; @@ -2496,18 +2502,12 @@ QVariant LocationFilterModel::data(const QModelIndex &index, int role) const return QVariant(); } -bool LocationFilterModel::filterRow(int source_row, const QModelIndex &source_parent, QAbstractItemModel *sourceModel) const +bool LocationFilterModel::doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const { - - // If there's nothing checked, this should show everythin. if (!anyChecked) { return true; } - 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 *>(); - 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)) @@ -2518,20 +2518,15 @@ bool LocationFilterModel::filterRow(int source_row, const QModelIndex &source_pa // Checked means 'Show', Unchecked means 'Hide'. QString location(d->location); - // only show empty buddie dives if the user checked that. + // only show empty location dives if the user checked that. if (location.isEmpty()) { if (rowCount() > 0) - if (checkState[rowCount() - 1]) { - return true; - } else { - deselect_dive(get_idx_by_uniq_id(d->id)); - return false; - } + return checkState[rowCount() - 1]; else return true; } - // have at least one buddy + // there is a location selected QStringList locationList = stringList(); if (!locationList.isEmpty()) { locationList.removeLast(); // remove the "Show Empty Tags"; @@ -2541,10 +2536,24 @@ bool LocationFilterModel::filterRow(int source_row, const QModelIndex &source_pa } } } - deselect_dive(get_idx_by_uniq_id(d->id)); return false; } +bool LocationFilterModel::filterRow(int source_row, const QModelIndex &source_parent, QAbstractItemModel *sourceModel) const +{ + + // If there's nothing checked, this should show everything + if (!anyChecked) { + return true; + } + + 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); +} + Qt::ItemFlags LocationFilterModel::flags(const QModelIndex &index) const { return QStringListModel::flags(index) | Qt::ItemIsUserCheckable; @@ -2610,10 +2619,19 @@ bool MultiFilterSortModel::filterAcceptsRow(int source_row, const QModelIndex &s return true; bool shouldShow = true; + 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 *>(); + Q_FOREACH (MultiFilterInterface *model, models) { - if (!model->filterRow(source_row, source_parent, sourceModel())) { + if (!model->doFilter(d, index0, sourceModel())) shouldShow = false; - } + } + // if it's a dive, mark it accordingly + if (d) { + if (d->selected) + d->selected = shouldShow; + d->hidden_by_filter = !shouldShow; } return shouldShow; } diff --git a/qt-ui/models.h b/qt-ui/models.h index 470cf5fbc..8a2d3dcb9 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -442,6 +442,7 @@ class MultiFilterInterface { public: MultiFilterInterface() : checkState(NULL){}; virtual bool filterRow(int source_row, const QModelIndex &source_parent, QAbstractItemModel *sourceModel) const = 0; + virtual bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const = 0; virtual void clearFilter() = 0; bool *checkState; bool anyChecked; @@ -455,6 +456,7 @@ public: virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); virtual Qt::ItemFlags flags(const QModelIndex &index) const; virtual bool filterRow(int source_row, const QModelIndex &source_parent, QAbstractItemModel *sourceModel) const; + bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const; void clearFilter(); public slots: @@ -472,6 +474,7 @@ public: virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); virtual Qt::ItemFlags flags(const QModelIndex &index) const; virtual bool filterRow(int source_row, const QModelIndex &source_parent, QAbstractItemModel *sourceModel) const; + bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const; void clearFilter(); public slots: @@ -489,6 +492,7 @@ public: virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); virtual Qt::ItemFlags flags(const QModelIndex &index) const; virtual bool filterRow(int source_row, const QModelIndex &source_parent, QAbstractItemModel *sourceModel) const; + bool doFilter(struct dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const; void clearFilter(); public slots: |