aboutsummaryrefslogtreecommitdiffstats
path: root/core/subsurface-qt
diff options
context:
space:
mode:
Diffstat (limited to 'core/subsurface-qt')
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.cpp210
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.h57
2 files changed, 6 insertions, 261 deletions
diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp
index 296414be3..7997852e6 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.cpp
+++ b/core/subsurface-qt/SettingsObjectWrapper.cpp
@@ -1138,191 +1138,6 @@ void DivePlannerSettings::setDecoMode(deco_mode value)
emit decoModeChanged(value);
}
-UnitsSettings::UnitsSettings(QObject *parent) :
- QObject(parent)
-{
-
-}
-
-int UnitsSettings::length() const
-{
- return prefs.units.length;
-}
-
-int UnitsSettings::pressure() const
-{
- return prefs.units.pressure;
-}
-
-int UnitsSettings::volume() const
-{
- return prefs.units.volume;
-}
-
-int UnitsSettings::temperature() const
-{
- return prefs.units.temperature;
-}
-
-int UnitsSettings::weight() const
-{
- return prefs.units.weight;
-}
-
-int UnitsSettings::verticalSpeedTime() const
-{
- return prefs.units.vertical_speed_time;
-}
-
-int UnitsSettings::durationUnits() const
-{
- return prefs.units.duration_units;
-}
-
-bool UnitsSettings::showUnitsTable() const
-{
- return prefs.units.show_units_table;
-}
-
-QString UnitsSettings::unitSystem() const
-{
- return prefs.unit_system == METRIC ? QStringLiteral("metric")
- : prefs.unit_system == IMPERIAL ? QStringLiteral("imperial")
- : QStringLiteral("personalized");
-}
-
-bool UnitsSettings::coordinatesTraditional() const
-{
- return prefs.coordinates_traditional;
-}
-
-void UnitsSettings::setLength(int value)
-{
- if (value == prefs.units.length)
- return;
-
- QSettings s;
- s.beginGroup(group);
- s.setValue("length", value);
- prefs.units.length = (units::LENGTH) value;
- emit lengthChanged(value);
-}
-
-void UnitsSettings::setPressure(int value)
-{
- if (value == prefs.units.pressure)
- return;
- QSettings s;
- s.beginGroup(group);
- s.setValue("pressure", value);
- prefs.units.pressure = (units::PRESSURE) value;
- emit pressureChanged(value);
-}
-
-void UnitsSettings::setVolume(int value)
-{
- if (value == prefs.units.volume)
- return;
- QSettings s;
- s.beginGroup(group);
- s.setValue("volume", value);
- prefs.units.volume = (units::VOLUME) value;
- emit volumeChanged(value);
-}
-
-void UnitsSettings::setTemperature(int value)
-{
- if (value == prefs.units.temperature)
- return;
- QSettings s;
- s.beginGroup(group);
- s.setValue("temperature", value);
- prefs.units.temperature = (units::TEMPERATURE) value;
- emit temperatureChanged(value);
-}
-
-void UnitsSettings::setWeight(int value)
-{
- if (value == prefs.units.weight)
- return;
- QSettings s;
- s.beginGroup(group);
- s.setValue("weight", value);
- prefs.units.weight = (units::WEIGHT) value;
- emit weightChanged(value);
-}
-
-void UnitsSettings::setVerticalSpeedTime(int value)
-{
- if (value == prefs.units.vertical_speed_time)
- return;
- QSettings s;
- s.beginGroup(group);
- s.setValue("vertical_speed_time", value);
- prefs.units.vertical_speed_time = (units::TIME) value;
- emit verticalSpeedTimeChanged(value);
-}
-
-void UnitsSettings::setDurationUnits(int value)
-{
- if (value == prefs.units.duration_units)
- return;
- QSettings s;
- s.beginGroup(group);
- s.setValue("duration_units", value);
- prefs.units.duration_units = (units::DURATION) value;
- emit durationUnitChanged(value);
-}
-
-void UnitsSettings::setShowUnitsTable(bool value)
-{
- if (value == prefs.units.show_units_table)
- return;
- QSettings s;
- s.beginGroup(group);
- s.setValue("show_units_table", value);
- prefs.units.show_units_table = value;
- emit showUnitsTableChanged(value);
-}
-
-void UnitsSettings::setCoordinatesTraditional(bool value)
-{
- if (value == prefs.coordinates_traditional)
- return;
- QSettings s;
- s.beginGroup(group);
- s.setValue("coordinates", value);
- prefs.coordinates_traditional = value;
- emit coordinatesTraditionalChanged(value);
-}
-
-void UnitsSettings::setUnitSystem(const QString& value)
-{
- short int v = value == QStringLiteral("metric") ? METRIC
- : value == QStringLiteral("imperial")? IMPERIAL
- : PERSONALIZE;
-
- if (v == prefs.unit_system)
- return;
-
- QSettings s;
- s.beginGroup(group);
- s.setValue("unit_system", value);
-
- if (value == QStringLiteral("metric")) {
- prefs.unit_system = METRIC;
- prefs.units = SI_units;
- } else if (value == QStringLiteral("imperial")) {
- prefs.unit_system = IMPERIAL;
- prefs.units = IMPERIAL_units;
- } else {
- prefs.unit_system = PERSONALIZE;
- }
-
- emit unitSystemChanged(value);
- // TODO: emit the other values here?
-}
-
GeneralSettingsObjectWrapper::GeneralSettingsObjectWrapper(QObject *parent) :
QObject(parent)
{
@@ -1714,7 +1529,7 @@ QObject(parent),
proxy(new qPrefProxy(this)),
cloud_storage(new qPrefCloudStorage(this)),
planner_settings(new DivePlannerSettings(this)),
- unit_settings(new UnitsSettings(this)),
+ unit_settings(new qPrefUnits(this)),
general_settings(new GeneralSettingsObjectWrapper(this)),
display_settings(new qPrefDisplay(this)),
language_settings(new LanguageSettingsObjectWrapper(this)),
@@ -1731,26 +1546,9 @@ void SettingsObjectWrapper::load()
QVariant v;
uiLanguage(NULL);
- s.beginGroup("Units");
- if (s.value("unit_system").toString() == "metric") {
- prefs.unit_system = METRIC;
- prefs.units = SI_units;
- } else if (s.value("unit_system").toString() == "imperial") {
- prefs.unit_system = IMPERIAL;
- prefs.units = IMPERIAL_units;
- } else {
- prefs.unit_system = PERSONALIZE;
- GET_UNIT("length", length, units::FEET, units::METERS);
- GET_UNIT("pressure", pressure, units::PSI, units::BAR);
- GET_UNIT("volume", volume, units::CUFT, units::LITER);
- GET_UNIT("temperature", temperature, units::FAHRENHEIT, units::CELSIUS);
- GET_UNIT("weight", weight, units::LBS, units::KG);
- }
- GET_UNIT("vertical_speed_time", vertical_speed_time, units::MINUTES, units::SECONDS);
- GET_UNIT3("duration_units", duration_units, units::MIXED, units::ALWAYS_HOURS, units::DURATION);
- GET_UNIT_BOOL("show_units_table", show_units_table);
- GET_BOOL("coordinates", coordinates_traditional);
- s.endGroup();
+
+ qPrefUnits::instance()->load();
+
s.beginGroup("TecDetails");
GET_BOOL("po2graph", pp_graphs.po2);
GET_BOOL("pn2graph", pp_graphs.pn2);
diff --git a/core/subsurface-qt/SettingsObjectWrapper.h b/core/subsurface-qt/SettingsObjectWrapper.h
index 5afcfccc4..9099b0ceb 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.h
+++ b/core/subsurface-qt/SettingsObjectWrapper.h
@@ -343,59 +343,6 @@ private:
const QString group = QStringLiteral("Planner");
};
-class UnitsSettings : public QObject {
- Q_OBJECT
- Q_PROPERTY(int length READ length WRITE setLength NOTIFY lengthChanged)
- Q_PROPERTY(int pressure READ pressure WRITE setPressure NOTIFY pressureChanged)
- Q_PROPERTY(int volume READ volume WRITE setVolume NOTIFY volumeChanged)
- Q_PROPERTY(int temperature READ temperature WRITE setTemperature NOTIFY temperatureChanged)
- Q_PROPERTY(int weight READ weight WRITE setWeight NOTIFY weightChanged)
- Q_PROPERTY(QString unit_system READ unitSystem WRITE setUnitSystem NOTIFY unitSystemChanged)
- Q_PROPERTY(bool coordinates_traditional READ coordinatesTraditional WRITE setCoordinatesTraditional NOTIFY coordinatesTraditionalChanged)
- Q_PROPERTY(int vertical_speed_time READ verticalSpeedTime WRITE setVerticalSpeedTime NOTIFY verticalSpeedTimeChanged)
- Q_PROPERTY(int duration_units READ durationUnits WRITE setDurationUnits NOTIFY durationUnitChanged)
- Q_PROPERTY(bool show_units_table READ showUnitsTable WRITE setShowUnitsTable NOTIFY showUnitsTableChanged)
-
-public:
- UnitsSettings(QObject *parent = 0);
- int length() const;
- int pressure() const;
- int volume() const;
- int temperature() const;
- int weight() const;
- int verticalSpeedTime() const;
- int durationUnits() const;
- bool showUnitsTable() const;
- QString unitSystem() const;
- bool coordinatesTraditional() const;
-
-public slots:
- void setLength(int value);
- void setPressure(int value);
- void setVolume(int value);
- void setTemperature(int value);
- void setWeight(int value);
- void setVerticalSpeedTime(int value);
- void setDurationUnits(int value);
- void setShowUnitsTable(bool value);
- void setUnitSystem(const QString& value);
- void setCoordinatesTraditional(bool value);
-
-signals:
- void lengthChanged(int value);
- void pressureChanged(int value);
- void volumeChanged(int value);
- void temperatureChanged(int value);
- void weightChanged(int value);
- void verticalSpeedTimeChanged(int value);
- void unitSystemChanged(const QString& value);
- void coordinatesTraditionalChanged(bool value);
- void durationUnitChanged(int value);
- void showUnitsTableChanged(bool value);
-private:
- const QString group = QStringLiteral("Units");
-};
-
class GeneralSettingsObjectWrapper : public QObject {
Q_OBJECT
Q_PROPERTY(QString default_filename READ defaultFilename WRITE setDefaultFilename NOTIFY defaultFilenameChanged)
@@ -526,7 +473,7 @@ class SettingsObjectWrapper : public QObject {
Q_PROPERTY(qPrefProxy* proxy MEMBER proxy CONSTANT)
Q_PROPERTY(qPrefCloudStorage* cloud_storage MEMBER cloud_storage CONSTANT)
Q_PROPERTY(DivePlannerSettings* planner MEMBER planner_settings CONSTANT)
- Q_PROPERTY(UnitsSettings* units MEMBER unit_settings CONSTANT)
+ Q_PROPERTY(qPrefUnits* units MEMBER unit_settings CONSTANT)
Q_PROPERTY(GeneralSettingsObjectWrapper* general MEMBER general_settings CONSTANT)
Q_PROPERTY(qPrefDisplay* display MEMBER display_settings CONSTANT)
@@ -546,7 +493,7 @@ public:
qPrefProxy *proxy;
qPrefCloudStorage *cloud_storage;
DivePlannerSettings *planner_settings;
- UnitsSettings *unit_settings;
+ qPrefUnits *unit_settings;
GeneralSettingsObjectWrapper *general_settings;
qPrefDisplay *display_settings;
LanguageSettingsObjectWrapper *language_settings;