From b28e0bf0b9bf9ae0613aec25440eff2e2a7e85c3 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 20 Jan 2019 21:01:00 +0100 Subject: 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 --- qt-models/filtermodels.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'qt-models') diff --git a/qt-models/filtermodels.cpp b/qt-models/filtermodels.cpp index 6efac8348..53149eba2 100644 --- a/qt-models/filtermodels.cpp +++ b/qt-models/filtermodels.cpp @@ -104,14 +104,13 @@ bool MultiFilterSortModel::showDive(const struct dive *d) const if (d->rating < filterData.minRating || d->rating > filterData.maxRating) return false; - // TODO: get the preferences for the imperial vs metric data. - // ignore the check if it doesn't makes sense. + auto temp_comp = prefs.units.temperature == units::CELSIUS ? C_to_mkelvin : F_to_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; 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; QDateTime t = filterData.fromDate; -- cgit v1.2.3-70-g09d2