LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / opmap / opmapgadgetconfiguration.cpp
blob9dba75bb837680bbd60d126e949f38c10c21008a
1 /**
2 ******************************************************************************
4 * @file opmapgadgetconfiguration.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
6 * @addtogroup GCSPlugins GCS Plugins
7 * @{
8 * @addtogroup OPMapPlugin OpenPilot Map Plugin
9 * @{
10 * @brief The OpenPilot Map plugin
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "opmapgadgetconfiguration.h"
29 #include "utils/pathutils.h"
30 #include <QDir>
32 OPMapGadgetConfiguration::OPMapGadgetConfiguration(QString classId, QSettings *qSettings, QObject *parent) :
33 IUAVGadgetConfiguration(classId, parent),
34 m_mapProvider("GoogleHybrid"),
35 m_defaultZoom(2),
36 m_defaultLatitude(0),
37 m_defaultLongitude(0),
38 m_useOpenGL(false),
39 m_showTileGridLines(false),
40 m_accessMode("ServerAndCache"),
41 m_useMemoryCache(true),
42 m_cacheLocation(Utils::GetStoragePath() + "mapscache" + QDir::separator()),
43 m_uavSymbol(QString::fromUtf8(":/uavs/images/mapquad.png")),
44 m_maxUpdateRate(2000), // ms
45 m_settings(qSettings),
46 m_opacity(1)
48 // if a saved configuration exists load it
49 if (qSettings != 0) {
50 QString mapProvider = qSettings->value("mapProvider").toString();
51 int zoom = qSettings->value("defaultZoom").toInt();
52 double latitude = qSettings->value("defaultLatitude").toDouble();
53 double longitude = qSettings->value("defaultLongitude").toDouble();
54 bool useOpenGL = qSettings->value("useOpenGL").toBool();
55 bool showTileGridLines = qSettings->value("showTileGridLines").toBool();
56 QString accessMode = qSettings->value("accessMode").toString();
57 bool useMemoryCache = qSettings->value("useMemoryCache").toBool();
58 QString cacheLocation = qSettings->value("cacheLocation").toString();
59 QString uavSymbol = qSettings->value("uavSymbol").toString();
60 int max_update_rate = qSettings->value("maxUpdateRate").toInt();
62 m_opacity = qSettings->value("overlayOpacity", 1).toReal();
64 if (!mapProvider.isEmpty()) {
65 m_mapProvider = mapProvider;
67 m_defaultZoom = zoom;
68 m_defaultLatitude = latitude;
69 m_defaultLongitude = longitude;
70 m_useOpenGL = useOpenGL;
71 m_showTileGridLines = showTileGridLines;
72 m_uavSymbol = uavSymbol;
74 m_maxUpdateRate = max_update_rate;
75 if (m_maxUpdateRate < 100 || m_maxUpdateRate > 5000) {
76 m_maxUpdateRate = 2000;
79 if (!accessMode.isEmpty()) {
80 m_accessMode = accessMode;
82 m_useMemoryCache = useMemoryCache;
83 if (!cacheLocation.isEmpty()) {
84 m_cacheLocation = Utils::InsertStoragePath(cacheLocation);
89 IUAVGadgetConfiguration *OPMapGadgetConfiguration::clone()
91 OPMapGadgetConfiguration *m = new OPMapGadgetConfiguration(this->classId());
93 m->m_mapProvider = m_mapProvider;
94 m->m_defaultZoom = m_defaultZoom;
95 m->m_defaultLatitude = m_defaultLatitude;
96 m->m_defaultLongitude = m_defaultLongitude;
97 m->m_useOpenGL = m_useOpenGL;
98 m->m_showTileGridLines = m_showTileGridLines;
99 m->m_accessMode = m_accessMode;
100 m->m_useMemoryCache = m_useMemoryCache;
101 m->m_cacheLocation = m_cacheLocation;
102 m->m_uavSymbol = m_uavSymbol;
103 m->m_maxUpdateRate = m_maxUpdateRate;
104 m->m_opacity = m_opacity;
106 return m;
108 void OPMapGadgetConfiguration::save() const
110 if (!m_settings) {
111 return;
114 saveConfig(m_settings);
116 void OPMapGadgetConfiguration::saveConfig(QSettings *qSettings) const
118 qSettings->setValue("mapProvider", m_mapProvider);
119 qSettings->setValue("defaultZoom", m_defaultZoom);
120 qSettings->setValue("defaultLatitude", m_defaultLatitude);
121 qSettings->setValue("defaultLongitude", m_defaultLongitude);
122 qSettings->setValue("useOpenGL", m_useOpenGL);
123 qSettings->setValue("showTileGridLines", m_showTileGridLines);
124 qSettings->setValue("accessMode", m_accessMode);
125 qSettings->setValue("useMemoryCache", m_useMemoryCache);
126 qSettings->setValue("uavSymbol", m_uavSymbol);
127 qSettings->setValue("cacheLocation", Utils::RemoveStoragePath(m_cacheLocation));
128 qSettings->setValue("maxUpdateRate", m_maxUpdateRate);
129 qSettings->setValue("overlayOpacity", m_opacity);
131 void OPMapGadgetConfiguration::setCacheLocation(QString cacheLocation)
133 m_cacheLocation = cacheLocation;