Filter: support imperial units

1) Choose the correct conversion function for comparison.
2) Add a unit suffix to the fields.
3) Update the suffixes on change of preferences.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-01-20 21:01:00 +01:00 committed by Dirk Hohndel
parent e8b0d165a7
commit b28e0bf0b9
3 changed files with 23 additions and 4 deletions

View file

@ -1,5 +1,7 @@
#include "desktop-widgets/filterwidget2.h" #include "desktop-widgets/filterwidget2.h"
#include "desktop-widgets/simplewidgets.h" #include "desktop-widgets/simplewidgets.h"
#include "core/qthelper.h"
#include "core/settings/qPrefUnit.h"
#include <QDoubleSpinBox> #include <QDoubleSpinBox>
@ -32,6 +34,9 @@ FilterWidget2::FilterWidget2(QWidget* parent) : QWidget(parent)
ui.toDate->setDate(data.toDate.date()); ui.toDate->setDate(data.toDate.date());
ui.toTime->setTime(data.toTime); ui.toTime->setTime(data.toTime);
// Initialize temperature fields to display correct unit.
temperatureChanged();
connect(ui.maxRating, &StarWidget::valueChanged, connect(ui.maxRating, &StarWidget::valueChanged,
this, &FilterWidget2::updateFilter); this, &FilterWidget2::updateFilter);
@ -80,6 +85,19 @@ FilterWidget2::FilterWidget2(QWidget* parent) : QWidget(parent)
connect(ui.logged, SIGNAL(stateChanged(int)), this, SLOT(updateLogged(int))); connect(ui.logged, SIGNAL(stateChanged(int)), this, SLOT(updateLogged(int)));
connect(ui.planned, SIGNAL(stateChanged(int)), this, SLOT(updatePlanned(int))); connect(ui.planned, SIGNAL(stateChanged(int)), this, SLOT(updatePlanned(int)));
// Update temperature fields if user changes temperature-units in preferences.
connect(qPrefUnits::instance(), &qPrefUnits::temperatureChanged, this, &FilterWidget2::temperatureChanged);
connect(qPrefUnits::instance(), &qPrefUnits::unit_systemChanged, this, &FilterWidget2::temperatureChanged);
}
void FilterWidget2::temperatureChanged()
{
QString temp = get_temp_unit();
ui.minAirTemp->setSuffix(temp);
ui.maxAirTemp->setSuffix(temp);
ui.minWaterTemp->setSuffix(temp);
ui.maxWaterTemp->setSuffix(temp);
} }
void FilterWidget2::updateFilter() void FilterWidget2::updateFilter()

View file

@ -27,6 +27,8 @@ protected:
public slots: public slots:
void updatePlanned(int value); void updatePlanned(int value);
void updateLogged(int value); void updateLogged(int value);
private slots:
void temperatureChanged();
private: private:
Ui::FilterWidget2 ui; Ui::FilterWidget2 ui;

View file

@ -104,14 +104,13 @@ bool MultiFilterSortModel::showDive(const struct dive *d) const
if (d->rating < filterData.minRating || d->rating > filterData.maxRating) if (d->rating < filterData.minRating || d->rating > filterData.maxRating)
return false; return false;
// TODO: get the preferences for the imperial vs metric data. auto temp_comp = prefs.units.temperature == units::CELSIUS ? C_to_mkelvin : F_to_mkelvin;
// ignore the check if it doesn't makes sense.
if (d->watertemp.mkelvin && if (d->watertemp.mkelvin &&
(d->watertemp.mkelvin < C_to_mkelvin(filterData.minWaterTemp) || d->watertemp.mkelvin > C_to_mkelvin((filterData.maxWaterTemp)))) (d->watertemp.mkelvin < (*temp_comp)(filterData.minWaterTemp) || d->watertemp.mkelvin > (*temp_comp)(filterData.maxWaterTemp)))
return false; return false;
if (d->airtemp.mkelvin && if (d->airtemp.mkelvin &&
(d->airtemp.mkelvin < C_to_mkelvin(filterData.minAirTemp) || d->airtemp.mkelvin > C_to_mkelvin(filterData.maxAirTemp))) (d->airtemp.mkelvin < (*temp_comp)(filterData.minAirTemp) || d->airtemp.mkelvin > (*temp_comp)(filterData.maxAirTemp)))
return false; return false;
QDateTime t = filterData.fromDate; QDateTime t = filterData.fromDate;