UnitsSettings.cc 5.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * 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(tr("Distance units"));
31 32
        metaData->setEnumInfo(enumStrings, enumValues);
        metaData->setRawDefaultValue(DistanceUnitsMeters);
33
        metaData->setQGCRebootRequired(true);
34
        _distanceUnitsFact = new SettingsFact(_settingsGroup, metaData, this);
35 36 37 38
    }
    return _distanceUnitsFact;
}

39
DECLARE_SETTINGSFACT_NO_FUNC(UnitsSettings, areaUnits)
40 41 42 43 44 45
{
    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";
46 47 48 49 50 51 52
        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));
53
        FactMetaData* metaData = new FactMetaData(FactMetaData::valueTypeUint32, this);
54
        metaData->setName(areaUnitsName);
55
        metaData->setShortDescription(tr("Area units"));
56 57
        metaData->setEnumInfo(enumStrings, enumValues);
        metaData->setRawDefaultValue(AreaUnitsSquareMeters);
58
        metaData->setQGCRebootRequired(true);
59
        _areaUnitsFact = new SettingsFact(_settingsGroup, metaData, this);
60 61 62 63
    }
    return _areaUnitsFact;
}

64
DECLARE_SETTINGSFACT_NO_FUNC(UnitsSettings, speedUnits)
65 66 67 68 69 70
{
    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";
71 72 73 74 75 76
        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));
77
        FactMetaData* metaData = new FactMetaData(FactMetaData::valueTypeUint32, this);
78
        metaData->setName(speedUnitsName);
79
        metaData->setShortDescription(tr("Speed units"));
80 81
        metaData->setEnumInfo(enumStrings, enumValues);
        metaData->setRawDefaultValue(SpeedUnitsMetersPerSecond);
82
        metaData->setQGCRebootRequired(true);
83
        _speedUnitsFact = new SettingsFact(_settingsGroup, metaData, this);
84 85 86
    }
    return _speedUnitsFact;
}
87

88
DECLARE_SETTINGSFACT_NO_FUNC(UnitsSettings, temperatureUnits)
89 90 91 92 93 94
{
    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";
95
        enumValues << QVariant::fromValue(static_cast<uint32_t>(TemperatureUnitsCelsius)) << QVariant::fromValue(static_cast<uint32_t>(TemperatureUnitsFarenheit));
96
        FactMetaData* metaData = new FactMetaData(FactMetaData::valueTypeUint32, this);
97
        metaData->setName(temperatureUnitsName);
98
        metaData->setShortDescription(tr("Temperature units"));
99 100
        metaData->setEnumInfo(enumStrings, enumValues);
        metaData->setRawDefaultValue(TemperatureUnitsCelsius);
101
        metaData->setQGCRebootRequired(true);
102
        _temperatureUnitsFact = new SettingsFact(_settingsGroup, metaData, this);
103 104 105
    }
    return _temperatureUnitsFact;
}