diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2014-10-31 16:37:26 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-10-31 14:58:55 -0700 |
commit | b1d76ed4d794ca1d97c81e769470e3da79c20b17 (patch) | |
tree | cef78f834a3aa29e103130480224d4e2f2c98a29 | |
parent | 30cf0ba79ae31086664fddbaf24cc0570b00eb1f (diff) | |
download | subsurface-b1d76ed4d794ca1d97c81e769470e3da79c20b17.tar.gz |
Implemented the filterRow method for BuddyList.
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/models.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 4f13d3b12..41087531c 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -2364,7 +2364,45 @@ BuddyFilterModel *BuddyFilterModel::instance() bool BuddyFilterModel::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 diveBuddy(d->buddy); + + // only show empty buddie dives if the user checked that. + if (diveBuddy.isEmpty()) { + if (rowCount() > 0) + return checkState[rowCount() - 1]; + else + return true; + } + + // have at least one buddy + QStringList buddyList = stringList(); + if (!buddyList.isEmpty()) { + buddyList.removeLast(); // remove the "Show Empty Tags"; + for(int i = 0; i < rowCount(); i++){ + if(checkState[i] && stringList()[i].indexOf(diveBuddy) != -1){ + return true; + } + } + } + return false; } Qt::ItemFlags BuddyFilterModel::flags(const QModelIndex &index) const |