summaryrefslogtreecommitdiffstats
path: root/core/settings/qPrefUnit.cpp
diff options
context:
space:
mode:
authorGravatar jan Iversen <jani@apache.org>2018-07-31 15:04:12 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-08-02 08:59:56 -0700
commit54335e1ec680216bc0fd15fa880e7dbc23d098a6 (patch)
treec8f4c5e4c6f63babfea75e000ea8492ef61d74c8 /core/settings/qPrefUnit.cpp
parent470b41e595419a01127f98845a59c5d65a41c73d (diff)
downloadsubsurface-54335e1ec680216bc0fd15fa880e7dbc23d098a6.tar.gz
core: create qPrefUnit from SettingsObjectWrapper
Update set/get functions to follow common name scheme: - get function have same name as in struct diveComputer - set function have set_<name> - signal function have <name>_changed one class one .h/.cpp is the C++ idiom. Having load/sync of each variable in 1 functions (in contrast to the distributed way SettingsObjectWrapper handles it) secures the same storage name is used. Having the set/get/load/sync functions grouped together makes it easier to get an overview. REMARK: this commit only defines the class, it is not active in production Signed-off-by: Jan Iversen <jani@apache.org>
Diffstat (limited to 'core/settings/qPrefUnit.cpp')
-rw-r--r--core/settings/qPrefUnit.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/core/settings/qPrefUnit.cpp b/core/settings/qPrefUnit.cpp
new file mode 100644
index 000000000..b0b45a881
--- /dev/null
+++ b/core/settings/qPrefUnit.cpp
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "qPref.h"
+#include "qPrefPrivate.h"
+
+
+static const QString group = QStringLiteral("Units");
+
+qPrefUnits::qPrefUnits(QObject *parent) : QObject(parent)
+{
+}
+qPrefUnits *qPrefUnits::instance()
+{
+ static qPrefUnits *self = new qPrefUnits;
+ return self;
+}
+
+
+void qPrefUnits::loadSync(bool doSync)
+{
+ disk_coordinates_traditional(doSync);
+ disk_duration_units(doSync);
+ disk_length(doSync);
+ disk_pressure(doSync);
+ disk_show_units_table(doSync);
+ disk_temperature(doSync);
+ disk_unit_system(doSync);
+ disk_vertical_speed_time(doSync);
+ disk_volume(doSync);
+ disk_weight(doSync);
+}
+
+HANDLE_PREFERENCE_BOOL(Units, "/coordinates", coordinates_traditional);
+
+HANDLE_PREFERENCE_ENUM_EXT(Units, units::DURATION, "/duration_units", duration_units, units.);
+
+HANDLE_PREFERENCE_ENUM_EXT(Units, units::LENGTH, "/length", length, units.);
+
+HANDLE_PREFERENCE_ENUM_EXT(Units, units::PRESSURE, "/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::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)
+{
+ short int v = value == QStringLiteral("metric") ? METRIC :
+ value == QStringLiteral("imperial")? IMPERIAL :
+ PERSONALIZE;
+ if (v != prefs.unit_system) {
+ if (v == METRIC) {
+ prefs.unit_system = METRIC;
+ prefs.units = SI_units;
+ } else if (v == IMPERIAL) {
+ prefs.unit_system = IMPERIAL;
+ prefs.units = IMPERIAL_units;
+ } else {
+ prefs.unit_system = PERSONALIZE;
+ }
+ disk_unit_system(true);
+ emit unit_system_changed(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.);
+
+HANDLE_PREFERENCE_ENUM_EXT(Units, units::VOLUME, "/volume", volume, units.);
+
+HANDLE_PREFERENCE_ENUM_EXT(Units, units::WEIGHT, "/weight", weight, units.);