UnitsSettings.cc 5.14 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 20
{
    QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
    qmlRegisterUncreatableType<UnitsSettings>("QGroundControl.SettingsManager", 1, 0, "UnitsSettings", "Reference only");
}

21
DECLARE_SETTINGSFACT_NO_FUNC(UnitsSettings, distanceUnits)
22 23 24 25 26 27
{
    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";
28
        enumValues << QVariant::fromValue(static_cast<uint32_t>(DistanceUnitsFeet)) << QVariant::fromValue(static_cast<uint32_t>(DistanceUnitsMeters));
29
        FactMetaData* metaData = new FactMetaData(FactMetaData::valueTypeUint32, this);
30
        metaData->setName(distanceUnitsName);
31
        metaData->setShortDescription(tr("Distance units"));
32 33
        metaData->setEnumInfo(enumStrings, enumValues);
        metaData->setRawDefaultValue(DistanceUnitsMeters);
34
        metaData->setQGCRebootRequired(true);
35
        _distanceUnitsFact = new SettingsFact(_settingsGroup, metaData, this);
36 37 38 39
    }
    return _distanceUnitsFact;
}

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

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

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