summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-04-12 15:47:41 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-12 18:19:07 +0300
commitafde4dce0dc89e4ac7edbbffd5dd68a9ce96c5f1 (patch)
treeeeecfd5a2aa34eb8f83d0562c87d1c13df7dad2e /qt-models
parent5aacd73a00bac5721674b1f8b223d3aacc862a4c (diff)
downloadsubsurface-afde4dce0dc89e4ac7edbbffd5dd68a9ce96c5f1.tar.gz
Filter: allow filtering multiple dive sites
In the edit-dive-site tab the filter is switched to a particular mode where only dives at that site are shown. If we want to reuse this for the dive-site tab the mode has to be extended to allow for multiple dive sites. This is trivially done by replacing a pointer by a vector of pointers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/filtermodels.cpp19
-rw-r--r--qt-models/filtermodels.h7
2 files changed, 13 insertions, 13 deletions
diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp
index 94b74d92d..bc454bcc9 100644
--- a/qt-models/filtermodels.cpp
+++ b/qt-models/filtermodels.cpp
@@ -105,8 +105,7 @@ MultiFilterSortModel *MultiFilterSortModel::instance()
}
MultiFilterSortModel::MultiFilterSortModel(QObject *parent) : QSortFilterProxyModel(parent),
- divesDisplayed(0),
- curr_dive_site(NULL)
+ divesDisplayed(0)
{
setFilterKeyColumn(-1); // filter all columns
setFilterCaseSensitivity(Qt::CaseInsensitive);
@@ -125,9 +124,9 @@ void MultiFilterSortModel::resetModel(DiveTripModelBase::Layout layout)
bool MultiFilterSortModel::showDive(const struct dive *d) const
{
- // If curr_dive_site is set, we are in a special dive-site editing mode.
- if (curr_dive_site)
- return d->dive_site == curr_dive_site;
+ // If dive_sites is not empty, we are in a special dive-site filtering mode.
+ if (!dive_sites.isEmpty())
+ return dive_sites.contains(d->dive_site);
if (!filterData.validFilter)
return true;
@@ -245,7 +244,7 @@ void MultiFilterSortModel::myInvalidate()
emit filterFinished();
#if !defined(SUBSURFACE_MOBILE)
- if (curr_dive_site)
+ if (!dive_sites.isEmpty())
MainWindow::instance()->diveList->expandAll();
#endif
}
@@ -267,15 +266,15 @@ void MultiFilterSortModel::clearFilter()
myInvalidate();
}
-void MultiFilterSortModel::startFilterDiveSite(struct dive_site *ds)
+void MultiFilterSortModel::startFilterDiveSites(QVector<dive_site *> ds)
{
- curr_dive_site = ds;
+ dive_sites = ds;
myInvalidate();
}
-void MultiFilterSortModel::stopFilterDiveSite()
+void MultiFilterSortModel::stopFilterDiveSites()
{
- curr_dive_site = NULL;
+ dive_sites.clear();
myInvalidate();
}
diff --git a/qt-models/filtermodels.h b/qt-models/filtermodels.h
index 45e1e7189..258b4186b 100644
--- a/qt-models/filtermodels.h
+++ b/qt-models/filtermodels.h
@@ -67,8 +67,8 @@ public
slots:
void myInvalidate();
void clearFilter();
- void startFilterDiveSite(struct dive_site *ds);
- void stopFilterDiveSite();
+ void startFilterDiveSites(QVector<dive_site *> ds);
+ void stopFilterDiveSites();
void filterChanged(const QModelIndex &from, const QModelIndex &to, const QVector<int> &roles);
void resetModel(DiveTripModelBase::Layout layout);
void filterDataChanged(const FilterData &data);
@@ -80,7 +80,8 @@ signals:
private:
MultiFilterSortModel(QObject *parent = 0);
- struct dive_site *curr_dive_site;
+ // Dive site filtering has priority over other filters
+ QVector<dive_site *> dive_sites;
void countsChanged();
FilterData filterData;
};