FlightMapSettings.cc 4.03 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9

10 11 12 13 14 15

#include "FlightMapSettings.h"

#include <QSettings>
#include <QtQml>

dogmaphobic's avatar
dogmaphobic committed
16 17 18 19
const char* FlightMapSettings::_defaultMapProvider      = "Bing";                 // Bing is default since it support full street/satellite/hybrid set
const char* FlightMapSettings::_settingsGroup           = "FlightMapSettings";
const char* FlightMapSettings::_mapProviderKey          = "MapProvider";
const char* FlightMapSettings::_mapTypeKey              = "MapType";
20

21 22
FlightMapSettings::FlightMapSettings(QGCApplication* app)
    : QGCTool(app)
23 24 25 26
    , _mapProvider(_defaultMapProvider)
{
}

27
void FlightMapSettings::setToolbox(QGCToolbox *toolbox)
28
{
29
    QGCTool::setToolbox(toolbox);
30

31 32
    qmlRegisterUncreatableType<FlightMapSettings> ("QGroundControl", 1, 0, "FlightMapSetting", "Reference only");

dogmaphobic's avatar
dogmaphobic committed
33
    _supportedMapProviders << "Bing" << "Google"; // << "OpenStreetMap";
34 35

    _loadSettings();
36 37 38 39 40
}

void FlightMapSettings::_storeSettings(void)
{
    QSettings settings;
dogmaphobic's avatar
dogmaphobic committed
41

42 43 44 45 46 47 48
    settings.beginGroup(_settingsGroup);
    settings.setValue(_mapProviderKey, _supportedMapProviders.contains(_mapProvider) ? _mapProvider : _defaultMapProvider);
}

void FlightMapSettings::_loadSettings(void)
{
    QSettings settings;
dogmaphobic's avatar
dogmaphobic committed
49

50 51
    settings.beginGroup(_settingsGroup);
    _mapProvider = settings.value(_mapProviderKey, _defaultMapProvider).toString();
dogmaphobic's avatar
dogmaphobic committed
52

53 54 55
    if (!_supportedMapProviders.contains(_mapProvider)) {
        _mapProvider = _defaultMapProvider;
    }
dogmaphobic's avatar
dogmaphobic committed
56

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    _setMapTypesForCurrentProvider();
}

QString FlightMapSettings::mapProvider(void)
{
    return _mapProvider;
}

void FlightMapSettings::setMapProvider(const QString& mapProvider)
{
    if (_supportedMapProviders.contains(mapProvider)) {
        _mapProvider = mapProvider;
        _storeSettings();
        _setMapTypesForCurrentProvider();
        emit mapProviderChanged(mapProvider);
    }
}

void FlightMapSettings::_setMapTypesForCurrentProvider(void)
{
    _mapTypes.clear();
dogmaphobic's avatar
dogmaphobic committed
78

79 80 81 82
    if (_mapProvider == "Bing") {
        _mapTypes << "Street Map" << "Satellite Map" << "Hybrid Map";
    } else if (_mapProvider == "Google") {
        _mapTypes << "Street Map" << "Satellite Map" << "Terrain Map";
dogmaphobic's avatar
dogmaphobic committed
83
    /*
dogmaphobic's avatar
dogmaphobic committed
84
    } else if (_mapProvider == "OpenStreetMap") {
85
        _mapTypes << "Street Map";
dogmaphobic's avatar
dogmaphobic committed
86
    */
87
    }
dogmaphobic's avatar
dogmaphobic committed
88

89 90 91
    emit mapTypesChanged(_mapTypes);
}

92
QString FlightMapSettings::mapType(void)
93 94
{
    QSettings settings;
dogmaphobic's avatar
dogmaphobic committed
95

96 97
    settings.beginGroup(_settingsGroup);
    settings.beginGroup(_mapProvider);
98
    return settings.value(_mapTypeKey, "Satellite Map").toString();
99 100
}

101
void FlightMapSettings::setMapType(const QString& mapType)
102 103
{
    QSettings settings;
dogmaphobic's avatar
dogmaphobic committed
104

105 106 107
    settings.beginGroup(_settingsGroup);
    settings.beginGroup(_mapProvider);
    settings.setValue(_mapTypeKey, mapType);
108 109

    emit mapTypeChanged(mapType);
110 111 112 113 114
}

void FlightMapSettings::saveMapSetting (const QString &mapName, const QString& key, const QString& value)
{
    QSettings settings;
dogmaphobic's avatar
dogmaphobic committed
115

116 117 118 119 120 121 122 123
    settings.beginGroup(_settingsGroup);
    settings.beginGroup(mapName);
    settings.setValue(key, value);
}

QString FlightMapSettings::loadMapSetting (const QString &mapName, const QString& key, const QString& defaultValue)
{
    QSettings settings;
dogmaphobic's avatar
dogmaphobic committed
124

125 126 127 128
    settings.beginGroup(_settingsGroup);
    settings.beginGroup(mapName);
    return settings.value(key, defaultValue).toString();
}
Don Gagne's avatar
Don Gagne committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146

void FlightMapSettings::saveBoolMapSetting (const QString &mapName, const QString& key, bool value)
{
    QSettings settings;

    settings.beginGroup(_settingsGroup);
    settings.beginGroup(mapName);
    settings.setValue(key, value);
}

bool FlightMapSettings::loadBoolMapSetting (const QString &mapName, const QString& key, bool defaultValue)
{
    QSettings settings;

    settings.beginGroup(_settingsGroup);
    settings.beginGroup(mapName);
    return settings.value(key, defaultValue).toBool();
}