diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2014-09-17 17:15:37 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-09-17 15:28:37 -0700 |
commit | f1e7c12e8a5e39c32ad74d9b0aee4cb0c0529159 (patch) | |
tree | 55b73f134fe9b24ecac90543c992a06aff931982 /qt-ui/models.cpp | |
parent | 4e3689370d8e81716759a5b29934c35cf848a379 (diff) | |
download | subsurface-f1e7c12e8a5e39c32ad74d9b0aee4cb0c0529159.tar.gz |
Correctly filter dives. (trips are always shown)
This patch correctly filter dives based on tags, but it will
also keep showing all the empty trips.
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.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index def258a5f..f1f1f636c 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -2146,6 +2146,7 @@ bool TagFilterModel::setData(const QModelIndex &index, const QVariant &value, in { if(role == Qt::CheckStateRole){ checkState[index.row()] = value.toBool(); + dataChanged(index,index); return true; } return false; @@ -2153,7 +2154,7 @@ bool TagFilterModel::setData(const QModelIndex &index, const QVariant &value, in TagFilterSortModel::TagFilterSortModel(QObject *parent): QSortFilterProxyModel(parent) { - + connect(TagFilterModel::instance(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(invalidate())); } bool TagFilterSortModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const @@ -2162,16 +2163,25 @@ bool TagFilterSortModel::filterAcceptsRow(int source_row, const QModelIndex &sou QVariant diveVariant = sourceModel()->data(index0, DiveTripModel::DIVE_ROLE); struct dive* d = (struct dive* ) diveVariant.value<void*>(); if(!d) - return false; // it's a trip. - + return false; // Checked means 'Show', Unchecked means 'Hide'. struct tag_entry *head = d->tag_list; + if (!head){ // doesn't have tags, only show if no tags are selected. + for(int i = 0; i < TagFilterModel::instance()->stringList().count(); i++){ + if (TagFilterModel::instance()->checkState[i]) + return false; + } + return true; + } + + // have at least one tag. while(head) { QString tagName(head->tag->name); int index = TagFilterModel::instance()->stringList().indexOf(tagName); - if (TagFilterModel::instance()->checkState[index] == false ) + if (TagFilterModel::instance()->checkState[index]) return true; + head = head->next; } return false; } |