Use the canonical file name also for the "already open" check
[GPXSee.git] / src / GUI / settings.cpp
blob3c7ec4b11d76c8774c7299bcc0f71a7f3477f38c
1 #include <QLocale>
2 #include <QDir>
3 #include <QPageLayout>
4 #include <QPageSize>
5 #include <QGeoPositionInfoSource>
6 #include "common/config.h"
7 #include "data/graph.h"
8 #include "format.h"
9 #include "units.h"
10 #include "timetype.h"
11 #include "markerinfoitem.h"
12 #include "timezoneinfo.h"
13 #include "settings.h"
16 #define SETTING(varName, name, defVal) \
17 const Settings::Setting Settings::varName = Settings::Setting(name, defVal)
19 #define IMPERIAL_UNITS() \
20 (QLocale::system().measurementSystem() == QLocale::ImperialSystem)
21 #define CWD(filename) \
22 QDir::current().filePath(filename)
23 #define UNITS() \
24 (IMPERIAL_UNITS() ? Imperial : Metric)
25 #define TIMEZONE() \
26 QVariant::fromValue(TimeZoneInfo())
27 #define POI_RADIUS() \
28 (int)(IMPERIAL_UNITS() ? MIINM : KMINM)
29 #define PAPER_SIZE() \
30 (IMPERIAL_UNITS() \
31 ? QPageSize::PageSizeId::Letter \
32 : QPageSize::PageSizeId::A4)
34 #ifdef Q_OS_ANDROID
35 #define PIXMAP_CACHE 384
36 #define DEM_CACHE 128
37 #else // Q_OS_ANDROID
38 #define PIXMAP_CACHE 512
39 #define DEM_CACHE 256
40 #endif // Q_OS_ANDROID
43 static QString defaultPlugin()
45 QString source;
47 QGeoPositionInfoSource *ps = QGeoPositionInfoSource::createDefaultSource(0);
48 if (ps) {
49 source = ps->sourceName();
50 delete ps;
53 return source;
56 QMap<QString, QVariantMap> Settings::SettingMap::read(QSettings &settings) const
58 QMap<QString, QVariantMap> map;
59 int size = settings.beginReadArray(_prefix);
61 for (int i = 0; i < size; i++) {
62 settings.setArrayIndex(i);
63 map.insert(settings.value(_key).toString(),
64 settings.value(_value).toMap());
66 settings.endArray();
68 return map;
71 void Settings::SettingMap::write(QSettings &settings,
72 const QMap<QString, QVariantMap> &map) const
74 int index = 0;
76 if (map.isEmpty())
77 return;
79 settings.beginWriteArray(_prefix);
81 for (QMap<QString, QVariantMap>::const_iterator it = map.constBegin();
82 it != map.constEnd(); ++it) {
83 if (!it.value().isEmpty()) {
84 settings.setArrayIndex(index++);
85 settings.setValue(_key, it.key());
86 settings.setValue(_value, it.value());
90 settings.endArray();
93 QStringList Settings::SettingList::read(QSettings &settings) const
95 QStringList list;
96 int size = settings.beginReadArray(_prefix);
98 for (int i = 0; i < size; i++) {
99 settings.setArrayIndex(i);
100 list.append(settings.value(_value).toString());
102 settings.endArray();
104 return list;
107 void Settings::SettingList::write(QSettings &settings,
108 const QStringList &list) const
110 if (list.isEmpty())
111 return;
113 settings.beginWriteArray(_prefix);
115 for (int i = 0; i < list.size(); i++) {
116 settings.setArrayIndex(i);
117 settings.setValue(_value, list.at(i));
120 settings.endArray();
123 const Settings::Setting &Settings::positionPlugin()
125 static Setting s("positionPlugin", defaultPlugin());
126 return s;
129 /* Window */
130 #ifndef Q_OS_ANDROID
131 SETTING(windowGeometry, "geometry", QByteArray() );
132 SETTING(windowState, "state", QByteArray() );
133 #endif // Q_OS_ANDROID
135 /* Settings */
136 SETTING(timeType, "timeType", Total );
137 SETTING(units, "units", UNITS() );
138 SETTING(coordinatesFormat, "coordinates", DecimalDegrees );
139 #ifndef Q_OS_ANDROID
140 SETTING(showToolbars, "toolbar", true );
141 #endif // Q_OS_ANDROID
143 /* Map */
144 SETTING(activeMap, "map", "Open Street Map" );
145 SETTING(showMap, "show", true );
146 SETTING(cursorCoordinates, "coordinates", false );
148 /* Graph */
149 SETTING(showGraphs, "show", true );
150 SETTING(graphType, "type", Distance );
151 SETTING(showGrid, "grid", true );
152 SETTING(sliderInfo, "sliderInfo", true );
153 #ifdef Q_OS_ANDROID
154 SETTING(showGraphTabs, "tabs", true );
155 #endif // Q_OS_ANDROID
157 /* POI */
158 SETTING(poiIcons, "icons", true );
159 SETTING(poiLabels, "labels", true );
160 SETTING(showPoi, "show", false );
161 SETTING(poiOverlap, "overlap", false );
163 /* Data */
164 SETTING(tracks, "tracks", true );
165 SETTING(routes, "routes", true );
166 SETTING(waypoints, "waypoints", true );
167 SETTING(areas, "areas", true );
168 SETTING(routeWaypoints, "routeWaypoints", true );
169 SETTING(waypointIcons, "waypointIcons", false );
170 SETTING(waypointLabels, "waypointLabels", true );
171 SETTING(pathTicks, "pathTicks", false );
172 SETTING(positionMarkers, "positionMarkers", true );
173 SETTING(markerInfo, "markerInfo", MarkerInfoItem::None );
174 SETTING(useStyles, "styles", true );
176 /* Position */
177 SETTING(showPosition, "show", false );
178 SETTING(followPosition, "follow", true );
179 SETTING(positionCoordinates, "coordinates", true );
180 SETTING(motionInfo, "motionInfo", true );
182 /* PDF export */
183 SETTING(pdfOrientation, "orientation", QPageLayout::Orientation::Portrait);
184 SETTING(pdfSize, "size", PAPER_SIZE() );
185 SETTING(pdfMarginLeft, "marginLeft", 5 );
186 SETTING(pdfMarginTop, "marginTop", 5 );
187 SETTING(pdfMarginRight, "marginRight", 5 );
188 SETTING(pdfMarginBottom, "marginBottom", 5 );
189 SETTING(pdfFileName, "fileName", CWD("export.pdf") );
190 SETTING(pdfResolution, "resolution", 600 );
192 /* PNG export */
193 SETTING(pngWidth, "width", 600 );
194 SETTING(pngHeight, "height", 800 );
195 SETTING(pngMarginLeft, "marginLeft", 5 );
196 SETTING(pngMarginTop, "marginTop", 5 );
197 SETTING(pngMarginRight, "marginRight", 5 );
198 SETTING(pngMarginBottom, "marginBottom", 5 );
199 SETTING(pngAntialiasing, "antialiasing", true );
200 SETTING(pngFileName, "fileName", CWD("export.png") );
202 /* Options */
203 SETTING(paletteColor, "paletteColor", QColor(Qt::blue) );
204 SETTING(paletteShift, "paletteShift", 0.62 );
205 SETTING(mapOpacity, "mapOpacity", 100 );
206 SETTING(backgroundColor, "backgroundColor", QColor(Qt::white) );
207 SETTING(crosshairColor, "crosshairColor", QColor(Qt::red) );
208 SETTING(infoColor, "infoColor", QColor(Qt::black) );
209 SETTING(infoBackground, "infoBackground", false );
210 SETTING(trackWidth, "trackWidth", 3 );
211 SETTING(routeWidth, "routeWidth", 3 );
212 SETTING(areaWidth, "areaWidth", 2 );
213 SETTING(trackStyle, "trackStyle", (int)Qt::SolidLine );
214 SETTING(routeStyle, "routeStyle", (int)Qt::DotLine );
215 SETTING(areaStyle, "areaStyle", (int)Qt::SolidLine );
216 SETTING(areaOpacity, "areaOpacity", 50 );
217 SETTING(waypointSize, "waypointSize", 8 );
218 SETTING(waypointColor, "waypointColor", QColor(Qt::black) );
219 SETTING(poiSize, "poiSize", 8 );
220 SETTING(poiColor, "poiColor", QColor(Qt::black) );
221 SETTING(graphWidth, "graphWidth", 1 );
222 SETTING(pathAntiAliasing, "pathAntiAliasing", true );
223 SETTING(graphAntiAliasing, "graphAntiAliasing", true );
224 SETTING(elevationFilter, "elevationFilter", 3 );
225 SETTING(speedFilter, "speedFilter", 5 );
226 SETTING(heartRateFilter, "heartrateFilter", 3 );
227 SETTING(cadenceFilter, "cadenceFilter", 3 );
228 SETTING(powerFilter, "powerFilter", 3 );
229 SETTING(outlierEliminate, "outlierEliminate", true );
230 SETTING(automaticPause, "automaticPause", true );
231 SETTING(pauseSpeed, "pauseSpeed", 0.5 );
232 SETTING(pauseInterval, "pauseInterval", 10 );
233 SETTING(useReportedSpeed, "useReportedSpeed", false );
234 SETTING(dataUseDEM, "dataUseDEM", false );
235 SETTING(secondaryElevation, "showSecondaryElevation", false );
236 SETTING(secondarySpeed, "showSecondarySpeed", false );
237 SETTING(timeZone, "timeZone", TIMEZONE() );
238 SETTING(useSegments, "useSegments", true );
239 SETTING(poiRadius, "poiRadius", POI_RADIUS() );
240 SETTING(demURL, "demURL", DEM_TILES_URL );
241 SETTING(demAuthentication, "demAuthentication", false );
242 SETTING(demUsername, "demUsername", "" );
243 SETTING(demPassword, "demPassword", "" );
244 SETTING(useOpenGL, "useOpenGL", false );
245 SETTING(enableHTTP2, "enableHTTP2", true );
246 SETTING(pixmapCache, "pixmapCache", PIXMAP_CACHE );
247 SETTING(demCache, "demCache", DEM_CACHE );
248 SETTING(connectionTimeout, "connectionTimeout", 30 );
249 SETTING(hiresPrint, "hiresPrint", false );
250 SETTING(printName, "printName", true );
251 SETTING(printDate, "printDate", true );
252 SETTING(printDistance, "printDistance", true );
253 SETTING(printTime, "printTime", true );
254 SETTING(printMovingTime, "printMovingTime", false );
255 SETTING(printItemCount, "printItemCount", true );
256 SETTING(separateGraphPage, "separateGraphPage", false );
257 SETTING(sliderColor, "sliderColor", QColor(Qt::red) );
258 SETTING(outputProjection, "outputProjection", 3856 );
259 SETTING(inputProjection, "inputProjection", 4326 );
260 SETTING(hidpiMap, "HiDPIMap", true );
261 SETTING(poiPath, "poiPath", "" );
262 SETTING(mapsPath, "mapsPath", "" );
263 SETTING(dataPath, "dataPath", "" );
265 const Settings::SettingMap Settings::positionPluginParameters
266 = Settings::SettingMap("pluginParameters", "plugin", "parameters");
268 const Settings::SettingList Settings::disabledPoiFiles
269 = Settings::SettingList("disabled", "file");
271 #ifndef Q_OS_ANDROID
272 const Settings::SettingList Settings::recentDataFiles
273 = Settings::SettingList("recent", "file");
274 #endif // Q_OS_ANDROID