UnitsSettings.cc 6.71 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9 10 11 12
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#include "UnitsSettings.h"

#include <QQmlEngine>
Don Gagne's avatar
Don Gagne committed
13
#include <QtQml>
14

15
DECLARE_SETTINGGROUP(Units, "Units")
16 17 18 19
{
    qmlRegisterUncreatableType<UnitsSettings>("QGroundControl.SettingsManager", 1, 0, "UnitsSettings", "Reference only");
}

20
DECLARE_SETTINGSFACT_NO_FUNC(UnitsSettings, distanceUnits)
21 22 23 24 25 26
{
    if (!_distanceUnitsFact) {
        // 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";
27
        enumValues << QVariant::fromValue(static_cast<uint32_t>(DistanceUnitsFeet)) << QVariant::fromValue(static_cast<uint32_t>(DistanceUnitsMeters));
28
        FactMetaData* metaData = new FactMetaData(FactMetaData::valueTypeUint32, this);
29
        metaData->setName(distanceUnitsName);
30
        metaData->setShortDescription("Distance units");
31
        metaData->setEnumInfo(enumStrings, enumValues);
32 33 34 35 36 37 38 39 40 41 42 43

        DistanceUnits defaultDistanceUnit = DistanceUnitsMeters;
        switch(QLocale::system().measurementSystem()) {
            case QLocale::MetricSystem: {
                defaultDistanceUnit = DistanceUnitsMeters;
            } break;
            case QLocale::ImperialUSSystem:
            case QLocale::ImperialUKSystem:
                defaultDistanceUnit = DistanceUnitsFeet;
                break;
        }
        metaData->setRawDefaultValue(defaultDistanceUnit);
44
        metaData->setQGCRebootRequired(true);
45
        _distanceUnitsFact = new SettingsFact(_settingsGroup, metaData, this);
46 47 48 49
    }
    return _distanceUnitsFact;
}

50
DECLARE_SETTINGSFACT_NO_FUNC(UnitsSettings, areaUnits)
51 52 53 54 55 56
{
    if (!_areaUnitsFact) {
        // 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 << "SquareFeet" << "SquareMeters" << "SquareKilometers" << "Hectares" << "Acres" << "SquareMiles";
57 58 59 60 61 62 63
        enumValues <<
            QVariant::fromValue(static_cast<uint32_t>(AreaUnitsSquareFeet)) <<
            QVariant::fromValue(static_cast<uint32_t>(AreaUnitsSquareMeters)) <<
            QVariant::fromValue(static_cast<uint32_t>(AreaUnitsSquareKilometers)) <<
            QVariant::fromValue(static_cast<uint32_t>(AreaUnitsHectares)) <<
            QVariant::fromValue(static_cast<uint32_t>(AreaUnitsAcres)) <<
            QVariant::fromValue(static_cast<uint32_t>(AreaUnitsSquareMiles));
64
        FactMetaData* metaData = new FactMetaData(FactMetaData::valueTypeUint32, this);
65
        metaData->setName(areaUnitsName);
66
        metaData->setShortDescription("Area units");
67
        metaData->setEnumInfo(enumStrings, enumValues);
68 69 70 71 72 73 74 75 76 77 78 79

        AreaUnits defaultAreaUnit = AreaUnitsSquareMeters;
        switch(QLocale::system().measurementSystem()) {
            case QLocale::MetricSystem: {
                defaultAreaUnit = AreaUnitsSquareMeters;
            } break;
            case QLocale::ImperialUSSystem:
            case QLocale::ImperialUKSystem:
                defaultAreaUnit = AreaUnitsSquareMiles;
                break;
        }
        metaData->setRawDefaultValue(defaultAreaUnit);
80
        metaData->setQGCRebootRequired(true);
81
        _areaUnitsFact = new SettingsFact(_settingsGroup, metaData, this);
82 83 84 85
    }
    return _areaUnitsFact;
}

86
DECLARE_SETTINGSFACT_NO_FUNC(UnitsSettings, speedUnits)
87 88 89 90 91 92
{
    if (!_speedUnitsFact) {
        // 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/second" << "Meters/second" << "Miles/hour" << "Kilometers/hour" << "Knots";
93 94 95 96 97 98
        enumValues <<
            QVariant::fromValue(static_cast<uint32_t>(SpeedUnitsFeetPerSecond)) <<
            QVariant::fromValue(static_cast<uint32_t>(SpeedUnitsMetersPerSecond)) <<
            QVariant::fromValue(static_cast<uint32_t>(SpeedUnitsMilesPerHour)) <<
            QVariant::fromValue(static_cast<uint32_t>(SpeedUnitsKilometersPerHour)) <<
            QVariant::fromValue(static_cast<uint32_t>(SpeedUnitsKnots));
99
        FactMetaData* metaData = new FactMetaData(FactMetaData::valueTypeUint32, this);
100
        metaData->setName(speedUnitsName);
101
        metaData->setShortDescription("Speed units");
102
        metaData->setEnumInfo(enumStrings, enumValues);
103 104 105 106 107 108 109 110 111 112 113 114

        SpeedUnits defaultSpeedUnit = SpeedUnitsMetersPerSecond;
        switch(QLocale::system().measurementSystem()) {
            case QLocale::MetricSystem: {
                defaultSpeedUnit = SpeedUnitsMetersPerSecond;
            } break;
            case QLocale::ImperialUSSystem:
            case QLocale::ImperialUKSystem:
                defaultSpeedUnit = SpeedUnitsMilesPerHour;
                break;
        }
        metaData->setRawDefaultValue(defaultSpeedUnit);
115
        metaData->setQGCRebootRequired(true);
116
        _speedUnitsFact = new SettingsFact(_settingsGroup, metaData, this);
117 118 119
    }
    return _speedUnitsFact;
}
120

121
DECLARE_SETTINGSFACT_NO_FUNC(UnitsSettings, temperatureUnits)
122 123 124 125 126 127
{
    if (!_temperatureUnitsFact) {
        // Units settings can't be loaded from json since it creates an infinite loop of meta data loading.
        QStringList     enumStrings;
        QVariantList    enumValues;
        enumStrings << "Celsius" << "Farenheit";
128
        enumValues << QVariant::fromValue(static_cast<uint32_t>(TemperatureUnitsCelsius)) << QVariant::fromValue(static_cast<uint32_t>(TemperatureUnitsFarenheit));
129
        FactMetaData* metaData = new FactMetaData(FactMetaData::valueTypeUint32, this);
130
        metaData->setName(temperatureUnitsName);
131
        metaData->setShortDescription("Temperature units");
132
        metaData->setEnumInfo(enumStrings, enumValues);
133 134 135 136 137 138 139 140 141 142 143 144

        TemperatureUnits defaultTemperatureUnit = TemperatureUnitsCelsius;
        switch(QLocale::system().measurementSystem()) {
            case QLocale::MetricSystem: {
                defaultTemperatureUnit = TemperatureUnitsCelsius;
            } break;
            case QLocale::ImperialUSSystem:
            case QLocale::ImperialUKSystem:
                defaultTemperatureUnit = TemperatureUnitsFarenheit;
                break;
        }
        metaData->setRawDefaultValue(defaultTemperatureUnit);
145
        metaData->setQGCRebootRequired(true);
146
        _temperatureUnitsFact = new SettingsFact(_settingsGroup, metaData, this);
147 148 149
    }
    return _temperatureUnitsFact;
}