summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/filterwidget2.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-04-22 00:05:52 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-04-24 10:05:27 -0700
commit89784a176efb52558b3fa103401fd7d8d2be0fe5 (patch)
tree5c5e124c30f4ee76103748b02fda2ceac7b3dac8 /desktop-widgets/filterwidget2.cpp
parent9b8eed7821c7e55c5e2eccd252184a6d2123e3cd (diff)
downloadsubsurface-89784a176efb52558b3fa103401fd7d8d2be0fe5.tar.gz
filter: implement filtering for divemode
This only checks the first divecomputer as the semantics for multiple dive computers with different dive modes are not clear. Should we check them all? The implementation is a bit hackish: the indexes [0...n] of the combobox are mapped onto [-1...n-1], where -1 means don't filter and n-1 is the last valid dive mode. Implements #2329 Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/filterwidget2.cpp')
-rw-r--r--desktop-widgets/filterwidget2.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/desktop-widgets/filterwidget2.cpp b/desktop-widgets/filterwidget2.cpp
index 2dee9979b..6d90ae0b3 100644
--- a/desktop-widgets/filterwidget2.cpp
+++ b/desktop-widgets/filterwidget2.cpp
@@ -21,6 +21,13 @@ FilterWidget2::FilterWidget2(QWidget* parent) :
ui.minWaterTemp->setRange(data.minWaterTemp, data.maxWaterTemp);
ui.maxWaterTemp->setRange(data.minWaterTemp, data.maxWaterTemp);
+ // This needs to be the same order as enum dive_comp_type in dive.h!
+ QStringList types;
+ types.append(""); // Empty means don't filter on dive mode
+ for (int i = 0; i < NUM_DIVEMODE; i++)
+ types.append(gettextFromC::tr(divemode_text_ui[i]));
+ ui.diveMode->insertItems(0, types);
+
// TODO: unhide this when we discover how to search for equipment.
ui.equipment->hide();
ui.equipmentMode->hide();
@@ -135,6 +142,9 @@ FilterWidget2::FilterWidget2(QWidget* parent) :
connect(ui.planned, &QCheckBox::stateChanged,
this, &FilterWidget2::updatePlanned);
+ connect(ui.diveMode, QOverload<int>::of(&QComboBox::currentIndexChanged),
+ this, &FilterWidget2::updateFilter);
+
// Update temperature fields if user changes temperature-units in preferences.
connect(qPrefUnits::instance(), &qPrefUnits::temperatureChanged,
this, &FilterWidget2::temperatureChanged);
@@ -183,6 +193,7 @@ void FilterWidget2::clearFilter()
ui.suitStringMode->setCurrentIndex((int)filterData.suitStringMode);
ui.dnotesStringMode->setCurrentIndex((int)filterData.dnotesStringMode);
ui.equipmentStringMode->setCurrentIndex((int)filterData.equipmentStringMode);
+ ui.diveMode->setCurrentIndex(filterData.diveMode + 1); // -1 means don't filter, transform that into index 0
ignoreSignal = false;
@@ -243,6 +254,7 @@ void FilterWidget2::updateFilter()
filterData.equipmentStringMode = (StringFilterMode)ui.equipmentStringMode->currentIndex();
filterData.logged = ui.logged->isChecked();
filterData.planned = ui.planned->isChecked();
+ filterData.diveMode = ui.diveMode->currentIndex() - 1; // The first entry means don't filter, transform that to -1.
filterDataChanged(filterData);
}