Commit a317d9c5 authored by Remek Zajac's avatar Remek Zajac

Introduce weight unit and separate distance from altitude

parent 72c97a09
This diff is collapsed.
......@@ -69,6 +69,24 @@ public:
/// Returns the string for distance units which has configued by user
static QString appSettingsDistanceUnitsString(void);
/// Converts from meters to the user specified altitude unit
static QVariant metersToAppSettingsAltitudeUnits(const QVariant& meters);
/// Converts from user specified altitude unit to meters
static QVariant appSettingsAltitudeUnitsToMeters(const QVariant& distance);
/// Returns the string for altitude units which has configued by user
static QString appSettingsAltitudeUnitsString(void);
/// Converts from grams to the user specified weight unit
static QVariant gramsToAppSettingsWeightUnits(const QVariant& meters);
/// Converts from user specified weight unit to grams
static QVariant appSettingsWeightUnitsToGrams(const QVariant& distance);
/// Returns the string for weight units which has configued by user
static QString appSettingsWeightUnitsString(void);
/// Converts from meters to the user specified distance unit
static QVariant squareMetersToAppSettingsAreaUnits(const QVariant& squareMeters);
......@@ -209,12 +227,21 @@ private:
static QVariant _inchesToCentimeters(const QVariant& inches);
static QVariant _celsiusToFarenheit(const QVariant& celsius);
static QVariant _farenheitToCelsius(const QVariant& farenheit);
static QVariant _kilogramsToGrams(const QVariant& kg);
static QVariant _ouncesToGrams(const QVariant& oz);
static QVariant _poundsToGrams(const QVariant& lbs);
static QVariant _gramsToKilograms(const QVariant& g);
static QVariant _gramsToOunces(const QVariant& g);
static QVariant _gramsToPunds(const QVariant& g);
enum UnitTypes {
UnitDistance = 0,
UnitAltitude,
UnitArea,
UnitSpeed,
UnitTemperature
UnitTemperature,
UnitWeight
};
struct AppSettingsTranslation_s {
......@@ -227,7 +254,9 @@ private:
};
static const AppSettingsTranslation_s* _findAppSettingsDistanceUnitsTranslation(const QString& rawUnits);
static const AppSettingsTranslation_s* _findAppSettingsAltitudeUnitsTranslation(const QString& rawUnits);
static const AppSettingsTranslation_s* _findAppSettingsAreaUnitsTranslation(const QString& rawUnits);
static const AppSettingsTranslation_s* _findAppSettingsWeightUnitsTranslation(const QString& rawUnits);
static void _loadJsonDefines(const QJsonObject& jsonDefinesObject, QMap<QString, QString>& defineMap);
......@@ -267,6 +296,8 @@ private:
static const qreal milesToMeters;
static const qreal feetToMeters;
static const qreal inchesToCentimeters;
static const qreal ouncesToGrams;
static const qreal poundsToGrams;
} constants;
struct BuiltInTranslation_s {
......
......@@ -145,6 +145,22 @@ public:
QString appSettingsDistanceUnitsString(void) const { return FactMetaData::appSettingsDistanceUnitsString(); }
/// Converts from meters to the user specified distance unit
Q_INVOKABLE QVariant metersToAppSettingsAltitudeUnits(const QVariant& meters) const { return FactMetaData::metersToAppSettingsAltitudeUnits(meters); }
/// Converts from user specified distance unit to meters
Q_INVOKABLE QVariant appSettingsAltitudeUnitsToMeters(const QVariant& distance) const { return FactMetaData::appSettingsAltitudeUnitsToMeters(distance); }
QString appSettingsAltitudeUnitsString(void) const { return FactMetaData::appSettingsAltitudeUnitsString(); }
/// Converts from grams to the user specified weight unit
Q_INVOKABLE QVariant gramsToAppSettingsWeightUnits(const QVariant& meters) const { return FactMetaData::gramsToAppSettingsWeightUnits(meters); }
/// Converts from user specified weight unit to grams
Q_INVOKABLE QVariant appSettingsWeightUnitsToGrams(const QVariant& distance) const { return FactMetaData::appSettingsWeightUnitsToGrams(distance); }
QString appSettingsWeightUnitsString(void) const { return FactMetaData::appSettingsWeightUnitsString(); }
/// Converts from square meters to the user specified area unit
Q_INVOKABLE QVariant squareMetersToAppSettingsAreaUnits(const QVariant& meters) const { return FactMetaData::squareMetersToAppSettingsAreaUnits(meters); }
......
......@@ -47,6 +47,35 @@ DECLARE_SETTINGSFACT_NO_FUNC(UnitsSettings, distanceUnits)
return _distanceUnitsFact;
}
DECLARE_SETTINGSFACT_NO_FUNC(UnitsSettings, altitudeUnits)
{
if (!_altitudeUnitsFact) {
// Distance/Area/Speed units settings can't be loaded from json since it creates an infinite loop of meta data loading.
QStringList enumStrings;
QVariantList enumValues;
enumStrings << "Feet" << "Meters";
enumValues << QVariant::fromValue(static_cast<uint32_t>(DistanceUnitsFeet)) << QVariant::fromValue(static_cast<uint32_t>(DistanceUnitsMeters));
FactMetaData* metaData = new FactMetaData(FactMetaData::valueTypeUint32, this);
metaData->setName(altitudeUnitsName);
metaData->setShortDescription("Altitude units");
metaData->setEnumInfo(enumStrings, enumValues);
AltitudeUnits defaultAltitudeUnit = AltitudeUnitsMeters;
switch(QLocale::system().measurementSystem()) {
case QLocale::MetricSystem: {
defaultAltitudeUnit = AltitudeUnitsMeters;
} break;
case QLocale::ImperialUSSystem:
case QLocale::ImperialUKSystem:
defaultAltitudeUnit = AltitudeUnitsFeet;
break;
}
metaData->setRawDefaultValue(defaultAltitudeUnit);
metaData->setQGCRebootRequired(true);
_altitudeUnitsFact = new SettingsFact(_settingsGroup, metaData, this);
}
return _altitudeUnitsFact;
}
DECLARE_SETTINGSFACT_NO_FUNC(UnitsSettings, areaUnits)
{
if (!_areaUnitsFact) {
......@@ -147,3 +176,36 @@ DECLARE_SETTINGSFACT_NO_FUNC(UnitsSettings, temperatureUnits)
}
return _temperatureUnitsFact;
}
DECLARE_SETTINGSFACT_NO_FUNC(UnitsSettings, weightUnits)
{
if (!_weightUnitsFact) {
// Units settings can't be loaded from json since it creates an infinite loop of meta data loading.
QStringList enumStrings;
QVariantList enumValues;
enumStrings << "Grams" << "Kilograms" << "Ounces" << "Pounds";
enumValues
<< QVariant::fromValue(static_cast<uint32_t>(WeightUnitsGrams))
<< QVariant::fromValue(static_cast<uint32_t>(WeightUnitsKg))
<< QVariant::fromValue(static_cast<uint32_t>(WeightUnitsOz))
<< QVariant::fromValue(static_cast<uint32_t>(WeightUnitsLbs));
FactMetaData* metaData = new FactMetaData(FactMetaData::valueTypeUint32, this);
metaData->setName(weightUnitsName);
metaData->setShortDescription(tr("Weight units"));
metaData->setEnumInfo(enumStrings, enumValues);
WeightUnits defaultWeightUnit = WeightUnitsGrams;
switch(QLocale::system().measurementSystem()) {
case QLocale::MetricSystem:
case QLocale::ImperialUKSystem: {
defaultWeightUnit = WeightUnitsGrams;
} break;
case QLocale::ImperialUSSystem:
defaultWeightUnit = WeightUnitsOz;
break;
}
metaData->setRawDefaultValue(defaultWeightUnit);
metaData->setQGCRebootRequired(true);
_weightUnitsFact = new SettingsFact(_settingsGroup, metaData, this);
}
return _weightUnitsFact;
}
......@@ -24,6 +24,11 @@ public:
DistanceUnitsMeters
};
enum AltitudeUnits {
AltitudeUnitsFeet = 0,
AltitudeUnitsMeters
};
enum AreaUnits {
AreaUnitsSquareFeet = 0,
AreaUnitsSquareMeters,
......@@ -46,17 +51,28 @@ public:
TemperatureUnitsFarenheit,
};
enum WeightUnits {
WeightUnitsGrams = 0,
WeightUnitsKg,
WeightUnitsOz,
WeightUnitsLbs
};
Q_ENUM(DistanceUnits)
Q_ENUM(AreaUnits)
Q_ENUM(AltitudeUnits)
Q_ENUM(SpeedUnits)
Q_ENUM(TemperatureUnits)
Q_ENUM(WeightUnits)
DEFINE_SETTING_NAME_GROUP()
DEFINE_SETTINGFACT(distanceUnits)
DEFINE_SETTINGFACT(altitudeUnits)
DEFINE_SETTINGFACT(areaUnits)
DEFINE_SETTINGFACT(speedUnits)
DEFINE_SETTINGFACT(temperatureUnits)
DEFINE_SETTINGFACT(weightUnits)
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment