summaryrefslogtreecommitdiffstats
path: root/qt-ui/filtermodels.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2014-11-13 17:12:46 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-13 12:06:20 -0800
commit462091b96311b0fdbc22a534904eb6ab096bd2db (patch)
treea8333e7f344d1ea3e27996d8c664fd13988429b0 /qt-ui/filtermodels.cpp
parentfdbdcaab809c969cd4154ae67a717283c94feb9f (diff)
downloadsubsurface-462091b96311b0fdbc22a534904eb6ab096bd2db.tar.gz
Create the doFilter for the Suits.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/filtermodels.cpp')
-rw-r--r--qt-ui/filtermodels.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/qt-ui/filtermodels.cpp b/qt-ui/filtermodels.cpp
index 4ed2948ec..9e3c76331 100644
--- a/qt-ui/filtermodels.cpp
+++ b/qt-ui/filtermodels.cpp
@@ -77,6 +77,38 @@ SuitsFilterModel::SuitsFilterModel(QObject *parent): QStringListModel(parent)
bool SuitsFilterModel::doFilter(dive *d, QModelIndex &index0, QAbstractItemModel *sourceModel) const
{
+ 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 suit(d->suit);
+ // only show empty suit dives if the user checked that.
+ if (suit.isEmpty()) {
+ if (rowCount() > 0)
+ return checkState[rowCount() - 1];
+ else
+ return true;
+ }
+
+ // there is a suit selected
+ QStringList suitList = stringList();
+ if (!suitList.isEmpty()) {
+ suitList.removeLast(); // remove the "Show Empty Suits";
+ for (int i = 0; i < rowCount(); i++) {
+ if (checkState[i] && (suit.indexOf(stringList()[i]) != -1)) {
+ return true;
+ }
+ }
+ }
return false;
}