From 6e065506317e2595a0df19dba147576d392c9506 Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Tue, 7 Jan 2020 14:31:49 +0100 Subject: core/settings:: remove string functions for units Remove string version of unit_system, duration_units, length, pressure, temperature, vertical_speed_time, and volume, including tests and make signals strongly typed in C++ Signed-off-by: jan Iversen Signed-off-by: Dirk Hohndel --- core/settings/qPrefUnit.cpp | 94 ++------------------------------------------- 1 file changed, 3 insertions(+), 91 deletions(-) (limited to 'core/settings/qPrefUnit.cpp') diff --git a/core/settings/qPrefUnit.cpp b/core/settings/qPrefUnit.cpp index 8a3bb50f7..c4f32490f 100644 --- a/core/settings/qPrefUnit.cpp +++ b/core/settings/qPrefUnit.cpp @@ -28,75 +28,24 @@ void qPrefUnits::loadSync(bool doSync) HANDLE_PREFERENCE_BOOL(Units, "coordinates", coordinates_traditional); -QString qPrefUnits::duration_units() -{ - return prefs.units.duration_units == units::DURATION::ALWAYS_HOURS ? QStringLiteral("hours") : - prefs.units.duration_units == units::DURATION::MINUTES_ONLY ? QStringLiteral("minutes") : - QStringLiteral("mixed"); -} -void qPrefUnits::set_duration_units(const QString& value) -{ - set_duration_units(value == QStringLiteral("hours") ? units::DURATION::ALWAYS_HOURS : - value == QStringLiteral("minutes")? units::DURATION::MINUTES_ONLY : - units::DURATION::MIXED); - emit instance()->duration_unitsStringChanged(value); -} SET_PREFERENCE_ENUM_EXT(Units, units::DURATION, duration_units, units.); DISK_LOADSYNC_ENUM_EXT(Units, "duration_units", units::DURATION, duration_units, units.); -QString qPrefUnits::length() -{ - return prefs.units.length == units::LENGTH::METERS ? QStringLiteral("meters") : QStringLiteral("feet"); -} -void qPrefUnits::set_length(const QString& value) -{ - set_length(value == QStringLiteral("meters") ? units::LENGTH::METERS : units::LENGTH::FEET); - emit instance()->lengthStringChanged(value); -} SET_PREFERENCE_ENUM_EXT(Units, units::LENGTH, length, units.); DISK_LOADSYNC_ENUM_EXT(Units, "length", units::LENGTH, length, units.); -QString qPrefUnits::pressure() -{ - return prefs.units.pressure == units::PRESSURE::BAR ? QStringLiteral("bar") : QStringLiteral("psi"); -} -void qPrefUnits::set_pressure(const QString& value) -{ - set_pressure(value == QStringLiteral("bar") ? units::PRESSURE::BAR : units::PRESSURE::PSI); - emit instance()->pressureStringChanged(value); -} SET_PREFERENCE_ENUM_EXT(Units, units::PRESSURE, pressure, units.); DISK_LOADSYNC_ENUM_EXT(Units, "pressure", units::PRESSURE, pressure, units.); HANDLE_PREFERENCE_BOOL_EXT(Units, "show_units_table", show_units_table, units.); -QString qPrefUnits::temperature() -{ - return prefs.units.temperature == units::TEMPERATURE::CELSIUS ? QStringLiteral("celcius") : QStringLiteral("fahrenheit"); -} -void qPrefUnits::set_temperature(const QString& value) -{ - set_temperature(value == QStringLiteral("celcius") ? units::TEMPERATURE::CELSIUS : units::TEMPERATURE::FAHRENHEIT); - emit instance()->temperatureStringChanged(value); -} SET_PREFERENCE_ENUM_EXT(Units, units::TEMPERATURE, temperature, units.); DISK_LOADSYNC_ENUM_EXT(Units, "temperature", units::TEMPERATURE, temperature, units.); -QString qPrefUnits::unit_system() -{ - return prefs.unit_system == METRIC ? QStringLiteral("metric") : - prefs.unit_system == IMPERIAL ? QStringLiteral("imperial") : - QStringLiteral("personalized"); -} -void qPrefUnits::set_unit_system(const QString& value) -{ - set_unit_system(value == QStringLiteral("metric") ? METRIC : value == QStringLiteral("imperial")? IMPERIAL : PERSONALIZE); - emit instance()->unit_systemStringChanged(value); -} void qPrefUnits::set_unit_system(unit_system_values value) { - if (value == METRIC) { - prefs.unit_system = METRIC; + prefs.unit_system = value; + if (prefs.unit_system == METRIC) { prefs.units = SI_units; // make sure all types are updated when changing @@ -105,8 +54,7 @@ void qPrefUnits::set_unit_system(unit_system_values value) set_length(units::LENGTH::METERS); set_pressure(units::PRESSURE::BAR); set_temperature(units::TEMPERATURE::CELSIUS); - } else if (value == IMPERIAL) { - prefs.unit_system = IMPERIAL; + } else if (prefs.unit_system == IMPERIAL) { prefs.units = IMPERIAL_units; // make sure all types are updated when changing @@ -120,50 +68,14 @@ void qPrefUnits::set_unit_system(unit_system_values value) } disk_unit_system(true); emit instance()->unit_systemChanged(value); - emit instance()->unit_systemStringChanged(unit_system()); - emit instance()->volumeChanged(prefs.units.volume); - emit instance()->volumeStringChanged(volume()); - emit instance()->weightChanged(prefs.units.weight); - emit instance()->weightStringChanged(weight()); - emit instance()->lengthChanged(prefs.units.length); - emit instance()->lengthStringChanged(length()); - emit instance()->temperatureChanged(prefs.units.temperature); - emit instance()->temperatureStringChanged(temperature()); } DISK_LOADSYNC_ENUM(Units, "unit_system", unit_system_values, unit_system); -QString qPrefUnits::vertical_speed_time() -{ - return prefs.units.vertical_speed_time == units::TIME::MINUTES ? QStringLiteral("minutes") : QStringLiteral("seconds"); -} -void qPrefUnits::set_vertical_speed_time(const QString& value) -{ - set_vertical_speed_time(value == QStringLiteral("minutes") ? units::TIME::MINUTES : units::TIME::SECONDS); - emit instance()->vertical_speed_timeStringChanged(value); -} SET_PREFERENCE_ENUM_EXT(Units, units::TIME, vertical_speed_time, units.); DISK_LOADSYNC_ENUM_EXT(Units, "vertical_speed_time", units::TIME, vertical_speed_time, units.); -QString qPrefUnits::volume() -{ - return prefs.units.volume == units::VOLUME::LITER ? QStringLiteral("liter") : QStringLiteral("cuft"); -} -void qPrefUnits::set_volume(const QString& value) -{ - set_volume(value == QStringLiteral("liter") ? units::VOLUME::LITER : units::VOLUME::CUFT); - emit instance()->volumeStringChanged(value); -} SET_PREFERENCE_ENUM_EXT(Units, units::VOLUME, volume, units.); DISK_LOADSYNC_ENUM_EXT(Units, "volume", units::VOLUME, volume, units.); -QString qPrefUnits::weight() -{ - return prefs.units.weight == units::WEIGHT::KG ? QStringLiteral("kg") : QStringLiteral("lbs"); -} -void qPrefUnits::set_weight(const QString& value) -{ - set_weight(value == QStringLiteral("kg") ? units::WEIGHT::KG : units::WEIGHT::LBS); - emit instance()->weightStringChanged(value); -} SET_PREFERENCE_ENUM_EXT(Units, units::WEIGHT, weight, units.); DISK_LOADSYNC_ENUM_EXT(Units, "weight", units::WEIGHT, weight, units.); -- cgit v1.2.3-70-g09d2