FlightMapSettings.cc 5.19 KB
Newer Older
1
/*=====================================================================
dogmaphobic's avatar
dogmaphobic committed
2

3
 QGroundControl Open Source Ground Control Station
dogmaphobic's avatar
dogmaphobic committed
4

5
 (c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
dogmaphobic's avatar
dogmaphobic committed
6

7
 This file is part of the QGROUNDCONTROL project
dogmaphobic's avatar
dogmaphobic committed
8

9 10 11 12
 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
dogmaphobic's avatar
dogmaphobic committed
13

14 15 16 17
 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
dogmaphobic's avatar
dogmaphobic committed
18

19 20
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
dogmaphobic's avatar
dogmaphobic committed
21

22 23 24 25 26 27 28
 ======================================================================*/

#include "FlightMapSettings.h"

#include <QSettings>
#include <QtQml>

dogmaphobic's avatar
dogmaphobic committed
29 30 31 32 33
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";
const char* FlightMapSettings::_showScaleOnFlyViewKey   = "ShowScaleOnFlyView";
34

35 36
FlightMapSettings::FlightMapSettings(QGCApplication* app)
    : QGCTool(app)
37 38 39 40
    , _mapProvider(_defaultMapProvider)
{
}

41
void FlightMapSettings::setToolbox(QGCToolbox *toolbox)
42
{
43
    QGCTool::setToolbox(toolbox);
44

45 46
    qmlRegisterUncreatableType<FlightMapSettings> ("QGroundControl", 1, 0, "FlightMapSetting", "Reference only");

dogmaphobic's avatar
dogmaphobic committed
47
    _supportedMapProviders << "Bing" << "Google"; // << "OpenStreetMap";
48 49

    _loadSettings();
50 51 52 53 54
}

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

56 57 58 59 60 61 62
    settings.beginGroup(_settingsGroup);
    settings.setValue(_mapProviderKey, _supportedMapProviders.contains(_mapProvider) ? _mapProvider : _defaultMapProvider);
}

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

64 65
    settings.beginGroup(_settingsGroup);
    _mapProvider = settings.value(_mapProviderKey, _defaultMapProvider).toString();
dogmaphobic's avatar
dogmaphobic committed
66

67 68 69
    if (!_supportedMapProviders.contains(_mapProvider)) {
        _mapProvider = _defaultMapProvider;
    }
dogmaphobic's avatar
dogmaphobic committed
70

71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
    _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
92

93 94 95 96
    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
97
    /*
dogmaphobic's avatar
dogmaphobic committed
98
    } else if (_mapProvider == "OpenStreetMap") {
99
        _mapTypes << "Street Map";
dogmaphobic's avatar
dogmaphobic committed
100
    */
101
    }
dogmaphobic's avatar
dogmaphobic committed
102

103 104 105 106 107 108
    emit mapTypesChanged(_mapTypes);
}

QString FlightMapSettings::mapTypeForMapName(const QString& mapName)
{
    QSettings settings;
dogmaphobic's avatar
dogmaphobic committed
109

110 111 112
    settings.beginGroup(_settingsGroup);
    settings.beginGroup(mapName);
    settings.beginGroup(_mapProvider);
113
    return settings.value(_mapTypeKey, "Satellite Map").toString();
114 115 116 117 118
}

void FlightMapSettings::setMapTypeForMapName(const QString& mapName, const QString& mapType)
{
    QSettings settings;
dogmaphobic's avatar
dogmaphobic committed
119

120 121 122 123 124 125 126 127 128
    settings.beginGroup(_settingsGroup);
    settings.beginGroup(mapName);
    settings.beginGroup(_mapProvider);
    settings.setValue(_mapTypeKey, mapType);
}

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

130 131 132 133 134 135 136 137
    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
138

139 140 141 142
    settings.beginGroup(_settingsGroup);
    settings.beginGroup(mapName);
    return settings.value(key, defaultValue).toString();
}
Don Gagne's avatar
Don Gagne committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160

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();
}
dogmaphobic's avatar
dogmaphobic committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176

bool FlightMapSettings::showScaleOnFlyView()
{
    QSettings settings;
    settings.beginGroup(_settingsGroup);
    bool show = settings.value(_showScaleOnFlyViewKey, true).toBool();
    return show;
}

void FlightMapSettings::setShowScaleOnFlyView(bool show)
{
    QSettings settings;
    settings.beginGroup(_settingsGroup);
    settings.setValue(_showScaleOnFlyViewKey, show);
    emit showScaleOnFlyViewChanged();
}