aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets/tab-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-04-12 16:12:15 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-12 18:19:07 +0300
commit8695d8bdb15f52fdfa1a5df1da83b18c4486a9d8 (patch)
tree7ce48bcaa08089351620b155c408ca32d59907a3 /desktop-widgets/tab-widgets
parentafde4dce0dc89e4ac7edbbffd5dd68a9ce96c5f1 (diff)
downloadsubsurface-8695d8bdb15f52fdfa1a5df1da83b18c4486a9d8.tar.gz
Dive sites: show dives at selected dive sites
When in dive site tab and some dive sites are selected, show only dives at those sites. Simply read the selection and pass it to the filter. Start and stop filtering when switching to and from the tab, respectively. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/tab-widgets')
-rw-r--r--desktop-widgets/tab-widgets/TabDiveSite.cpp32
-rw-r--r--desktop-widgets/tab-widgets/TabDiveSite.h4
2 files changed, 36 insertions, 0 deletions
diff --git a/desktop-widgets/tab-widgets/TabDiveSite.cpp b/desktop-widgets/tab-widgets/TabDiveSite.cpp
index 816835dd3..c14cc6d4f 100644
--- a/desktop-widgets/tab-widgets/TabDiveSite.cpp
+++ b/desktop-widgets/tab-widgets/TabDiveSite.cpp
@@ -3,6 +3,7 @@
#include "core/subsurface-qt/DiveListNotifier.h"
#include "core/divesite.h"
#include "qt-models/divelocationmodel.h"
+#include "qt-models/filtermodels.h"
#include "desktop-widgets/command.h"
#include <qt-models/divecomputerextradatamodel.h>
@@ -23,6 +24,7 @@ TabDiveSite::TabDiveSite(QWidget *parent) : TabBase(parent)
ui.diveSites->view()->setColumnHidden(i, true);
connect(ui.diveSites, &TableView::addButtonClicked, this, &TabDiveSite::add);
+ connect(ui.diveSites->view()->selectionModel(), &QItemSelectionModel::selectionChanged, this, &TabDiveSite::selectionChanged);
// Subtle: We depend on this slot being executed after the slot in the model.
// This is realized because the model was constructed as a member object and connects in the constructor.
@@ -79,3 +81,33 @@ void TabDiveSite::on_filterText_textChanged(const QString &text)
{
model.setFilter(text);
}
+
+void TabDiveSite::updateFilter()
+{
+ const QModelIndexList indexes = ui.diveSites->view()->selectionModel()->selectedIndexes();
+ QVector<dive_site *> sites;
+ sites.reserve(indexes.size());
+ for (const QModelIndex &idx: indexes) {
+ struct dive_site *ds = model.getDiveSite(idx);
+ sites.append(ds);
+ }
+ MultiFilterSortModel::instance()->startFilterDiveSites(sites);
+}
+
+void TabDiveSite::selectionChanged(const QItemSelection &, const QItemSelection &)
+{
+ updateFilter();
+}
+
+void TabDiveSite::showEvent(QShowEvent *)
+{
+ // If the user switches to the dive site tab and there was already a selection,
+ // filter on that selection.
+ updateFilter();
+}
+
+void TabDiveSite::hideEvent(QHideEvent *)
+{
+ // If the user switches to a different tab, stop the dive site filtering
+ MultiFilterSortModel::instance()->stopFilterDiveSites();
+}
diff --git a/desktop-widgets/tab-widgets/TabDiveSite.h b/desktop-widgets/tab-widgets/TabDiveSite.h
index 1fdaeb989..2f831f71c 100644
--- a/desktop-widgets/tab-widgets/TabDiveSite.h
+++ b/desktop-widgets/tab-widgets/TabDiveSite.h
@@ -18,9 +18,13 @@ private slots:
void diveSiteChanged(struct dive_site *ds, int field);
void on_purgeUnused_clicked();
void on_filterText_textChanged(const QString &text);
+ void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
private:
Ui::TabDiveSite ui;
DiveSiteSortedModel model;
+ void updateFilter();
+ void hideEvent(QHideEvent *) override;
+ void showEvent(QShowEvent *) override;
};
#endif