1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2023-12-21
* Description : Geolocation Settings.
*
* SPDX-FileCopyrightText: 2022-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "geolocationsettings.h"
// Qt includes
#include <QDir>
#include <QFileInfo>
#include <QMutex>
#include <QList>
// KDE includes
#include <kconfiggroup.h>
#include <ksharedconfig.h>
// Local includes
#include "digikam_debug.h"
#include "backendgooglemaps.h"
#include "backendmarble.h"
#include "mapwidget.h"
#include "MarbleGlobal.h"
#include "MarbleWidget.h"
#include "MarbleModel.h"
#include "MarbleWidgetInputHandler.h"
namespace Digikam
{
class Q_DECL_HIDDEN GeolocationSettings::Private
{
public:
Private() = default;
GeolocationSettingsContainer settings;
QMutex mutex;
const QString configGroup = QLatin1String("Marble Settings");
QList<MapWidget*> widgets;
public:
GeolocationSettingsContainer readFromConfig() const;
void writeToConfig() const;
GeolocationSettingsContainer setSettings(const GeolocationSettingsContainer& s);
void applySettingsToWidget(MapWidget* const w, const GeolocationSettingsContainer& settings);
};
GeolocationSettingsContainer GeolocationSettings::Private::readFromConfig() const
{
GeolocationSettingsContainer s;
KSharedConfig::Ptr config = KSharedConfig::openConfig();
KConfigGroup group = config->group(configGroup);
s.readFromConfig(group);
return s;
}
void GeolocationSettings::Private::writeToConfig() const
{
KSharedConfig::Ptr config = KSharedConfig::openConfig();
KConfigGroup group = config->group(configGroup);
settings.writeToConfig(group);
}
GeolocationSettingsContainer GeolocationSettings::Private::setSettings(const GeolocationSettingsContainer& s)
{
QMutexLocker lock(&mutex);
GeolocationSettingsContainer old;
old = settings;
settings = s;
return old;
}
void GeolocationSettings::Private::applySettingsToWidget(MapWidget* const w,
const GeolocationSettingsContainer& settings)
{
if (w)
{
const auto backs = w->backends();
for (MapBackend* const b : backs)
{
BackendMarble* const mb = dynamic_cast<BackendMarble*>(b);
if (mb && mb->isReady())
{
MarbleWidget* const mw = static_cast<MarbleWidget*>(mb->mapWidget());
qCDebug(DIGIKAM_GEOIFACE_LOG) << "Apply settings to Marble Widget instance:" << mw;
MarbleGlobal::getInstance()->locale()->setMeasurementSystem(settings.distanceUnit);
mw->model()->setPersistentTileCacheLimit(settings.persistentTileCacheLimit * 1024);
mw->setDefaultFont(settings.mapFont);
mw->setMapQualityForViewContext(settings.stillQuality, Marble::Still);
mw->setMapQualityForViewContext(settings.animationQuality, Marble::Animation);
mw->setDefaultAngleUnit(settings.angleUnit);
mw->inputHandler()->setInertialEarthRotationEnabled(settings.inertialRotation);
mw->inputHandler()->setMouseViewRotationEnabled(settings.mouseRotation);
mw->setVolatileTileCacheLimit(settings.volatileTileCacheLimit * 1024);
mw->setShowGrid(settings.showGrid);
mw->setShowCrosshairs(settings.showCross);
mw->setShowAtmosphere(settings.showAtmos);
mw->setShowSunShading(settings.showSunShading);
mw->setShowCities(settings.showCities);
mw->setShowRelief(settings.showRelief);
mw->update();
}
}
}
}
// -----------------------------------------------------------------------------------------------
class Q_DECL_HIDDEN GeolocationSettingsCreator
{
public:
GeolocationSettings object;
};
Q_GLOBAL_STATIC(GeolocationSettingsCreator, geolocationSettingsCreator)
// -----------------------------------------------------------------------------------------------
GeolocationSettings* GeolocationSettings::instance()
{
return &geolocationSettingsCreator->object;
}
GeolocationSettings::GeolocationSettings()
: d(new Private)
{
readFromConfig();
qRegisterMetaType<GeolocationSettingsContainer>("GeolocationSettingsContainer");
}
GeolocationSettings::~GeolocationSettings()
{
delete d;
}
void GeolocationSettings::registerWidget(MapWidget* const widget)
{
if (!widget)
{
return;
}
if (!d->widgets.contains(widget))
{
d->widgets << widget;
}
}
void GeolocationSettings::applySettingsToWidget(MapWidget* const widget)
{
d->applySettingsToWidget(widget, d->settings);
}
void GeolocationSettings::unregisterWidget(MapWidget* const widget)
{
if (!widget)
{
return;
}
d->widgets.removeAll(widget);
}
void GeolocationSettings::applySettingsToWidgets(const GeolocationSettingsContainer& settings)
{
for (MapWidget* const w : std::as_const(d->widgets))
{
d->applySettingsToWidget(w, settings);
}
}
MarbleWidget* GeolocationSettings::mainMarbleWidget() const
{
qDebug() << "Registered Marble Widget:" << d->widgets;
for (MapWidget* const w : std::as_const(d->widgets))<--- Variable 'w' can be declared as pointer to const
{
if (w)
{
const auto backs = w->backends();
for (MapBackend* const b : backs)
{
BackendMarble* const mb = dynamic_cast<BackendMarble*>(b);
if (mb)
{
return (static_cast<MarbleWidget*>(mb->mapWidget()));
}
}
}
}
return nullptr;
}
void GeolocationSettings::reloadGoogleMaps()
{
for (MapWidget* const w : std::as_const(d->widgets))<--- Variable 'w' can be declared as pointer to const
{
if (w)
{
const auto backs = w->backends();
for (MapBackend* const b : backs)
{
BackendGoogleMaps* const gb = dynamic_cast<BackendGoogleMaps*>(b);
if (gb)
{
gb->reload();
}
}
}
}
}
GeolocationSettingsContainer GeolocationSettings::settings() const
{
QMutexLocker lock(&d->mutex);
GeolocationSettingsContainer s(d->settings);
return s;
}
void GeolocationSettings::setSettings(const GeolocationSettingsContainer& settings)
{
GeolocationSettingsContainer old = d->setSettings(settings);
Q_EMIT signalGeolocationSettingsChanged(settings, old);
Q_EMIT signalSettingsChanged();
applySettingsToWidgets(settings);
d->writeToConfig();
}
void GeolocationSettings::readFromConfig()
{
GeolocationSettingsContainer s = d->readFromConfig();
GeolocationSettingsContainer old = d->setSettings(s);
Q_EMIT signalGeolocationSettingsChanged(s, old);
Q_EMIT signalSettingsChanged();
}
void GeolocationSettings::openSetupGeolocation(SetupGeolocation::GeolocationTab tab)
{
Q_EMIT signalSetupGeolocation(tab);
}
} // namespace Digikam
#include "moc_geolocationsettings.cpp"
|