dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
opmapgadgetconfiguration.cpp
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
29 #include "utils/pathutils.h"
30 #include <QDir>
31 
32 OPMapGadgetConfiguration::OPMapGadgetConfiguration(QString classId, QSettings *qSettings,
33  QObject *parent)
34  : IUAVGadgetConfiguration(classId, parent)
35  , m_mapProvider("GoogleHybrid")
36  , m_defaultZoom(2)
37  , m_defaultLatitude(0)
38  , 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)
45  , // ms
46  m_settings(qSettings)
47  , m_opacity(1)
48  , m_geoLanguage("autoDetect")
49 {
50 
51  // if a saved configuration exists load it
52  if (qSettings != nullptr) {
53 
54  QString mapProvider = qSettings->value("mapProvider").toString();
55  int zoom = qSettings->value("defaultZoom").toInt();
56  double latitude = qSettings->value("defaultLatitude").toDouble();
57  double longitude = qSettings->value("defaultLongitude").toDouble();
58  bool showTileGridLines = qSettings->value("showTileGridLines").toBool();
59  QString accessMode = qSettings->value("accessMode").toString();
60  bool useMemoryCache = qSettings->value("useMemoryCache").toBool();
61  QString cacheLocation = qSettings->value("cacheLocation").toString();
62  QString uavSymbol = qSettings->value("uavSymbol").toString();
63  int max_update_rate = qSettings->value("maxUpdateRate").toInt();
64  float userImageHorizontalScale = qSettings->value("userImageHorizontalScale").toFloat();
65  float userImageVerticalScale = qSettings->value("userImageVerticalScale").toFloat();
66  QString userImageLocation = qSettings->value("userImageLocation").toString();
67  QString language = qSettings->value("geolanguage").toString();
68  m_opacity = qSettings->value("overlayOpacity", 1).toReal();
69 
70  if (!mapProvider.isEmpty()) {
71  m_mapProvider = mapProvider;
72  }
73  if (!language.isEmpty()) {
74  m_geoLanguage = language;
75  }
76  m_defaultZoom = zoom;
77  m_defaultLatitude = latitude;
78  m_defaultLongitude = longitude;
79  m_showTileGridLines = showTileGridLines;
80  m_uavSymbol = uavSymbol;
81 
82  m_userImageHorizontalScale = userImageHorizontalScale;
83  m_userImageVerticalScale = userImageVerticalScale;
84  m_userImageLocation = userImageLocation;
85 
86  m_maxUpdateRate = max_update_rate;
87  if (m_maxUpdateRate < 100 || m_maxUpdateRate > 5000)
88  m_maxUpdateRate = 2000;
89 
90  if (!accessMode.isEmpty())
91  m_accessMode = accessMode;
92  m_useMemoryCache = useMemoryCache;
93 
94  // Assign cache location from settings
95  if (!cacheLocation.isEmpty())
96  m_cacheLocation = Utils::PathUtils().InsertStoragePath(cacheLocation);
97  }
98 }
99 
100 IUAVGadgetConfiguration *OPMapGadgetConfiguration::clone()
101 {
103 
104  m->m_mapProvider = m_mapProvider;
105  m->m_defaultZoom = m_defaultZoom;
106  m->m_defaultLatitude = m_defaultLatitude;
107  m->m_defaultLongitude = m_defaultLongitude;
108  m->m_showTileGridLines = m_showTileGridLines;
109  m->m_accessMode = m_accessMode;
110  m->m_useMemoryCache = m_useMemoryCache;
111  m->m_cacheLocation = m_cacheLocation;
112  m->m_uavSymbol = m_uavSymbol;
113  m->m_maxUpdateRate = m_maxUpdateRate;
114  m->m_opacity = m_opacity;
115  m->m_userImageHorizontalScale = m_userImageHorizontalScale;
116  m->m_userImageVerticalScale = m_userImageVerticalScale;
117  m->m_userImageLocation = m_userImageLocation;
118  m->m_geoLanguage = m_geoLanguage;
119 
120  return m;
121 }
123 {
124  if (!m_settings)
125  return;
126  m_settings->setValue("mapProvider", m_mapProvider);
127  m_settings->setValue("defaultZoom", m_defaultZoom);
128  m_settings->setValue("defaultLatitude", m_defaultLatitude);
129  m_settings->setValue("defaultLongitude", m_defaultLongitude);
130  m_settings->setValue("showTileGridLines", m_showTileGridLines);
131  m_settings->setValue("accessMode", m_accessMode);
132  m_settings->setValue("useMemoryCache", m_useMemoryCache);
133  m_settings->setValue("uavSymbol", m_uavSymbol);
134  m_settings->setValue("cacheLocation", Utils::PathUtils().RemoveStoragePath(m_cacheLocation));
135  m_settings->setValue("maxUpdateRate", m_maxUpdateRate);
136  m_settings->setValue("overlayOpacity", m_opacity);
137  m_settings->setValue("userImageHorizontalScale", m_userImageHorizontalScale);
138  m_settings->setValue("userImageVerticalScale", m_userImageVerticalScale);
139  m_settings->setValue("userImageLocation", m_userImageLocation);
140  m_settings->setValue("geolanguage", m_geoLanguage);
141 }
142 void OPMapGadgetConfiguration::saveConfig(QSettings *qSettings) const
143 {
144  qSettings->setValue("mapProvider", m_mapProvider);
145  qSettings->setValue("defaultZoom", m_defaultZoom);
146  qSettings->setValue("defaultLatitude", m_defaultLatitude);
147  qSettings->setValue("defaultLongitude", m_defaultLongitude);
148  qSettings->setValue("showTileGridLines", m_showTileGridLines);
149  qSettings->setValue("accessMode", m_accessMode);
150  qSettings->setValue("useMemoryCache", m_useMemoryCache);
151  qSettings->setValue("uavSymbol", m_uavSymbol);
152  qSettings->setValue("cacheLocation", Utils::PathUtils().RemoveStoragePath(m_cacheLocation));
153  qSettings->setValue("maxUpdateRate", m_maxUpdateRate);
154  qSettings->setValue("overlayOpacity", m_opacity);
155  qSettings->setValue("userImageHorizontalScale", m_userImageHorizontalScale);
156  qSettings->setValue("userImageVerticalScale", m_userImageVerticalScale);
157  qSettings->setValue("userImageLocation", m_userImageLocation);
158  qSettings->setValue("geolanguage", m_geoLanguage);
159 }
IUAVGadgetConfiguration * clone()
OPMapGadgetConfiguration(QString classId, QSettings *qSettings=nullptr, QObject *parent=nullptr)
QString InsertStoragePath(QString path)
Definition: pathutils.cpp:135