UnitsSettings.cc 5.44 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 16 17 18 19 20 21
const char* UnitsSettings::name =                           "Units";
const char* UnitsSettings::settingsGroup =                  ""; // settings are in root group

const char* UnitsSettings::distanceUnitsSettingsName =      "DistanceUnits";
const char* UnitsSettings::areaUnitsSettingsName =          "AreaUnits";
const char* UnitsSettings::speedUnitsSettingsName =         "SpeedUnits";
const char* UnitsSettings::temperatureUnitsSettingsName =   "TemperatureUnits";
22 23

UnitsSettings::UnitsSettings(QObject* parent)
24
    : SettingsGroup(name, settingsGroup, parent)
25 26 27
    , _distanceUnitsFact(NULL)
    , _areaUnitsFact(NULL)
    , _speedUnitsFact(NULL)
28
    , _temperatureUnitsFact(NULL)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
{
    QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
    qmlRegisterUncreatableType<UnitsSettings>("QGroundControl.SettingsManager", 1, 0, "UnitsSettings", "Reference only");
}

Fact* UnitsSettings::distanceUnits(void)
{
    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";
        enumValues << QVariant::fromValue((uint32_t)DistanceUnitsFeet) << QVariant::fromValue((uint32_t)DistanceUnitsMeters);
        
        FactMetaData* metaData = new FactMetaData(FactMetaData::valueTypeUint32, this);
        metaData->setName(distanceUnitsSettingsName);
46
        metaData->setShortDescription(tr("Distance units"));
47 48
        metaData->setEnumInfo(enumStrings, enumValues);
        metaData->setRawDefaultValue(DistanceUnitsMeters);
49
        metaData->setQGCRebootRequired(true);
50

51
        _distanceUnitsFact = new SettingsFact(_settingsGroup, metaData, this);
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

    }

    return _distanceUnitsFact;

}

Fact* UnitsSettings::areaUnits(void)
{
    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";
        enumValues << QVariant::fromValue((uint32_t)AreaUnitsSquareFeet) << QVariant::fromValue((uint32_t)AreaUnitsSquareMeters) << QVariant::fromValue((uint32_t)AreaUnitsSquareKilometers) << QVariant::fromValue((uint32_t)AreaUnitsHectares) << QVariant::fromValue((uint32_t)AreaUnitsAcres) << QVariant::fromValue((uint32_t)AreaUnitsSquareMiles);

        FactMetaData* metaData = new FactMetaData(FactMetaData::valueTypeUint32, this);
        metaData->setName(areaUnitsSettingsName);
71
        metaData->setShortDescription(tr("Area units"));
72 73
        metaData->setEnumInfo(enumStrings, enumValues);
        metaData->setRawDefaultValue(AreaUnitsSquareMeters);
74
        metaData->setQGCRebootRequired(true);
75

76
        _areaUnitsFact = new SettingsFact(_settingsGroup, metaData, this);
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
    }

    return _areaUnitsFact;

}

Fact* UnitsSettings::speedUnits(void)
{
    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";
        enumValues << QVariant::fromValue((uint32_t)SpeedUnitsFeetPerSecond) << QVariant::fromValue((uint32_t)SpeedUnitsMetersPerSecond) << QVariant::fromValue((uint32_t)SpeedUnitsMilesPerHour) << QVariant::fromValue((uint32_t)SpeedUnitsKilometersPerHour) << QVariant::fromValue((uint32_t)SpeedUnitsKnots);

        FactMetaData* metaData = new FactMetaData(FactMetaData::valueTypeUint32, this);
        metaData->setName(speedUnitsSettingsName);
95
        metaData->setShortDescription(tr("Speed units"));
96 97
        metaData->setEnumInfo(enumStrings, enumValues);
        metaData->setRawDefaultValue(SpeedUnitsMetersPerSecond);
98
        metaData->setQGCRebootRequired(true);
99

100
        _speedUnitsFact = new SettingsFact(_settingsGroup, metaData, this);
101 102 103 104
    }

    return _speedUnitsFact;
}
105 106 107 108 109 110 111 112 113 114 115 116 117

Fact* UnitsSettings::temperatureUnits(void)
{
    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";
        enumValues << QVariant::fromValue((uint32_t)TemperatureUnitsCelsius) << QVariant::fromValue((uint32_t)TemperatureUnitsFarenheit);

        FactMetaData* metaData = new FactMetaData(FactMetaData::valueTypeUint32, this);
        metaData->setName(temperatureUnitsSettingsName);
118
        metaData->setShortDescription(tr("Temperature units"));
119 120
        metaData->setEnumInfo(enumStrings, enumValues);
        metaData->setRawDefaultValue(TemperatureUnitsCelsius);
121
        metaData->setQGCRebootRequired(true);
122

123
        _temperatureUnitsFact = new SettingsFact(_settingsGroup, metaData, this);
124 125 126 127
    }

    return _temperatureUnitsFact;
}