From 123f3ef7ec8f977c9949c3ac24008163c722e208 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Tue, 1 Jan 2019 18:49:56 +0100 Subject: Filter for logged/planned dives Add filter for dives having a planned dive computer or a logged dive computer. Signed-off-by: Robert C. Helling --- CHANGELOG.md | 1 + core/dive.c | 12 ++ core/dive.h | 2 + desktop-widgets/filterwidget2.cpp | 22 ++++ desktop-widgets/filterwidget2.h | 6 + desktop-widgets/filterwidget2.ui | 260 ++++++++++++++++++++------------------ qt-models/filtermodels.cpp | 6 + qt-models/filtermodels.h | 2 + 8 files changed, 191 insertions(+), 120 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3746d168..d72f17cba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- Allow to filter for logged/planned dives - Core, Windows: fix a bug related to non-ASCII characters in user names - Shearwater import: add suppport for importing Shearwater Cloud logs - Core, Mobile: all controller states other than powered off are valid [#1903] diff --git a/core/dive.c b/core/dive.c index 0ec9e381c..36d05dad5 100644 --- a/core/dive.c +++ b/core/dive.c @@ -3361,6 +3361,18 @@ bool is_dc_planner(const struct divecomputer *dc) { return same_string(dc->model, "planned dive"); } +// Does this dive have a dive computer for which is_dc_planner has value planned +bool has_planned(const struct dive *dive, bool planned) { + const struct divecomputer *dc = &dive->dc; + + while (dc) { + if (is_dc_planner(&dive->dc) == planned) + return true; + dc = dc->next; + } + return false; +} + /* * Merging two dives can be subtle, because there's two different ways * of merging: diff --git a/core/dive.h b/core/dive.h index f447c88b5..a93020507 100644 --- a/core/dive.h +++ b/core/dive.h @@ -653,6 +653,8 @@ extern void vpmb_start_gradient(struct deco_state *ds); extern void vpmb_next_gradient(struct deco_state *ds, double deco_time, double surface_pressure); extern double tissue_tolerance_calc(struct deco_state *ds, const struct dive *dive, double pressure); extern bool is_dc_planner(const struct divecomputer *dc); +extern bool has_planned(const struct dive *dive, bool planned); + /* this should be converted to use our types */ struct divedatapoint { diff --git a/desktop-widgets/filterwidget2.cpp b/desktop-widgets/filterwidget2.cpp index d120ffe4d..b2f74d742 100644 --- a/desktop-widgets/filterwidget2.cpp +++ b/desktop-widgets/filterwidget2.cpp @@ -18,6 +18,8 @@ FilterWidget2::FilterWidget2(QWidget* parent) ui->maxAirTemp->setValue(data.maxAirTemp); ui->minWaterTemp->setValue(data.minWaterTemp); ui->maxWaterTemp->setValue(data.maxWaterTemp); + ui->planned->setChecked(data.logged); + ui->planned->setChecked(data.planned); // TODO: unhide this when we discover how to search for equipment. ui->equipment->hide(); @@ -64,6 +66,11 @@ FilterWidget2::FilterWidget2(QWidget* parent) connect(ui->location, &QLineEdit::textChanged, this, &FilterWidget2::updateFilter); + + connect(ui->logged, SIGNAL(stateChanged(int)), this, SLOT(updateLogged(int))); + + connect(ui->planned, SIGNAL(stateChanged(int)), this, SLOT(updatePlanned(int))); + } void FilterWidget2::updateFilter() @@ -86,11 +93,26 @@ void FilterWidget2::updateFilter() data.location = ui->location->text().split(",", QString::SkipEmptyParts); data.equipment = ui->equipment->text().split(",", QString::SkipEmptyParts); data.invertFilter = ui->invertFilter->isChecked(); + data.logged = ui->logged->isChecked(); + data.planned = ui->planned->isChecked(); filterData = data; emit filterDataChanged(data); } +void FilterWidget2::updateLogged(int value) { + if (value == Qt::Unchecked) + ui->planned->setChecked(true); + updateFilter(); +} + +void FilterWidget2::updatePlanned(int value) { + if (value == Qt::Unchecked) + ui->logged->setChecked(true); + updateFilter(); +} + + void FilterWidget2::showEvent(QShowEvent *event) { QWidget::showEvent(event); diff --git a/desktop-widgets/filterwidget2.h b/desktop-widgets/filterwidget2.h index 80629f0cc..fba012095 100644 --- a/desktop-widgets/filterwidget2.h +++ b/desktop-widgets/filterwidget2.h @@ -27,6 +27,12 @@ protected: signals: void filterDataChanged(const FilterData& data); +public slots: + void updatePlanned(int value); + void updateLogged(int value); + + + private: std::unique_ptr ui; FilterData filterData; diff --git a/desktop-widgets/filterwidget2.ui b/desktop-widgets/filterwidget2.ui index 978dafc6e..b8d5af48a 100644 --- a/desktop-widgets/filterwidget2.ui +++ b/desktop-widgets/filterwidget2.ui @@ -7,53 +7,34 @@ 0 0 510 - 320 + 349 Form - - + + + + + Min - - - - - 0 - 0 - - - - Qt::TabFocus - - - - - - - - - - - 0 - 0 - - - - Qt::TabFocus + + + + People - - + + - Tags + Max @@ -64,44 +45,17 @@ - - - - - 0 - 0 - - - - Qt::TabFocus - - - - - - People - - - - - - - Max - - - - - + - Min + Tags - - + + - + Display dives that will not match the search, only applies to tags, people, location and equipment @@ -118,32 +72,48 @@ - - + + + + Min + + - - + + + + From + + - - - - - 0 - 0 - + + + + To - - Qt::TabFocus + + + + + + Min - - + + - Equipment + Visibility + + + + + + + Min @@ -154,83 +124,133 @@ - - + + + + + - Location + Equipment - - + + - - + + - + - - + + - From + Water Temp - - + + + + + - To + Max - - + + + + + - Visibility + Location - - + + + + + - Water Temp + Air Temp - - - - Min + + + + + 0 + 0 + + + + Qt::TabFocus - - - - Air Temp + + + + + 0 + 0 + + + + Qt::TabFocus - - - - Min + + + + + 0 + 0 + + + + Qt::TabFocus - - - - Max + + + + + 0 + 0 + + + + Qt::TabFocus - - + + + + Logged + + + true + + - - + + + + Planned + + + true + + diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp index 4e4134033..8609243b2 100644 --- a/qt-models/filtermodels.cpp +++ b/qt-models/filtermodels.cpp @@ -138,6 +138,12 @@ bool MultiFilterSortModel::showDive(const struct dive *d) const if (!hasEquipment(filterData.equipment, d)) return false; + // Planned/Logged + if (!filterData.logged && !has_planned(d, true)) + return false; + if (!filterData.planned && !has_planned(d, false)) + return false; + return true; } diff --git a/qt-models/filtermodels.h b/qt-models/filtermodels.h index a8a601ecc..b16ce4a3b 100644 --- a/qt-models/filtermodels.h +++ b/qt-models/filtermodels.h @@ -30,6 +30,8 @@ struct FilterData { QStringList people; QStringList location; QStringList equipment; + bool logged = true; + bool planned = true; bool invertFilter; }; -- cgit v1.2.3-70-g09d2