summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2017-05-06 13:44:22 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2017-05-06 13:49:36 -0700
commit876b479d695acda652e7b6c81c6b899946d42a85 (patch)
treecc01ab6c306c94e0d542fd43000d11f62e056cd8 /core
parent38b9185974e4f5199ee8f65bac97dab76b058e41 (diff)
downloadsubsurface-876b479d695acda652e7b6c81c6b899946d42a85.tar.gz
Wire up duration units preference UI
Now we track the preference, but we don't act on it, yet. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r--core/prefs-macros.h7
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.cpp17
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.h4
-rw-r--r--core/units.h25
4 files changed, 44 insertions, 9 deletions
diff --git a/core/prefs-macros.h b/core/prefs-macros.h
index bd1fc9a33..9208fb82e 100644
--- a/core/prefs-macros.h
+++ b/core/prefs-macros.h
@@ -11,6 +11,13 @@
else \
prefs.units.field = default_prefs.units.field
+#define GET_UNIT3(name, field, f, l, type) \
+ v = s.value(QString(name)); \
+ if (v.isValid() && v.toInt() >= (f) && v.toInt() <= (l)) \
+ prefs.units.field = (type)v.toInt(); \
+ else \
+ prefs.units.field = default_prefs.units.field
+
#define GET_BOOL(name, field) \
v = s.value(QString(name)); \
if (v.isValid()) \
diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp
index 2752567ae..25161a904 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.cpp
+++ b/core/subsurface-qt/SettingsObjectWrapper.cpp
@@ -1626,6 +1626,11 @@ int UnitsSettings::verticalSpeedTime() const
return prefs.units.vertical_speed_time;
}
+int UnitsSettings::durationUnits() const
+{
+ return prefs.units.duration_units;
+}
+
QString UnitsSettings::unitSystem() const
{
return prefs.unit_system == METRIC ? QStringLiteral("metric")
@@ -1705,6 +1710,17 @@ void UnitsSettings::setVerticalSpeedTime(int 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::setCoordinatesTraditional(bool value)
{
if (value == prefs.coordinates_traditional)
@@ -2180,6 +2196,7 @@ void SettingsObjectWrapper::load()
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_BOOL("coordinates", coordinates_traditional);
s.endGroup();
s.beginGroup("TecDetails");
diff --git a/core/subsurface-qt/SettingsObjectWrapper.h b/core/subsurface-qt/SettingsObjectWrapper.h
index bb0e9db62..7116e682e 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.h
+++ b/core/subsurface-qt/SettingsObjectWrapper.h
@@ -511,6 +511,7 @@ class UnitsSettings : public QObject {
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)
public:
UnitsSettings(QObject *parent = 0);
@@ -520,6 +521,7 @@ public:
int temperature() const;
int weight() const;
int verticalSpeedTime() const;
+ int durationUnits() const;
QString unitSystem() const;
bool coordinatesTraditional() const;
@@ -530,6 +532,7 @@ public slots:
void setTemperature(int value);
void setWeight(int value);
void setVerticalSpeedTime(int value);
+ void setDurationUnits(int value);
void setUnitSystem(const QString& value);
void setCoordinatesTraditional(bool value);
@@ -542,6 +545,7 @@ signals:
void verticalSpeedTimeChanged(int value);
void unitSystemChanged(const QString& value);
void coordinatesTraditionalChanged(bool value);
+ void durationUnitChanged(int value);
private:
const QString group = QStringLiteral("Units");
};
diff --git a/core/units.h b/core/units.h
index c92c23d3a..7e4c2e7d2 100644
--- a/core/units.h
+++ b/core/units.h
@@ -255,6 +255,11 @@ struct units {
SECONDS,
MINUTES
} vertical_speed_time;
+ enum DURATION {
+ MIXED,
+ MINUTES_ONLY,
+ ALWAYS_HOURS
+ } duration_units;
};
/*
@@ -264,15 +269,17 @@ struct units {
* actually use. Similarly, C instead of Kelvin.
* And kg instead of g.
*/
-#define SI_UNITS \
- { \
- .length = METERS, .volume = LITER, .pressure = BAR, .temperature = CELSIUS, .weight = KG, .vertical_speed_time = MINUTES \
- }
-
-#define IMPERIAL_UNITS \
- { \
- .length = FEET, .volume = CUFT, .pressure = PSI, .temperature = FAHRENHEIT, .weight = LBS, .vertical_speed_time = MINUTES \
- }
+#define SI_UNITS \
+ { \
+ .length = METERS, .volume = LITER, .pressure = BAR, .temperature = CELSIUS, .weight = KG, \
+ .vertical_speed_time = MINUTES, .duration_units = MIXED \
+ }
+
+#define IMPERIAL_UNITS \
+ { \
+ .length = FEET, .volume = CUFT, .pressure = PSI, .temperature = FAHRENHEIT, .weight = LBS, \
+ .vertical_speed_time = MINUTES, .duration_units = MIXED \
+ }
#ifdef __cplusplus
}