diff options
-rw-r--r-- | core/CMakeLists.txt | 1 | ||||
-rw-r--r-- | core/settings/qPref.h | 1 | ||||
-rw-r--r-- | core/settings/qPrefPrivate.h | 1 | ||||
-rw-r--r-- | core/settings/qPrefUnit.cpp | 75 | ||||
-rw-r--r-- | core/settings/qPrefUnit.h | 80 | ||||
-rw-r--r-- | packaging/ios/Subsurface-mobile.pro | 2 |
6 files changed, 160 insertions, 0 deletions
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 29b6a4446..d71b6e0cd 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -110,6 +110,7 @@ set(SUBSURFACE_CORE_LIB_SRCS settings/qPrefFacebook.cpp settings/qPrefPrivate.cpp settings/qPrefProxy.cpp + settings/qPrefUnit.cpp #Subsurface Qt have the Subsurface structs QObjectified for easy access via QML. subsurface-qt/DiveObjectHelper.cpp diff --git a/core/settings/qPref.h b/core/settings/qPref.h index 8cd7a2862..867c5f439 100644 --- a/core/settings/qPref.h +++ b/core/settings/qPref.h @@ -11,6 +11,7 @@ #include "qPrefDiveComputer.h" #include "qPrefFacebook.h" #include "qPrefProxy.h" +#include "qPrefUnit.h" class qPref : public QObject { Q_OBJECT diff --git a/core/settings/qPrefPrivate.h b/core/settings/qPrefPrivate.h index 881c53fc6..5ef60fbc8 100644 --- a/core/settings/qPrefPrivate.h +++ b/core/settings/qPrefPrivate.h @@ -20,6 +20,7 @@ public: friend class qPrefDiveComputer; friend class qPrefFacebook; friend class qPrefProxy; + friend class qPrefUnits; private: static qPrefPrivate *instance(); 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.); diff --git a/core/settings/qPrefUnit.h b/core/settings/qPrefUnit.h new file mode 100644 index 000000000..c1bed4103 --- /dev/null +++ b/core/settings/qPrefUnit.h @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef QPREFUNIT_H +#define QPREFUNIT_H +#include "core/pref.h" + +#include <QObject> + + +class qPrefUnits : public QObject { + Q_OBJECT + Q_PROPERTY(bool coordinates_traditional READ coordinates_traditional WRITE set_coordinates_traditional NOTIFY coordinates_traditional_changed); + Q_PROPERTY(units::DURATION duration_units READ duration_units WRITE set_duration_units NOTIFY duration_units_changed); + Q_PROPERTY(units::LENGTH length READ length WRITE set_length NOTIFY length_changed); + Q_PROPERTY(units::PRESSURE pressure READ pressure WRITE set_pressure NOTIFY pressure_changed); + Q_PROPERTY(bool show_units_table READ show_units_table WRITE set_show_units_table NOTIFY show_units_table_changed); + Q_PROPERTY(units::TEMPERATURE temperature READ temperature WRITE set_temperature NOTIFY temperature_changed); + Q_PROPERTY(QString unit_system READ unit_system WRITE set_unit_system NOTIFY unit_system_changed); + Q_PROPERTY(units::TIME vertical_speed_time READ vertical_speed_time WRITE set_vertical_speed_time NOTIFY vertical_speed_time_changed); + Q_PROPERTY(units::VOLUME volume READ volume WRITE set_volume NOTIFY volume_changed); + Q_PROPERTY(units::WEIGHT weight READ weight WRITE set_weight NOTIFY weight_changed); + +public: + qPrefUnits(QObject *parent = NULL); + static qPrefUnits *instance(); + + // Load/Sync local settings (disk) and struct preference + void loadSync(bool doSync); + void inline load() { loadSync(false); } + void inline sync() { loadSync(true); } + +public: + static inline bool coordinates_traditional() { return prefs.coordinates_traditional; } + static inline units::DURATION duration_units() { return prefs.units.duration_units; } + static inline units::LENGTH length() { return prefs.units.length; } + static inline units::PRESSURE pressure() { return prefs.units.pressure; } + static inline bool show_units_table() { return prefs.units.show_units_table; } + static inline units::TEMPERATURE temperature() { return prefs.units.temperature; } + static QString unit_system(); + static inline units::TIME vertical_speed_time() { return prefs.units.vertical_speed_time; } + static inline units::VOLUME volume() { return prefs.units.volume; } + static inline units::WEIGHT weight() { return prefs.units.weight; } + +public slots: + void set_coordinates_traditional(bool value); + void set_duration_units(units::DURATION value); + void set_length(units::LENGTH value); + void set_pressure(units::PRESSURE value); + void set_show_units_table(bool value); + void set_temperature(units::TEMPERATURE value); + void set_unit_system(const QString& value); + void set_vertical_speed_time(units::TIME value); + void set_volume(units::VOLUME value); + void set_weight(units::WEIGHT value); + +signals: + void coordinates_traditional_changed(bool value); + void duration_units_changed(int value); + void length_changed(int value); + void pressure_changed(int value); + void show_units_table_changed(bool value); + void temperature_changed(int value); + void unit_system_changed(const QString& value); + void vertical_speed_time_changed(int value); + void volume_changed(int value); + void weight_changed(int value); + +private: + void disk_coordinates_traditional(bool doSync); + void disk_duration_units(bool doSync); + void disk_length(bool doSync); + void disk_pressure(bool doSync); + void disk_show_units_table(bool doSync); + void disk_temperature(bool doSync); + void disk_unit_system(bool doSync); + void disk_vertical_speed_time(bool doSync); + void disk_volume(bool doSync); + void disk_weight(bool doSync); +}; + +#endif diff --git a/packaging/ios/Subsurface-mobile.pro b/packaging/ios/Subsurface-mobile.pro index c286c34e7..30eb6ce94 100644 --- a/packaging/ios/Subsurface-mobile.pro +++ b/packaging/ios/Subsurface-mobile.pro @@ -85,6 +85,7 @@ SOURCES += ../../subsurface-mobile-main.cpp \ ../../core/settings/qPrefFacebook.cpp \ ../../core/settings/qPrefPrivate.cpp \ ../../core/settings/qPrefProxy.cpp \ + ../../core/settings/qPrefUnit.cpp \ ../../core/subsurface-qt/CylinderObjectHelper.cpp \ ../../core/subsurface-qt/DiveObjectHelper.cpp \ ../../core/subsurface-qt/SettingsObjectWrapper.cpp \ @@ -199,6 +200,7 @@ HEADERS += \ ../../core/settings/qPrefFacebook.h \ ../../core/settings/qPrefPrivate.h \ ../../core/settings/qPrefProxy.h \ + ../../core/settings/qPrefUnit.h \ ../../core/subsurface-qt/CylinderObjectHelper.h \ ../../core/subsurface-qt/DiveObjectHelper.h \ ../../core/subsurface-qt/SettingsObjectWrapper.h \ |