aboutsummaryrefslogtreecommitdiffstats
path: root/core/settings/qPrefUnit.cpp
blob: 8fe2477b9141f0d52de1f3c6b7c949230eb2b6ab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// SPDX-License-Identifier: GPL-2.0
#include "qPrefUnit.h"
#include "qPrefPrivate.h"


static const QString group = QStringLiteral("Units");

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);

QString qPrefUnits::duration_units()
{
	return 	prefs.units.duration_units == units::DURATION::ALWAYS_HOURS ? QStringLiteral("hours") :
			prefs.units.duration_units == units::DURATION::MINUTES_ONLY ? QStringLiteral("minutes") :
											QStringLiteral("mixed");
}
void qPrefUnits::set_duration_units(const QString& value)
{
	prefs.units.duration_units = value == QStringLiteral("hours") ? units::DURATION::ALWAYS_HOURS :
								 value == QStringLiteral("minutes")? units::DURATION::MINUTES_ONLY :
																	 units::DURATION::MIXED;
	disk_duration_units(true);
	emit instance()->duration_unitsStringChanged(value);
}
SET_PREFERENCE_ENUM_EXT(Units, units::DURATION, duration_units, units.);
DISK_LOADSYNC_ENUM_EXT(Units, "duration_units", units::DURATION, duration_units, units.);

QString qPrefUnits::length()
{
	return 	prefs.units.length == units::LENGTH::METERS ? QStringLiteral("meters") : QStringLiteral("feet");
}
void qPrefUnits::set_length(const QString& value)
{
	prefs.units.length = value == QStringLiteral("meters") ? units::LENGTH::METERS : units::LENGTH::FEET;
	disk_length(true);
	emit instance()->lengthStringChanged(value);
}
SET_PREFERENCE_ENUM_EXT(Units, units::LENGTH, length, units.);
DISK_LOADSYNC_ENUM_EXT(Units, "length", units::LENGTH, length, units.);

QString qPrefUnits::pressure()
{
	return 	prefs.units.pressure == units::PRESSURE::BAR ? QStringLiteral("bar") : QStringLiteral("psi");
}
void qPrefUnits::set_pressure(const QString& value)
{
	prefs.units.pressure = value == QStringLiteral("bar") ? units::PRESSURE::BAR : units::PRESSURE::PSI;
	disk_pressure(true);
	emit instance()->pressureStringChanged(value);
}
SET_PREFERENCE_ENUM_EXT(Units, units::PRESSURE, pressure, units.);
DISK_LOADSYNC_ENUM_EXT(Units, "pressure", units::PRESSURE, pressure, units.);

HANDLE_PREFERENCE_BOOL_EXT(Units, "show_units_table", show_units_table, units.);

QString qPrefUnits::temperature()
{
	return 	prefs.units.temperature == units::TEMPERATURE::CELSIUS ? QStringLiteral("celcius") : QStringLiteral("fahrenheit");
}
void qPrefUnits::set_temperature(const QString& value)
{
	prefs.units.temperature = value == QStringLiteral("celcius") ? units::TEMPERATURE::CELSIUS : units::TEMPERATURE::FAHRENHEIT;
	disk_temperature(true);
	emit instance()->temperatureStringChanged(value);
}
SET_PREFERENCE_ENUM_EXT(Units, units::TEMPERATURE, temperature, units.);
DISK_LOADSYNC_ENUM_EXT(Units, "temperature", units::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)
{
	set_unit_system(value == QStringLiteral("metric") ? METRIC : value == QStringLiteral("imperial")? IMPERIAL : PERSONALIZE);
	emit instance()->unit_systemStringChanged(value);
}
void qPrefUnits::set_unit_system(unit_system_values value)
{
	if (value == METRIC) {
		prefs.unit_system = METRIC;
		prefs.units = SI_units;

		// make sure all types are updated when changing
		set_volume(units::VOLUME::LITER);
		set_weight(units::WEIGHT::KG);
		set_length(units::LENGTH::METERS);
		set_pressure(units::PRESSURE::BAR);
		set_temperature(units::TEMPERATURE::CELSIUS);
	} else if (value == IMPERIAL) {
		prefs.unit_system = IMPERIAL;
		prefs.units = IMPERIAL_units;

		// make sure all types are updated when changing
		set_volume(units::VOLUME::CUFT);
		set_weight(units::WEIGHT::LBS);
		set_length(units::LENGTH::FEET);
		set_pressure(units::PRESSURE::PSI);
		set_temperature(units::TEMPERATURE::FAHRENHEIT);
	} else {
		prefs.unit_system = PERSONALIZE;
	}
	disk_unit_system(true);
	emit instance()->unit_systemChanged(value);
}
DISK_LOADSYNC_ENUM(Units, "unit_system", unit_system_values, unit_system);

QString qPrefUnits::vertical_speed_time()
{
	return 	prefs.units.vertical_speed_time == units::TIME::MINUTES ? QStringLiteral("minutes") : QStringLiteral("seconds");
}
void qPrefUnits::set_vertical_speed_time(const QString& value)
{
	prefs.units.vertical_speed_time = value == QStringLiteral("minutes") ? units::TIME::MINUTES : units::TIME::SECONDS;
	disk_vertical_speed_time(true);
	emit instance()->vertical_speed_timeStringChanged(value);
}
SET_PREFERENCE_ENUM_EXT(Units, units::TIME, vertical_speed_time, units.);
DISK_LOADSYNC_ENUM_EXT(Units, "vertical_speed_time", units::TIME, vertical_speed_time, units.);

QString qPrefUnits::volume()
{
	return 	prefs.units.volume == units::VOLUME::LITER ? QStringLiteral("liter") : QStringLiteral("cuft");
}
void qPrefUnits::set_volume(const QString& value)
{
	prefs.units.volume = value == QStringLiteral("liter") ? units::VOLUME::LITER : units::VOLUME::CUFT;
	disk_volume(true);
	emit instance()->volumeStringChanged(value);
}
SET_PREFERENCE_ENUM_EXT(Units, units::VOLUME, volume, units.);
DISK_LOADSYNC_ENUM_EXT(Units, "volume", units::VOLUME, volume, units.);

QString qPrefUnits::weight()
{
	return 	prefs.units.weight == units::WEIGHT::KG ? QStringLiteral("kg") : QStringLiteral("lbs");
}
void qPrefUnits::set_weight(const QString& value)
{
	prefs.units.weight = value == QStringLiteral("kg") ? units::WEIGHT::KG : units::WEIGHT::LBS;
	disk_weight(true);
	emit instance()->weightStringChanged(value);
}
SET_PREFERENCE_ENUM_EXT(Units, units::WEIGHT, weight, units.);
DISK_LOADSYNC_ENUM_EXT(Units, "weight", units::WEIGHT, weight, units.);