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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2023-05-15
* Description : geolocation engine based on Marble.
* (c) 2007-2022 Marble Team
* https://invent.kde.org/education/marble/-/raw/master/data/credits_authors.html
*
* SPDX-FileCopyrightText: 2023-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*
* ============================================================ */
#include "GeoDataFeature.h"
#include "GeoDataFeature_p.h"
// Qt includes
#include <QDataStream>
#include <QSize>
// Local includes
#include "MarbleDirs.h"
#include "GeoDataStyle.h"
#include "GeoDataStyleMap.h"
#include "GeoDataContainer.h"
#include "GeoDataDocument.h"
#include "GeoDataFolder.h"
#include "GeoDataGroundOverlay.h"
#include "GeoDataNetworkLink.h"
#include "GeoDataNetworkLinkControl.h"
#include "GeoDataPhotoOverlay.h"
#include "GeoDataPlacemark.h"
#include "GeoDataScreenOverlay.h"
#include "GeoDataTour.h"
#include "GeoDataRegion.h"
#include "GeoDataCamera.h"
#include "digikam_debug.h"
namespace Marble
{
GeoDataFeature::GeoDataFeature()
: d_ptr(new GeoDataFeaturePrivate())
{
}
GeoDataFeature::GeoDataFeature(const GeoDataFeature& other)
: GeoDataObject(),
d_ptr(new GeoDataFeaturePrivate(*other.d_ptr))
{
}
GeoDataFeature::GeoDataFeature(const QString& name)
: d_ptr(new GeoDataFeaturePrivate())
{
d_ptr->m_name = name;
}
GeoDataFeature::GeoDataFeature(GeoDataFeaturePrivate* dd)
: GeoDataObject(),
d_ptr(dd)
{
}
GeoDataFeature::GeoDataFeature(const GeoDataFeature& other, GeoDataFeaturePrivate* dd)
: GeoDataObject(),
d_ptr(dd)
{
Q_UNUSED(other);
// TODO: some classes pass "other" on and thus get duplicated id, also in operator=. Align behaviour
}
GeoDataFeature::~GeoDataFeature()
{
delete d_ptr;
}
GeoDataFeature& GeoDataFeature::operator=(const GeoDataFeature& other)
{
if (this != &other)
{
*d_ptr = *other.d_ptr;
}
return *this;
}
bool GeoDataFeature::operator==(const GeoDataFeature& other) const
{
if (nodeType() != other.nodeType())
{
return false;
}
if (nodeType() == GeoDataTypes::GeoDataDocumentType)
{
const GeoDataDocument& thisDoc = static_cast<const GeoDataDocument&>(*this);
const GeoDataDocument& otherDoc = static_cast<const GeoDataDocument&>(other);
return thisDoc == otherDoc;
}
else if (nodeType() == GeoDataTypes::GeoDataFolderType)
{
const GeoDataFolder& thisFolder = static_cast<const GeoDataFolder&>(*this);
const GeoDataFolder& otherFolder = static_cast<const GeoDataFolder&>(other);
return thisFolder == otherFolder;
}
else if (nodeType() == GeoDataTypes::GeoDataGroundOverlayType)
{
const GeoDataGroundOverlay& thisGO = static_cast<const GeoDataGroundOverlay&>(*this);
const GeoDataGroundOverlay& otherGO = static_cast<const GeoDataGroundOverlay&>(other);
return thisGO == otherGO;
}
else if (nodeType() == GeoDataTypes::GeoDataNetworkLinkType)
{
const GeoDataNetworkLink& thisNetLink = static_cast<const GeoDataNetworkLink&>(*this);
const GeoDataNetworkLink& otherNetLink = static_cast<const GeoDataNetworkLink&>(other);
return thisNetLink == otherNetLink;
}
else if (nodeType() == GeoDataTypes::GeoDataNetworkLinkControlType)
{
const GeoDataNetworkLinkControl& thisNLC = static_cast<const GeoDataNetworkLinkControl&>(*this);
const GeoDataNetworkLinkControl& otherNLC = static_cast<const GeoDataNetworkLinkControl&>(other);
return thisNLC == otherNLC;
}
else if (nodeType() == GeoDataTypes::GeoDataPhotoOverlayType)
{
const GeoDataPhotoOverlay& thisPO = static_cast<const GeoDataPhotoOverlay&>(*this);
const GeoDataPhotoOverlay& otherPO = static_cast<const GeoDataPhotoOverlay&>(other);
return thisPO == otherPO;
}
else if (nodeType() == GeoDataTypes::GeoDataPlacemarkType)
{
const GeoDataPlacemark& thisPM = static_cast<const GeoDataPlacemark&>(*this);
const GeoDataPlacemark& otherPM = static_cast<const GeoDataPlacemark&>(other);
return thisPM == otherPM;
}
else if (nodeType() == GeoDataTypes::GeoDataScreenOverlayType)
{
const GeoDataScreenOverlay& thisSO = static_cast<const GeoDataScreenOverlay&>(*this);
const GeoDataScreenOverlay& otherSO = static_cast<const GeoDataScreenOverlay&>(other);
return thisSO == otherSO;
}
else if (nodeType() == GeoDataTypes::GeoDataTourType)
{
const GeoDataTour& thisTour = static_cast<const GeoDataTour&>(*this);
const GeoDataTour& otherTour = static_cast<const GeoDataTour&>(other);
return thisTour == otherTour;
}
return false;
}
bool GeoDataFeature::equals(const GeoDataFeature& other) const
{
Q_D(const GeoDataFeature);
const GeoDataFeaturePrivate* const other_d = other.d_func();
if (!GeoDataObject::equals(other) ||
d->m_name != other_d->m_name ||
d->m_styleUrl != other_d->m_styleUrl ||
d->m_popularity != other_d->m_popularity ||
d->m_zoomLevel != other_d->m_zoomLevel ||
d->m_visible != other_d->m_visible ||
d->m_role != other_d->m_role ||
d->m_extendedData != other_d->m_extendedData ||
*style() != *other.style())
{
return false;
}
if ((!d->m_styleMap && other_d->m_styleMap) ||
(d->m_styleMap && !other_d->m_styleMap))
{
return false;
}
if ((d->m_styleMap && other_d->m_styleMap) &&
(*d->m_styleMap != *other_d->m_styleMap))
{
return false;
}
if ((!d->m_featureExtendedData && other_d->m_featureExtendedData && other_d->m_featureExtendedData->m_abstractView) ||
(d->m_featureExtendedData && d->m_featureExtendedData->m_abstractView && !other_d->m_featureExtendedData))
{
return false;
}
if ((d->m_featureExtendedData && other_d->m_featureExtendedData) &&
(*d->m_featureExtendedData != *other_d->m_featureExtendedData))
{
return false;
}
return true;
}
EnumFeatureId GeoDataFeature::featureId() const
{
Q_D(const GeoDataFeature);
return d->featureId();
}
QString GeoDataFeature::name() const
{
Q_D(const GeoDataFeature);
return d->m_name;
}
void GeoDataFeature::setName(const QString& value)
{
Q_D(GeoDataFeature);
d->m_name = value;
}
GeoDataSnippet GeoDataFeature::snippet() const
{
Q_D(const GeoDataFeature);
return d->featureExtendedData().m_snippet;
}
void GeoDataFeature::setSnippet(const GeoDataSnippet& snippet)<--- Shadow argument
{
Q_D(GeoDataFeature);
d->featureExtendedData().m_snippet = snippet;
}
QString GeoDataFeature::address() const
{
Q_D(const GeoDataFeature);
if (!d->m_featureExtendedData)
{
return QString();
}
return d->featureExtendedData().m_address;
}
void GeoDataFeature::setAddress(const QString& value)
{
Q_D(GeoDataFeature);
if (value.isEmpty() && !d->m_featureExtendedData)
{
return; // nothing to change
}
d->featureExtendedData().m_address = value;
}
QString GeoDataFeature::phoneNumber() const
{
Q_D(const GeoDataFeature);
if (!d->m_featureExtendedData)
{
return QString();
}
return d->featureExtendedData().m_phoneNumber;
}
void GeoDataFeature::setPhoneNumber(const QString& value)
{
Q_D(GeoDataFeature);
if (value.isEmpty() && !d->m_featureExtendedData)
{
return; // nothing to change
}
d->featureExtendedData().m_phoneNumber = value;
}
QString GeoDataFeature::description() const
{
Q_D(const GeoDataFeature);
if (!d->m_featureExtendedData)
{
return QString();
}
return d->featureExtendedData().m_description;
}
void GeoDataFeature::setDescription(const QString& value)
{
Q_D(GeoDataFeature);
if (value.isEmpty() && !d->m_featureExtendedData)
{
return; // nothing to change
}
d->featureExtendedData().m_description = value;
}
bool GeoDataFeature::descriptionIsCDATA() const
{
Q_D(const GeoDataFeature);
if (!d->m_featureExtendedData)
{
return false;
}
return d->featureExtendedData().m_descriptionCDATA;
}
void GeoDataFeature::setDescriptionCDATA(bool cdata)
{
Q_D(GeoDataFeature);
d->featureExtendedData().m_descriptionCDATA = cdata;
}
const GeoDataAbstractView* GeoDataFeature::abstractViewBase() const
{
Q_D(const GeoDataFeature);
if (!d->m_featureExtendedData)
{
return nullptr;
}
return d->featureExtendedData().m_abstractView;
}
GeoDataAbstractView* GeoDataFeature::abstractViewBase()
{
// FIXME: Calling detach() doesn't help at all because the m_abstractView
// object isn't actually copied in the Private class as well.
// detach();
Q_D(GeoDataFeature);
return d->featureExtendedData().m_abstractView;
}
void GeoDataFeature::setAbstractViewBase(GeoDataAbstractView* abstractView)
{
Q_D(GeoDataFeature);
if (abstractView == nullptr && !d->m_featureExtendedData)
{
return; // nothing to change
}
d->featureExtendedData().m_abstractView = abstractView;
}
QString GeoDataFeature::styleUrl() const
{
Q_D(const GeoDataFeature);
return d->m_styleUrl;
}
void GeoDataFeature::setStyleUrl(const QString& value)
{
Q_D(GeoDataFeature);
d->m_styleUrl = value;
if (value.isEmpty())
{
d->m_style = GeoDataStyle::Ptr();
return;
}
QString styleUrl = value;<--- Shadow local variable
styleUrl.remove(QLatin1Char('#'));
for (auto object = parent(); object != nullptr; object = object->parent())
{
if (GeoDataDocument* doc = geodata_cast<GeoDataDocument>(object))
{
GeoDataStyleMap& styleMap = doc->styleMap(styleUrl);<--- Shadow local variable
const QString normalStyleUrl = styleMap.value(QStringLiteral("normal"));
if (!normalStyleUrl.isEmpty())
{
styleUrl = normalStyleUrl;
styleUrl.remove(QLatin1Char('#'));
}
// Not calling setStyle here because we don't want
// re-parenting of the style
d->m_style = doc->style(styleUrl);
break;
}
}
}
bool GeoDataFeature::isVisible() const
{
Q_D(const GeoDataFeature);
return d->m_visible;
}
void GeoDataFeature::setVisible(bool value)
{
Q_D(GeoDataFeature);
d->m_visible = value;
}
bool GeoDataFeature::isGloballyVisible() const
{
Q_D(const GeoDataFeature);
if (parent() == nullptr)
{
return d->m_visible;
}
const GeoDataContainer* container = static_cast<const GeoDataContainer*>(parent());
return d->m_visible && container->isGloballyVisible();
}
const GeoDataTimeSpan& GeoDataFeature::timeSpan() const
{
Q_D(const GeoDataFeature);
return d->featureExtendedData().m_timeSpan;
}
GeoDataTimeSpan& GeoDataFeature::timeSpan()
{
Q_D(GeoDataFeature);
return d->featureExtendedData().m_timeSpan;
}
void GeoDataFeature::setTimeSpan(const GeoDataTimeSpan& timeSpan)<--- Shadow argument
{
Q_D(GeoDataFeature);
d->featureExtendedData().m_timeSpan = timeSpan;
}
const GeoDataTimeStamp& GeoDataFeature::timeStamp() const
{
Q_D(const GeoDataFeature);
return d->featureExtendedData().m_timeStamp;
}
GeoDataTimeStamp& GeoDataFeature::timeStamp()
{
Q_D(GeoDataFeature);
return d->featureExtendedData().m_timeStamp;
}
void GeoDataFeature::setTimeStamp(const GeoDataTimeStamp& timeStamp)<--- Shadow argument
{
Q_D(GeoDataFeature);
d->featureExtendedData().m_timeStamp = timeStamp;
}
const GeoDataExtendedData& GeoDataFeature::extendedData() const
{
Q_D(const GeoDataFeature);
return d->m_extendedData;
}
GeoDataStyle::ConstPtr GeoDataFeature::style() const
{
Q_D(const GeoDataFeature);
if (d->m_style)
{
return d->m_style;
}
static const QSharedPointer<const GeoDataStyle> s_defaultStyle(new GeoDataStyle);
return s_defaultStyle;
}
GeoDataStyle::ConstPtr GeoDataFeature::customStyle() const
{
Q_D(const GeoDataFeature);
return d->m_style;
}
void GeoDataFeature::setStyle(const GeoDataStyle::Ptr& style)<--- Shadow argument
{
Q_D(GeoDataFeature);
if (style)
{
style->setParent(this);
}
d->m_style = style;
}
GeoDataExtendedData& GeoDataFeature::extendedData()
{
Q_D(GeoDataFeature);
return d->m_extendedData;
}
void GeoDataFeature::setExtendedData(const GeoDataExtendedData& extendedData)<--- Shadow argument
{
Q_D(GeoDataFeature);
d->m_extendedData = extendedData;
}
const GeoDataRegion& GeoDataFeature::region() const
{
Q_D(const GeoDataFeature);
return d->featureExtendedData().m_region;
}
GeoDataRegion& GeoDataFeature::region()
{
Q_D(GeoDataFeature);
return d->featureExtendedData().m_region;
}
void GeoDataFeature::setRegion(const GeoDataRegion& region)<--- Shadow argument
{
Q_D(GeoDataFeature);
d->featureExtendedData().m_region = region;
}
const QString GeoDataFeature::role() const
{
Q_D(const GeoDataFeature);
return d->m_role;
}
void GeoDataFeature::setRole(const QString& role)<--- Shadow argument
{
Q_D(GeoDataFeature);
d->m_role = role;
}
const GeoDataStyleMap* GeoDataFeature::styleMap() const
{
Q_D(const GeoDataFeature);
return d->m_styleMap;
}
void GeoDataFeature::setStyleMap(const GeoDataStyleMap* styleMap)<--- Shadow argument
{
Q_D(GeoDataFeature);
d->m_styleMap = styleMap;
}
int GeoDataFeature::zoomLevel() const
{
Q_D(const GeoDataFeature);
return d->m_zoomLevel;
}
void GeoDataFeature::setZoomLevel(int zoomLevel)<--- Shadow argument
{
Q_D(GeoDataFeature);
d->m_zoomLevel = zoomLevel;
}
qint64 GeoDataFeature::popularity() const
{
Q_D(const GeoDataFeature);
return d->m_popularity;
}
void GeoDataFeature::setPopularity(qint64 popularity)<--- Shadow argument
{
Q_D(GeoDataFeature);
d->m_popularity = popularity;
}
void GeoDataFeature::pack(QDataStream& stream) const
{
Q_D(const GeoDataFeature);
GeoDataObject::pack(stream);
stream << d->m_name;
stream << d->featureExtendedData().m_address;
stream << d->featureExtendedData().m_phoneNumber;
stream << d->featureExtendedData().m_description;
stream << d->m_visible;
// stream << d->m_visualCategory;
stream << d->m_role;
stream << d->m_popularity;
stream << d->m_zoomLevel;
}
void GeoDataFeature::unpack(QDataStream& stream)
{
Q_D(GeoDataFeature);
GeoDataObject::unpack(stream);
stream >> d->m_name;
stream >> d->featureExtendedData().m_address;
stream >> d->featureExtendedData().m_phoneNumber;
stream >> d->featureExtendedData().m_description;
stream >> d->m_visible;
// stream >> (int)d->m_visualCategory;
stream >> d->m_role;
stream >> d->m_popularity;
stream >> d->m_zoomLevel;
}
} // namespace Marble
|