mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Filter: split out filter from model
Split out the actual filtering from the MultiFilterSortModel. Create a DiveFilter class that does the actual filtering. Currently, mobile and desktop have their own version of this class, though ultimately we may want to merge them. The idea here is that the trip-model and undo-commands have direct access to the filter-function and thus can take care of keeping track of the number of shown dives, etc. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
6d6d10f03a
commit
b76f207158
16 changed files with 369 additions and 308 deletions
|
|
@ -10,6 +10,7 @@
|
|||
#include "desktop-widgets/mainwindow.h"
|
||||
#include "desktop-widgets/divepicturewidget.h"
|
||||
#include "core/display.h"
|
||||
#include "core/divefilter.h"
|
||||
#include <unistd.h>
|
||||
#include <QSettings>
|
||||
#include <QKeyEvent>
|
||||
|
|
@ -463,7 +464,7 @@ void DiveListView::selectDives(const QList<int> &newDiveSelection)
|
|||
// But don't do this if we are in divesite mode, because then
|
||||
// the dive-site selection is controlled by the filter not
|
||||
// by the selected dives.
|
||||
if (!MultiFilterSortModel::instance()->diveSiteMode()) {
|
||||
if (!DiveFilter::instance()->diveSiteMode()) {
|
||||
QVector<dive_site *> selectedSites;
|
||||
for (int idx: newDiveSelection) {
|
||||
dive *d = get_dive(idx);
|
||||
|
|
@ -698,7 +699,7 @@ void DiveListView::selectionChanged(const QItemSelection &selected, const QItemS
|
|||
// But don't do this if we are in divesite mode, because then
|
||||
// the dive-site selection is controlled by the filter not
|
||||
// by the selected dives.
|
||||
if (!MultiFilterSortModel::instance()->diveSiteMode()) {
|
||||
if (!DiveFilter::instance()->diveSiteMode()) {
|
||||
QVector<dive_site *> selectedSites;
|
||||
for (QModelIndex index: selectionModel()->selection().indexes()) {
|
||||
const QAbstractItemModel *model = index.model();
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include "core/save-html.h"
|
||||
#include "core/settings/qPrefDisplay.h"
|
||||
#include "core/save-profiledata.h"
|
||||
#include "core/divefilter.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/errorhelper.h"
|
||||
#include "core/file.h"
|
||||
|
|
@ -134,10 +135,10 @@ static std::vector<const dive_site *> getDiveSitesToExport(bool selectedOnly)
|
|||
{
|
||||
std::vector<const dive_site *> res;
|
||||
|
||||
if (selectedOnly && MultiFilterSortModel::instance()->diveSiteMode()) {
|
||||
if (selectedOnly && DiveFilter::instance()->diveSiteMode()) {
|
||||
// Special case in dive site mode: export all selected dive sites,
|
||||
// not the dive sites of selected dives.
|
||||
QVector<dive_site *> sites = MultiFilterSortModel::instance()->filteredDiveSites();
|
||||
QVector<dive_site *> sites = DiveFilter::instance()->filteredDiveSites();
|
||||
res.reserve(sites.size());
|
||||
for (const dive_site *ds: sites)
|
||||
res.push_back(ds);
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ void FilterWidget2::hideEvent(QHideEvent *event)
|
|||
|
||||
void FilterWidget2::filterDataChanged(const FilterData &data)
|
||||
{
|
||||
MultiFilterSortModel::instance()->filterDataChanged(data);
|
||||
DiveFilter::instance()->setFilter(data);
|
||||
}
|
||||
|
||||
QString FilterWidget2::shownText()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#include <memory>
|
||||
|
||||
#include "ui_filterwidget2.h"
|
||||
#include "qt-models/filtermodels.h"
|
||||
#include "core/divefilter.h"
|
||||
|
||||
namespace Ui {
|
||||
class FilterWidget2;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include "desktop-widgets/divelistview.h"
|
||||
#include "core/qthelper.h"
|
||||
#include "desktop-widgets/mapwidget.h"
|
||||
#include "qt-models/filtermodels.h"
|
||||
#include "core/divefilter.h"
|
||||
#include "core/divesitehelpers.h"
|
||||
#include "desktop-widgets/modeldelegates.h"
|
||||
#include "core/subsurface-qt/DiveListNotifier.h"
|
||||
|
|
@ -194,7 +194,7 @@ void LocationInformationWidget::acceptChanges()
|
|||
MainWindow::instance()->diveList->setEnabled(true);
|
||||
MainWindow::instance()->setEnabledToolbar(true);
|
||||
MainWindow::instance()->setApplicationState(ApplicationState::Default);
|
||||
MultiFilterSortModel::instance()->stopFilterDiveSites();
|
||||
DiveFilter::instance()->stopFilterDiveSites();
|
||||
|
||||
// Subtlety alert: diveSite must be cleared *after* exiting the dive-site mode.
|
||||
// Exiting dive-site mode removes the focus from the active widget and
|
||||
|
|
@ -211,7 +211,7 @@ void LocationInformationWidget::initFields(dive_site *ds)
|
|||
filter_model.set(ds, ds->location);
|
||||
updateLabels();
|
||||
enableLocationButtons(dive_site_has_gps_location(ds));
|
||||
MultiFilterSortModel::instance()->startFilterDiveSites(QVector<dive_site *>{ ds });
|
||||
DiveFilter::instance()->startFilterDiveSites(QVector<dive_site *>{ ds });
|
||||
filter_model.invalidate();
|
||||
} else {
|
||||
filter_model.set(0, location_t { degrees_t{ 0 }, degrees_t{ 0 } });
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#include "desktop-widgets/filterwidget2.h"
|
||||
#include "core/applicationstate.h"
|
||||
#include "core/gpslocation.h"
|
||||
#include "core/dive.h"
|
||||
|
||||
#define NUM_RECENT_FILES 4
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
#include "TabDiveSite.h"
|
||||
#include "core/subsurface-qt/DiveListNotifier.h"
|
||||
#include "core/divesite.h"
|
||||
#include "core/divefilter.h"
|
||||
#include "qt-models/divelocationmodel.h"
|
||||
#include "qt-models/filtermodels.h"
|
||||
#include "commands/command.h"
|
||||
|
||||
#include <qt-models/divecomputerextradatamodel.h>
|
||||
|
|
@ -97,18 +97,18 @@ QVector<dive_site *> TabDiveSite::selectedDiveSites()
|
|||
|
||||
void TabDiveSite::selectionChanged(const QItemSelection &, const QItemSelection &)
|
||||
{
|
||||
MultiFilterSortModel::instance()->setFilterDiveSite(selectedDiveSites());
|
||||
DiveFilter::instance()->setFilterDiveSite(selectedDiveSites());
|
||||
}
|
||||
|
||||
void TabDiveSite::showEvent(QShowEvent *)
|
||||
{
|
||||
// If the user switches to the dive site tab and there was already a selection,
|
||||
// filter on that selection.
|
||||
MultiFilterSortModel::instance()->startFilterDiveSites(selectedDiveSites());
|
||||
DiveFilter::instance()->startFilterDiveSites(selectedDiveSites());
|
||||
}
|
||||
|
||||
void TabDiveSite::hideEvent(QHideEvent *)
|
||||
{
|
||||
// If the user switches to a different tab, stop the dive site filtering
|
||||
MultiFilterSortModel::instance()->stopFilterDiveSites();
|
||||
DiveFilter::instance()->stopFilterDiveSites();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue