aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--desktop-widgets/tab-widgets/TabDiveSite.cpp32
-rw-r--r--desktop-widgets/tab-widgets/TabDiveSite.h4
-rw-r--r--qt-models/divelocationmodel.h2
3 files changed, 37 insertions, 1 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
diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h
index 914672725..a42354737 100644
--- a/qt-models/divelocationmodel.h
+++ b/qt-models/divelocationmodel.h
@@ -41,7 +41,6 @@ public slots:
class DiveSiteSortedModel : public QSortFilterProxyModel {
Q_OBJECT
private:
- struct dive_site *getDiveSite(const QModelIndex &idx);
bool filterAcceptsRow(int sourceRow, const QModelIndex &source_parent) const override;
bool lessThan(const QModelIndex &i1, const QModelIndex &i2) const override;
QString fullText;
@@ -54,6 +53,7 @@ public:
DiveSiteSortedModel();
QStringList allSiteNames() const;
void setFilter(const QString &text);
+ struct dive_site *getDiveSite(const QModelIndex &idx);
};
// To access only divesites at the given GPS coordinates with the exception of a given dive site