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>
This commit is contained in:
Dirk Hohndel 2017-05-06 13:44:22 -07:00
parent 38b9185974
commit 876b479d69
5 changed files with 47 additions and 8 deletions

View file

@ -11,6 +11,13 @@
else \ else \
prefs.units.field = default_prefs.units.field 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) \ #define GET_BOOL(name, field) \
v = s.value(QString(name)); \ v = s.value(QString(name)); \
if (v.isValid()) \ if (v.isValid()) \

View file

@ -1626,6 +1626,11 @@ int UnitsSettings::verticalSpeedTime() const
return prefs.units.vertical_speed_time; return prefs.units.vertical_speed_time;
} }
int UnitsSettings::durationUnits() const
{
return prefs.units.duration_units;
}
QString UnitsSettings::unitSystem() const QString UnitsSettings::unitSystem() const
{ {
return prefs.unit_system == METRIC ? QStringLiteral("metric") return prefs.unit_system == METRIC ? QStringLiteral("metric")
@ -1705,6 +1710,17 @@ void UnitsSettings::setVerticalSpeedTime(int value)
emit verticalSpeedTimeChanged(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) void UnitsSettings::setCoordinatesTraditional(bool value)
{ {
if (value == prefs.coordinates_traditional) if (value == prefs.coordinates_traditional)
@ -2180,6 +2196,7 @@ void SettingsObjectWrapper::load()
GET_UNIT("weight", weight, units::LBS, units::KG); GET_UNIT("weight", weight, units::LBS, units::KG);
} }
GET_UNIT("vertical_speed_time", vertical_speed_time, units::MINUTES, units::SECONDS); 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); GET_BOOL("coordinates", coordinates_traditional);
s.endGroup(); s.endGroup();
s.beginGroup("TecDetails"); s.beginGroup("TecDetails");

View file

@ -511,6 +511,7 @@ class UnitsSettings : public QObject {
Q_PROPERTY(QString unit_system READ unitSystem WRITE setUnitSystem NOTIFY unitSystemChanged) Q_PROPERTY(QString unit_system READ unitSystem WRITE setUnitSystem NOTIFY unitSystemChanged)
Q_PROPERTY(bool coordinates_traditional READ coordinatesTraditional WRITE setCoordinatesTraditional NOTIFY coordinatesTraditionalChanged) 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 vertical_speed_time READ verticalSpeedTime WRITE setVerticalSpeedTime NOTIFY verticalSpeedTimeChanged)
Q_PROPERTY(int duration_units READ durationUnits WRITE setDurationUnits NOTIFY durationUnitChanged)
public: public:
UnitsSettings(QObject *parent = 0); UnitsSettings(QObject *parent = 0);
@ -520,6 +521,7 @@ public:
int temperature() const; int temperature() const;
int weight() const; int weight() const;
int verticalSpeedTime() const; int verticalSpeedTime() const;
int durationUnits() const;
QString unitSystem() const; QString unitSystem() const;
bool coordinatesTraditional() const; bool coordinatesTraditional() const;
@ -530,6 +532,7 @@ public slots:
void setTemperature(int value); void setTemperature(int value);
void setWeight(int value); void setWeight(int value);
void setVerticalSpeedTime(int value); void setVerticalSpeedTime(int value);
void setDurationUnits(int value);
void setUnitSystem(const QString& value); void setUnitSystem(const QString& value);
void setCoordinatesTraditional(bool value); void setCoordinatesTraditional(bool value);
@ -542,6 +545,7 @@ signals:
void verticalSpeedTimeChanged(int value); void verticalSpeedTimeChanged(int value);
void unitSystemChanged(const QString& value); void unitSystemChanged(const QString& value);
void coordinatesTraditionalChanged(bool value); void coordinatesTraditionalChanged(bool value);
void durationUnitChanged(int value);
private: private:
const QString group = QStringLiteral("Units"); const QString group = QStringLiteral("Units");
}; };

View file

@ -255,6 +255,11 @@ struct units {
SECONDS, SECONDS,
MINUTES MINUTES
} vertical_speed_time; } vertical_speed_time;
enum DURATION {
MIXED,
MINUTES_ONLY,
ALWAYS_HOURS
} duration_units;
}; };
/* /*
@ -266,12 +271,14 @@ struct units {
*/ */
#define SI_UNITS \ #define SI_UNITS \
{ \ { \
.length = METERS, .volume = LITER, .pressure = BAR, .temperature = CELSIUS, .weight = KG, .vertical_speed_time = MINUTES \ .length = METERS, .volume = LITER, .pressure = BAR, .temperature = CELSIUS, .weight = KG, \
.vertical_speed_time = MINUTES, .duration_units = MIXED \
} }
#define IMPERIAL_UNITS \ #define IMPERIAL_UNITS \
{ \ { \
.length = FEET, .volume = CUFT, .pressure = PSI, .temperature = FAHRENHEIT, .weight = LBS, .vertical_speed_time = MINUTES \ .length = FEET, .volume = CUFT, .pressure = PSI, .temperature = FAHRENHEIT, .weight = LBS, \
.vertical_speed_time = MINUTES, .duration_units = MIXED \
} }
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -40,6 +40,9 @@ void PreferencesUnits::refreshSettings()
ui->vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES); ui->vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES);
ui->vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS); ui->vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS);
ui->duration_mixed->setChecked(prefs.units.duration_units == units::MIXED);
ui->duration_no_hours->setChecked(prefs.units.duration_units == units::MINUTES_ONLY);
ui->duration_show_hours->setChecked(prefs.units.duration_units == units::ALWAYS_HOURS);
} }
void PreferencesUnits::syncSettings() void PreferencesUnits::syncSettings()
@ -56,4 +59,5 @@ void PreferencesUnits::syncSettings()
units->setWeight(ui->lbs->isChecked() ? units::LBS : units::KG); units->setWeight(ui->lbs->isChecked() ? units::LBS : units::KG);
units->setVerticalSpeedTime(ui->vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS); units->setVerticalSpeedTime(ui->vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS);
units->setCoordinatesTraditional(ui->gpsTraditional->isChecked()); units->setCoordinatesTraditional(ui->gpsTraditional->isChecked());
units->setDurationUnits(ui->duration_mixed->isChecked() ? units::MIXED : (ui->duration_no_hours->isChecked() ? units::MINUTES_ONLY : units::ALWAYS_HOURS));
} }