aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar jan Iversen <jan@casacondor.com>2020-01-07 14:31:49 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-01-20 09:55:26 -0800
commit6e065506317e2595a0df19dba147576d392c9506 (patch)
tree9061a855826df17a5acf6cb4b207c205694db7dd /core
parent13b2b9f19c3f9ecb41565c5eab07d590071dede6 (diff)
downloadsubsurface-6e065506317e2595a0df19dba147576d392c9506.tar.gz
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 <jan@casacondor.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r--core/settings/qPrefUnit.cpp94
-rw-r--r--core/settings/qPrefUnit.h66
2 files changed, 20 insertions, 140 deletions
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.);
diff --git a/core/settings/qPrefUnit.h b/core/settings/qPrefUnit.h
index 467117ef2..5e81bd77a 100644
--- a/core/settings/qPrefUnit.h
+++ b/core/settings/qPrefUnit.h
@@ -9,15 +9,7 @@
class qPrefUnits : public QObject {
Q_OBJECT
Q_PROPERTY(bool coordinates_traditional READ coordinates_traditional WRITE set_coordinates_traditional NOTIFY coordinates_traditionalChanged)
- Q_PROPERTY(QString duration_units READ duration_units WRITE set_duration_units NOTIFY duration_unitsStringChanged)
- Q_PROPERTY(QString length READ length WRITE set_length NOTIFY lengthStringChanged)
- Q_PROPERTY(QString pressure READ pressure WRITE set_pressure NOTIFY pressureStringChanged)
Q_PROPERTY(bool show_units_table READ show_units_table WRITE set_show_units_table NOTIFY show_units_tableChanged)
- Q_PROPERTY(QString temperature READ temperature WRITE set_temperature NOTIFY temperatureStringChanged)
- Q_PROPERTY(QString unit_system READ unit_system WRITE set_unit_system NOTIFY unit_systemStringChanged)
- Q_PROPERTY(QString vertical_speed_time READ vertical_speed_time WRITE set_vertical_speed_time NOTIFY vertical_speed_timeStringChanged)
- Q_PROPERTY(QString volume READ volume WRITE set_volume NOTIFY volumeStringChanged)
- Q_PROPERTY(QString weight READ weight WRITE set_weight NOTIFY weightStringChanged)
public:
static qPrefUnits *instance();
@@ -29,63 +21,40 @@ public:
public:
static bool coordinates_traditional() { return prefs.coordinates_traditional; }
- static QString duration_units();
- static QString length();
- static QString pressure();
+ static units::DURATION duration_units() { return prefs.units.duration_units; }
+ static units::LENGTH length() { return prefs.units.length; }
+ static units::PRESSURE pressure() { return prefs.units.pressure; }
static bool show_units_table() { return prefs.units.show_units_table; }
- static QString temperature();
- static QString unit_system();
- static QString vertical_speed_time();
- static QString volume();
- static QString weight();
+ static unit_system_values unit_system() { return prefs.unit_system; }
+ static units::TEMPERATURE temperature() { return prefs.units.temperature; }
+ static units::TIME vertical_speed_time() { return prefs.units.vertical_speed_time; }
+ static units::VOLUME volume() { return prefs.units.volume; }
+ static units::WEIGHT weight() { return prefs.units.weight; }
public slots:
static void set_coordinates_traditional(bool value);
static void set_duration_units(units::DURATION value);
- static void set_duration_units(const QString& value);
static void set_length(units::LENGTH value);
- static void set_length(const QString& value);
static void set_pressure(units::PRESSURE value);
- static void set_pressure(const QString& value);
static void set_show_units_table(bool value);
static void set_temperature(units::TEMPERATURE value);
- static void set_temperature(const QString& value);
static void set_unit_system(unit_system_values value);
- static void set_unit_system(const QString& value);
static void set_vertical_speed_time(units::TIME value);
- static void set_vertical_speed_time(const QString& value);
static void set_volume(units::VOLUME value);
- static void set_volume(const QString& value);
static void set_weight(units::WEIGHT value);
- static void set_weight(const QString& value);
signals:
- // Normally the same signal name are used with different parameters:
- // void weightChanged(int value);
- // void weightChanged(const QString& value);
- // This works perfect, however connect() cannot automatically determine
- // which signal to catch, for that purpose SIGNAL() / SLOT() macros are used,
- // since they include the parameter type.
- // However there is a design decision, not to use the macros, so
- // signal must have unique names.
void coordinates_traditionalChanged(bool value);
- void duration_unitsChanged(int value);
- void duration_unitsStringChanged(const QString& value);
- void lengthChanged(int value);
- void lengthStringChanged(const QString& value);
- void pressureChanged(int value);
- void pressureStringChanged(const QString& value);
+ void duration_unitsChanged(units::DURATION value);
+ void lengthChanged(units::LENGTH value);
+ void pressureChanged(units::PRESSURE value);
void show_units_tableChanged(bool value);
- void temperatureChanged(int value);
- void temperatureStringChanged(const QString& value);
- void unit_systemChanged(int value);
- void unit_systemStringChanged(const QString& value);
- void vertical_speed_timeChanged(int value);
- void vertical_speed_timeStringChanged(const QString& value);
- void volumeChanged(int value);
- void volumeStringChanged(const QString& value);
- void weightChanged(int value);
- void weightStringChanged(const QString& value);
+ void temperatureChanged(units::TEMPERATURE value);
+ void unit_systemChanged(unit_system_values value);
+ void vertical_speed_timeChanged(units::TIME value);
+ void volumeChanged(units::VOLUME value);
+ void weightChanged(units::WEIGHT value);
+
private:
qPrefUnits() {}
@@ -100,5 +69,4 @@ private:
static void disk_volume(bool doSync);
static void disk_weight(bool doSync);
};
-
#endif