| 
									
										
										
										
											2018-07-31 15:04:12 +02:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							| 
									
										
										
										
											2018-08-14 12:25:15 +02:00
										 |  |  | #include "qPrefUnit.h"
 | 
					
						
							| 
									
										
										
										
											2018-07-31 15:04:12 +02:00
										 |  |  | #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); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 09:06:00 -07:00
										 |  |  | HANDLE_PREFERENCE_BOOL(Units, "coordinates", coordinates_traditional); | 
					
						
							| 
									
										
										
										
											2018-07-31 15:04:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-18 08:07:00 +01:00
										 |  |  | SET_PREFERENCE_ENUM_EXT(Units, units::DURATION, duration_units, units.); | 
					
						
							|  |  |  | DISK_LOADSYNC_ENUM_EXT(Units, "duration_units", units::DURATION, duration_units, units.); | 
					
						
							| 
									
										
										
										
											2018-07-31 15:04:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-18 08:07:00 +01:00
										 |  |  | SET_PREFERENCE_ENUM_EXT(Units, units::LENGTH, length, units.); | 
					
						
							|  |  |  | DISK_LOADSYNC_ENUM_EXT(Units, "length", units::LENGTH, length, units.); | 
					
						
							| 
									
										
										
										
											2018-07-31 15:04:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-18 08:07:00 +01:00
										 |  |  | SET_PREFERENCE_ENUM_EXT(Units, units::PRESSURE, pressure, units.); | 
					
						
							|  |  |  | DISK_LOADSYNC_ENUM_EXT(Units, "pressure", units::PRESSURE, pressure, units.); | 
					
						
							| 
									
										
										
										
											2018-07-31 15:04:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 09:06:00 -07:00
										 |  |  | HANDLE_PREFERENCE_BOOL_EXT(Units, "show_units_table", show_units_table, units.); | 
					
						
							| 
									
										
										
										
											2018-07-31 15:04:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-18 08:07:00 +01:00
										 |  |  | SET_PREFERENCE_ENUM_EXT(Units, units::TEMPERATURE, temperature, units.); | 
					
						
							|  |  |  | DISK_LOADSYNC_ENUM_EXT(Units, "temperature", units::TEMPERATURE, temperature, units.); | 
					
						
							| 
									
										
										
										
											2018-07-31 15:04:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-02 13:41:55 +01:00
										 |  |  | void qPrefUnits::set_unit_system(unit_system_values value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-01-07 14:31:49 +01:00
										 |  |  | 	prefs.unit_system = value; | 
					
						
							|  |  |  | 	if (prefs.unit_system == METRIC) { | 
					
						
							| 
									
										
										
										
											2020-01-02 09:12:40 +01:00
										 |  |  | 		// 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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-08 09:32:47 +01:00
										 |  |  | 		// this statement need to be AFTER the setters are called
 | 
					
						
							|  |  |  | 		// because it sets all of prefs.units without calling the
 | 
					
						
							|  |  |  | 		// setters
 | 
					
						
							|  |  |  | 		prefs.units = SI_units; | 
					
						
							|  |  |  | 	} else if (prefs.unit_system == IMPERIAL) { | 
					
						
							| 
									
										
										
										
											2020-01-02 09:12:40 +01:00
										 |  |  | 		// 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); | 
					
						
							| 
									
										
										
										
											2020-01-08 09:32:47 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// this statement need to be AFTER the setters are called
 | 
					
						
							|  |  |  | 		// because it sets all of prefs.units without calling the
 | 
					
						
							|  |  |  | 		// setters
 | 
					
						
							|  |  |  | 		prefs.units = IMPERIAL_units; | 
					
						
							| 
									
										
										
										
											2018-07-31 15:04:12 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-09-18 17:22:01 +02:00
										 |  |  | 	disk_unit_system(true); | 
					
						
							|  |  |  | 	emit instance()->unit_systemChanged(value); | 
					
						
							| 
									
										
										
										
											2018-07-31 15:04:12 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-09-07 09:06:00 -07:00
										 |  |  | DISK_LOADSYNC_ENUM(Units, "unit_system", unit_system_values, unit_system); | 
					
						
							| 
									
										
										
										
											2018-07-31 15:04:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-18 08:07:00 +01:00
										 |  |  | 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.); | 
					
						
							| 
									
										
										
										
											2018-07-31 15:04:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-18 08:07:00 +01:00
										 |  |  | SET_PREFERENCE_ENUM_EXT(Units, units::VOLUME, volume, units.); | 
					
						
							|  |  |  | DISK_LOADSYNC_ENUM_EXT(Units, "volume", units::VOLUME, volume, units.); | 
					
						
							| 
									
										
										
										
											2018-07-31 15:04:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-18 08:07:00 +01:00
										 |  |  | SET_PREFERENCE_ENUM_EXT(Units, units::WEIGHT, weight, units.); | 
					
						
							|  |  |  | DISK_LOADSYNC_ENUM_EXT(Units, "weight", units::WEIGHT, weight, units.); |