2 ******************************************************************************
4 * @file opmapgadgetconfiguration.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
6 * @addtogroup GCSPlugins GCS Plugins
8 * @addtogroup OPMapPlugin OpenPilot Map Plugin
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
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"
32 OPMapGadgetConfiguration::OPMapGadgetConfiguration(QString classId
, QSettings
*qSettings
, QObject
*parent
) :
33 IUAVGadgetConfiguration(classId
, parent
),
34 m_mapProvider("GoogleHybrid"),
37 m_defaultLongitude(0),
39 m_showTileGridLines(false),
40 m_accessMode("ServerAndCache"),
41 m_useMemoryCache(true),
42 m_cacheLocation(Utils::PathUtils().GetStoragePath() + "mapscache" + QDir::separator()),
43 m_uavSymbol(QString::fromUtf8(":/uavs/images/mapquad.png")),
44 m_maxUpdateRate(2000), // ms
45 m_settings(qSettings
),
48 // if a saved configuration exists load it
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
;
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::PathUtils().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
;
108 void OPMapGadgetConfiguration::saveConfig() const
113 m_settings
->setValue("mapProvider", m_mapProvider
);
114 m_settings
->setValue("defaultZoom", m_defaultZoom
);
115 m_settings
->setValue("defaultLatitude", m_defaultLatitude
);
116 m_settings
->setValue("defaultLongitude", m_defaultLongitude
);
117 m_settings
->setValue("useOpenGL", m_useOpenGL
);
118 m_settings
->setValue("showTileGridLines", m_showTileGridLines
);
119 m_settings
->setValue("accessMode", m_accessMode
);
120 m_settings
->setValue("useMemoryCache", m_useMemoryCache
);
121 m_settings
->setValue("uavSymbol", m_uavSymbol
);
122 m_settings
->setValue("cacheLocation", Utils::PathUtils().RemoveStoragePath(m_cacheLocation
));
123 m_settings
->setValue("maxUpdateRate", m_maxUpdateRate
);
124 m_settings
->setValue("overlayOpacity", m_opacity
);
126 void OPMapGadgetConfiguration::saveConfig(QSettings
*qSettings
) const
128 qSettings
->setValue("mapProvider", m_mapProvider
);
129 qSettings
->setValue("defaultZoom", m_defaultZoom
);
130 qSettings
->setValue("defaultLatitude", m_defaultLatitude
);
131 qSettings
->setValue("defaultLongitude", m_defaultLongitude
);
132 qSettings
->setValue("useOpenGL", m_useOpenGL
);
133 qSettings
->setValue("showTileGridLines", m_showTileGridLines
);
134 qSettings
->setValue("accessMode", m_accessMode
);
135 qSettings
->setValue("useMemoryCache", m_useMemoryCache
);
136 qSettings
->setValue("uavSymbol", m_uavSymbol
);
137 qSettings
->setValue("cacheLocation", Utils::PathUtils().RemoveStoragePath(m_cacheLocation
));
138 qSettings
->setValue("maxUpdateRate", m_maxUpdateRate
);
139 qSettings
->setValue("overlayOpacity", m_opacity
);
141 void OPMapGadgetConfiguration::setCacheLocation(QString cacheLocation
)
143 m_cacheLocation
= cacheLocation
;