mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 21:23:24 +00:00
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>
This commit is contained in:
parent
5aacd73a00
commit
afde4dce0d
3 changed files with 15 additions and 15 deletions
|
@ -184,7 +184,7 @@ void LocationInformationWidget::acceptChanges()
|
||||||
MainWindow::instance()->setApplicationState("Default");
|
MainWindow::instance()->setApplicationState("Default");
|
||||||
MapWidget::instance()->endGetDiveCoordinates();
|
MapWidget::instance()->endGetDiveCoordinates();
|
||||||
MapWidget::instance()->repopulateLabels();
|
MapWidget::instance()->repopulateLabels();
|
||||||
MultiFilterSortModel::instance()->stopFilterDiveSite();
|
MultiFilterSortModel::instance()->stopFilterDiveSites();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationInformationWidget::initFields(dive_site *ds)
|
void LocationInformationWidget::initFields(dive_site *ds)
|
||||||
|
@ -195,7 +195,7 @@ void LocationInformationWidget::initFields(dive_site *ds)
|
||||||
updateLabels();
|
updateLabels();
|
||||||
enableLocationButtons(dive_site_has_gps_location(ds));
|
enableLocationButtons(dive_site_has_gps_location(ds));
|
||||||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(ui.diveSiteListView->model());
|
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(ui.diveSiteListView->model());
|
||||||
MultiFilterSortModel::instance()->startFilterDiveSite(ds);
|
MultiFilterSortModel::instance()->startFilterDiveSites(QVector<dive_site *>{ ds });
|
||||||
if (m)
|
if (m)
|
||||||
m->invalidate();
|
m->invalidate();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -105,8 +105,7 @@ MultiFilterSortModel *MultiFilterSortModel::instance()
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiFilterSortModel::MultiFilterSortModel(QObject *parent) : QSortFilterProxyModel(parent),
|
MultiFilterSortModel::MultiFilterSortModel(QObject *parent) : QSortFilterProxyModel(parent),
|
||||||
divesDisplayed(0),
|
divesDisplayed(0)
|
||||||
curr_dive_site(NULL)
|
|
||||||
{
|
{
|
||||||
setFilterKeyColumn(-1); // filter all columns
|
setFilterKeyColumn(-1); // filter all columns
|
||||||
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
@ -125,9 +124,9 @@ void MultiFilterSortModel::resetModel(DiveTripModelBase::Layout layout)
|
||||||
|
|
||||||
bool MultiFilterSortModel::showDive(const struct dive *d) const
|
bool MultiFilterSortModel::showDive(const struct dive *d) const
|
||||||
{
|
{
|
||||||
// If curr_dive_site is set, we are in a special dive-site editing mode.
|
// If dive_sites is not empty, we are in a special dive-site filtering mode.
|
||||||
if (curr_dive_site)
|
if (!dive_sites.isEmpty())
|
||||||
return d->dive_site == curr_dive_site;
|
return dive_sites.contains(d->dive_site);
|
||||||
|
|
||||||
if (!filterData.validFilter)
|
if (!filterData.validFilter)
|
||||||
return true;
|
return true;
|
||||||
|
@ -245,7 +244,7 @@ void MultiFilterSortModel::myInvalidate()
|
||||||
emit filterFinished();
|
emit filterFinished();
|
||||||
|
|
||||||
#if !defined(SUBSURFACE_MOBILE)
|
#if !defined(SUBSURFACE_MOBILE)
|
||||||
if (curr_dive_site)
|
if (!dive_sites.isEmpty())
|
||||||
MainWindow::instance()->diveList->expandAll();
|
MainWindow::instance()->diveList->expandAll();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -267,15 +266,15 @@ void MultiFilterSortModel::clearFilter()
|
||||||
myInvalidate();
|
myInvalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiFilterSortModel::startFilterDiveSite(struct dive_site *ds)
|
void MultiFilterSortModel::startFilterDiveSites(QVector<dive_site *> ds)
|
||||||
{
|
{
|
||||||
curr_dive_site = ds;
|
dive_sites = ds;
|
||||||
myInvalidate();
|
myInvalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiFilterSortModel::stopFilterDiveSite()
|
void MultiFilterSortModel::stopFilterDiveSites()
|
||||||
{
|
{
|
||||||
curr_dive_site = NULL;
|
dive_sites.clear();
|
||||||
myInvalidate();
|
myInvalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,8 +67,8 @@ public
|
||||||
slots:
|
slots:
|
||||||
void myInvalidate();
|
void myInvalidate();
|
||||||
void clearFilter();
|
void clearFilter();
|
||||||
void startFilterDiveSite(struct dive_site *ds);
|
void startFilterDiveSites(QVector<dive_site *> ds);
|
||||||
void stopFilterDiveSite();
|
void stopFilterDiveSites();
|
||||||
void filterChanged(const QModelIndex &from, const QModelIndex &to, const QVector<int> &roles);
|
void filterChanged(const QModelIndex &from, const QModelIndex &to, const QVector<int> &roles);
|
||||||
void resetModel(DiveTripModelBase::Layout layout);
|
void resetModel(DiveTripModelBase::Layout layout);
|
||||||
void filterDataChanged(const FilterData &data);
|
void filterDataChanged(const FilterData &data);
|
||||||
|
@ -80,7 +80,8 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MultiFilterSortModel(QObject *parent = 0);
|
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();
|
void countsChanged();
|
||||||
FilterData filterData;
|
FilterData filterData;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue