summaryrefslogtreecommitdiffstats
path: root/core/settings
diff options
context:
space:
mode:
authorGravatar jan Iversen <jani@apache.org>2019-01-18 08:07:00 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-12-27 04:03:25 +0900
commitfc7aec540242b874857cec16fd337e04f18675df (patch)
tree0b04ba51e2f7f4f83ba5d7e09552bc0187ded40f /core/settings
parent573a4a5e2da9531fbaa9e82da57131edc691a851 (diff)
downloadsubsurface-fc7aec540242b874857cec16fd337e04f18675df.tar.gz
core/settings: make qPrefUnit accesable from QML
Use string literals to communicate with QML. Instead of passing arounds enum/int value, it seems easier to pass string literals to QML and have that code respond to those Signed-off-by: Jan Iversen <jani@apache.org>
Diffstat (limited to 'core/settings')
-rw-r--r--core/settings/qPrefUnit.cpp95
-rw-r--r--core/settings/qPrefUnit.h51
2 files changed, 124 insertions, 22 deletions
diff --git a/core/settings/qPrefUnit.cpp b/core/settings/qPrefUnit.cpp
index 6704cb42f..8a2244c8b 100644
--- a/core/settings/qPrefUnit.cpp
+++ b/core/settings/qPrefUnit.cpp
@@ -28,15 +28,63 @@ void qPrefUnits::loadSync(bool doSync)
HANDLE_PREFERENCE_BOOL(Units, "coordinates", coordinates_traditional);
-HANDLE_PREFERENCE_ENUM_EXT(Units, units::DURATION, "duration_units", duration_units, units.);
+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)
+{
+ prefs.units.duration_units = value == QStringLiteral("hours") ? units::DURATION::ALWAYS_HOURS :
+ value == QStringLiteral("minutes")? units::DURATION::MINUTES_ONLY :
+ units::DURATION::MIXED;
+ disk_duration_units(true);
+ 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.);
-HANDLE_PREFERENCE_ENUM_EXT(Units, units::LENGTH, "length", length, units.);
+QString qPrefUnits::length()
+{
+ return prefs.units.length == units::LENGTH::METERS ? QStringLiteral("meters") : QStringLiteral("feet");
+}
+void qPrefUnits::set_length(const QString& value)
+{
+ prefs.units.length = value == QStringLiteral("meters") ? units::LENGTH::METERS : units::LENGTH::FEET;
+ disk_length(true);
+ emit instance()->lengthStringChanged(value);
+}
+SET_PREFERENCE_ENUM_EXT(Units, units::LENGTH, length, units.);
+DISK_LOADSYNC_ENUM_EXT(Units, "length", units::LENGTH, length, units.);
-HANDLE_PREFERENCE_ENUM_EXT(Units, units::PRESSURE, "pressure", pressure, units.);
+QString qPrefUnits::pressure()
+{
+ return prefs.units.pressure == units::PRESSURE::BAR ? QStringLiteral("bar") : QStringLiteral("psi");
+}
+void qPrefUnits::set_pressure(const QString& value)
+{
+ prefs.units.pressure = value == QStringLiteral("bar") ? units::PRESSURE::BAR : units::PRESSURE::PSI;
+ disk_pressure(true);
+ 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.);
-HANDLE_PREFERENCE_ENUM_EXT(Units, units::TEMPERATURE, "temperature", temperature, units.);
+QString qPrefUnits::temperature()
+{
+ return prefs.units.temperature == units::TEMPERATURE::CELSIUS ? QStringLiteral("celcius") : QStringLiteral("fahrenheit");
+}
+void qPrefUnits::set_temperature(const QString& value)
+{
+ prefs.units.temperature = value == QStringLiteral("celcius") ? units::TEMPERATURE::CELSIUS : units::TEMPERATURE::FAHRENHEIT;
+ disk_temperature(true);
+ 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()
{
@@ -63,8 +111,41 @@ void qPrefUnits::set_unit_system(const QString& value)
}
DISK_LOADSYNC_ENUM(Units, "unit_system", unit_system_values, unit_system);
-HANDLE_PREFERENCE_ENUM_EXT(Units, units::TIME, "vertical_speed_time", vertical_speed_time, units.);
+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)
+{
+ prefs.units.vertical_speed_time = value == QStringLiteral("minutes") ? units::TIME::MINUTES : units::TIME::SECONDS;
+ disk_vertical_speed_time(true);
+ 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.);
-HANDLE_PREFERENCE_ENUM_EXT(Units, units::VOLUME, "volume", volume, units.);
+QString qPrefUnits::volume()
+{
+ return prefs.units.volume == units::VOLUME::LITER ? QStringLiteral("liter") : QStringLiteral("cuft");
+}
+void qPrefUnits::set_volume(const QString& value)
+{
+ prefs.units.volume = value == QStringLiteral("liter") ? units::VOLUME::LITER : units::VOLUME::CUFT;
+ disk_volume(true);
+ emit instance()->volumeStringChanged(value);
+}
+SET_PREFERENCE_ENUM_EXT(Units, units::VOLUME, volume, units.);
+DISK_LOADSYNC_ENUM_EXT(Units, "volume", units::VOLUME, volume, units.);
-HANDLE_PREFERENCE_ENUM_EXT(Units, units::WEIGHT, "weight", weight, units.);
+QString qPrefUnits::weight()
+{
+ return prefs.units.weight == units::WEIGHT::KG ? QStringLiteral("kg") : QStringLiteral("lbs");
+}
+void qPrefUnits::set_weight(const QString& value)
+{
+ prefs.units.weight = value == QStringLiteral("kg") ? units::WEIGHT::KG : units::WEIGHT::LBS;
+ disk_weight(true);
+ 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 6a800fbfa..12adc33a2 100644
--- a/core/settings/qPrefUnit.h
+++ b/core/settings/qPrefUnit.h
@@ -9,15 +9,15 @@
class qPrefUnits : public QObject {
Q_OBJECT
Q_PROPERTY(bool coordinates_traditional READ coordinates_traditional WRITE set_coordinates_traditional NOTIFY coordinates_traditionalChanged)
- Q_PROPERTY(units::DURATION duration_units READ duration_units WRITE set_duration_units NOTIFY duration_unitsChanged)
- Q_PROPERTY(units::LENGTH length READ length WRITE set_length NOTIFY lengthChanged)
- Q_PROPERTY(units::PRESSURE pressure READ pressure WRITE set_pressure NOTIFY pressureChanged)
+ 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(units::TEMPERATURE temperature READ temperature WRITE set_temperature NOTIFY temperatureChanged)
+ 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_systemChanged)
- Q_PROPERTY(units::TIME vertical_speed_time READ vertical_speed_time WRITE set_vertical_speed_time NOTIFY vertical_speed_timeChanged)
- Q_PROPERTY(units::VOLUME volume READ volume WRITE set_volume NOTIFY volumeChanged)
- Q_PROPERTY(units::WEIGHT weight READ weight WRITE set_weight NOTIFY weightChanged)
+ 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,40 +29,61 @@ public:
public:
static bool coordinates_traditional() { return prefs.coordinates_traditional; }
- 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 QString duration_units();
+ static QString length();
+ static QString pressure();
static bool show_units_table() { return prefs.units.show_units_table; }
- static units::TEMPERATURE temperature() { return prefs.units.temperature; }
+ static QString temperature();
static QString unit_system();
- 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; }
+ static QString vertical_speed_time();
+ static QString volume();
+ static QString 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(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 show_units_tableChanged(bool value);
void temperatureChanged(int value);
+ void temperatureStringChanged(const QString& value);
void unit_systemChanged(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);
private:
qPrefUnits() {}