2018-07-31 13:04:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2018-08-14 10:25:15 +00:00
|
|
|
#include "qPrefUnit.h"
|
2018-07-31 13:04:12 +00:00
|
|
|
#include "qPrefPrivate.h"
|
|
|
|
|
|
|
|
|
|
|
|
static const QString group = QStringLiteral("Units");
|
|
|
|
|
|
|
|
qPrefUnits::qPrefUnits(QObject *parent) : QObject(parent)
|
|
|
|
{
|
|
|
|
}
|
2018-09-02 09:50:55 +00:00
|
|
|
|
2018-07-31 13:04:12 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_BOOL(Units, "coordinates", coordinates_traditional);
|
2018-07-31 13:04:12 +00:00
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_ENUM_EXT(Units, units::DURATION, "duration_units", duration_units, units.);
|
2018-07-31 13:04:12 +00:00
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_ENUM_EXT(Units, units::LENGTH, "length", length, units.);
|
2018-07-31 13:04:12 +00:00
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_ENUM_EXT(Units, units::PRESSURE, "pressure", pressure, units.);
|
2018-07-31 13:04:12 +00:00
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_BOOL_EXT(Units, "show_units_table", show_units_table, units.);
|
2018-07-31 13:04:12 +00:00
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_ENUM_EXT(Units, units::TEMPERATURE, "temperature", temperature, units.);
|
2018-07-31 13:04:12 +00:00
|
|
|
|
|
|
|
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;
|
2018-09-18 15:22:01 +00:00
|
|
|
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;
|
2018-07-31 13:04:12 +00:00
|
|
|
}
|
2018-09-18 15:22:01 +00:00
|
|
|
disk_unit_system(true);
|
|
|
|
emit instance()->unit_systemChanged(value);
|
2018-07-31 13:04:12 +00:00
|
|
|
}
|
2018-09-07 16:06:00 +00:00
|
|
|
DISK_LOADSYNC_ENUM(Units, "unit_system", unit_system_values, unit_system);
|
2018-07-31 13:04:12 +00:00
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_ENUM_EXT(Units, units::TIME, "vertical_speed_time", vertical_speed_time, units.);
|
2018-07-31 13:04:12 +00:00
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_ENUM_EXT(Units, units::VOLUME, "volume", volume, units.);
|
2018-07-31 13:04:12 +00:00
|
|
|
|
2018-09-07 16:06:00 +00:00
|
|
|
HANDLE_PREFERENCE_ENUM_EXT(Units, units::WEIGHT, "weight", weight, units.);
|