summaryrefslogtreecommitdiffstats
path: root/qt-ui/models.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2014-10-31 17:42:07 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-10-31 14:58:56 -0700
commitfd1cc4ea2d6e93e673807ca7a54fdcb3fa08dcf9 (patch)
treec50f4f9d09cdeb43316a17992add9015b73ec5c2 /qt-ui/models.cpp
parent8399d6f977170227c7f7dd0a57c34d0f9e01dd60 (diff)
downloadsubsurface-fd1cc4ea2d6e93e673807ca7a54fdcb3fa08dcf9.tar.gz
FilterRow implemented for LocationFilter.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r--qt-ui/models.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 6f1ace9b9..410c258ee 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -2483,6 +2483,44 @@ QVariant LocationFilterModel::data(const QModelIndex &index, int role) const
bool LocationFilterModel::filterRow(int source_row, const QModelIndex &source_parent, 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))
+ return true;
+ }
+ return false;
+ }
+
+ // Checked means 'Show', Unchecked means 'Hide'.
+ QString location(d->location);
+ // only show empty buddie dives if the user checked that.
+ if (location.isEmpty()) {
+ if (rowCount() > 0)
+ return checkState[rowCount() - 1];
+ else
+ return true;
+ }
+
+ // have at least one buddy
+ QStringList locationList = stringList();
+ if (!locationList.isEmpty()) {
+ locationList.removeLast(); // remove the "Show Empty Tags";
+ for(int i = 0; i < rowCount(); i++){
+ if(checkState[i] && (location.indexOf(stringList()[i]) != -1)){
+ return true;
+ }
+ }
+ }
+ return false;
}
Qt::ItemFlags LocationFilterModel::flags(const QModelIndex &index) const