mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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>
This commit is contained in:
parent
afde4dce0d
commit
8695d8bdb1
3 changed files with 37 additions and 1 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue