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
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687 | /* ============================================================
*
* 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-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*
* ============================================================ */
#include "MarbleMap.h"
// C++ includes
#include <cmath>
// Qt includes
#include <QElapsedTimer>
#include <QtMath>
// Local includes
#include "FloatItemsLayer.h"
#include "FogLayer.h"
#include "FpsLayer.h"
#include "GeometryLayer.h"
#include "GroundLayer.h"
#include "MarbleSplashLayer.h"
#include "PlacemarkLayer.h"
#include "TextureLayer.h"
#include "VectorTileLayer.h"
#include "AbstractFloatItem.h"
#include "DgmlAuxillaryDictionary.h"
#include "FileManager.h"
#include "GeoDataTreeModel.h"
#include "GeoPainter.h"
#include "GeoSceneDocument.h"
#include "GeoSceneFilter.h"
#include "GeoSceneGeodata.h"
#include "GeoSceneHead.h"
#include "GeoSceneLayer.h"
#include "GeoSceneMap.h"
#include "GeoScenePalette.h"
#include "GeoSceneSettings.h"
#include "GeoSceneVector.h"
#include "GeoSceneVectorTileDataset.h"
#include "GeoSceneTextureTileDataset.h"
#include "GeoSceneZoom.h"
#include "GeoDataDocument.h"
#include "GeoDataFeature.h"
#include "GeoDataStyle.h"
#include "GeoDataStyleMap.h"
#include "LayerManager.h"
#include "MapThemeManager.h"
#include "MarbleDirs.h"
#include "MarbleModel.h"
#include "PluginManager.h"
#include "RenderPlugin.h"
#include "StyleBuilder.h"
#include "SunLocator.h"
#include "TileId.h"
#include "TileCoordsPyramid.h"
#include "TileCreator.h"
#include "TileCreatorDialog.h"
#include "TileLoader.h"
#include "ViewParams.h"
#include "ViewportParams.h"
#include "RenderState.h"
#include "digikam_debug.h"
namespace Marble
{
class Q_DECL_HIDDEN MarbleMap::CustomPaintLayer : public LayerInterface
{
public:
explicit CustomPaintLayer(MarbleMap* map)
: m_map(map)
{
}
QStringList renderPosition() const override
{
return QStringList() << QString::fromUtf8("USER_TOOLS");
}
bool render(GeoPainter* painter, ViewportParams* viewport,
const QString& renderPos, GeoSceneLayer* layer) override
{
Q_UNUSED(viewport);
Q_UNUSED(renderPos);
Q_UNUSED(layer);
m_map->customPaint(painter);
return true;
}
qreal zValue() const override
{
return 1.0e6;
}
RenderState renderState() const override
{
return RenderState(QStringLiteral("Custom Map Paint"));
}
QString runtimeTrace() const override
{
return QStringLiteral("CustomPaint");
}
private:
MarbleMap* const m_map = nullptr;
};
class Q_DECL_HIDDEN MarbleMapPrivate
{
friend class Q_DECL_HIDDEN MarbleWidget;
public:
explicit MarbleMapPrivate(MarbleMap* parent, MarbleModel* model);
void updateMapTheme();
void updateProperty(const QString&, bool);
void setDocument(const QString& key);
void updateTileLevel();
void addPlugins();
MarbleMap* const q = nullptr;
// The model we are showing.
MarbleModel* const m_model = nullptr;
bool m_modelIsOwned;
// Parameters for the maps appearance.
ViewParams m_viewParams;
ViewportParams m_viewport;
bool m_showFrameRate;
bool m_showDebugPolygons;
bool m_showDebugBatchRender;
GeoDataRelation::RelationTypes m_visibleRelationTypes;
StyleBuilder m_styleBuilder;
QList<RenderPlugin*> m_renderPlugins;
LayerManager m_layerManager;
MarbleSplashLayer m_marbleSplashLayer;
MarbleMap::CustomPaintLayer m_customPaintLayer;
GeometryLayer m_geometryLayer;
FloatItemsLayer m_floatItemsLayer;
FogLayer m_fogLayer;
GroundLayer m_groundLayer;
TextureLayer m_textureLayer;
PlacemarkLayer m_placemarkLayer;
VectorTileLayer m_vectorTileLayer;
bool m_isLockedToSubSolarPoint;
bool m_isSubSolarPointIconVisible;
RenderState m_renderState;
};
MarbleMapPrivate::MarbleMapPrivate(MarbleMap* parent, MarbleModel* model) :
q(parent),
m_model(model),
m_modelIsOwned(false),
m_viewParams(),
m_showFrameRate(false),
m_showDebugPolygons(false),
m_showDebugBatchRender(false),
m_visibleRelationTypes(GeoDataRelation::RouteFerry),
m_styleBuilder(),
m_layerManager(parent),
m_customPaintLayer(parent),
m_geometryLayer(model->treeModel(), &m_styleBuilder),
m_floatItemsLayer(parent),
m_textureLayer(model->downloadManager(), model->pluginManager(), model->sunLocator(), model->groundOverlayModel()),
m_placemarkLayer(model->placemarkModel(), model->placemarkSelectionModel(), model->clock(), &m_styleBuilder),
m_vectorTileLayer(model->downloadManager(), model->pluginManager(), model->treeModel()),
m_isLockedToSubSolarPoint(false),
m_isSubSolarPointIconVisible(false)
{
m_layerManager.addLayer(&m_floatItemsLayer);
m_layerManager.addLayer(&m_fogLayer);
m_layerManager.addLayer(&m_groundLayer);
m_layerManager.addLayer(&m_geometryLayer);
m_layerManager.addLayer(&m_placemarkLayer);
m_layerManager.addLayer(&m_customPaintLayer);
QObject::connect(m_model, SIGNAL(themeChanged(QString)),
parent, SLOT(updateMapTheme()));
QObject::connect(m_model->fileManager(), SIGNAL(fileAdded(QString)),
parent, SLOT(setDocument(QString)));
QObject::connect(&m_placemarkLayer, SIGNAL(repaintNeeded()),
parent, SIGNAL(repaintNeeded()));
QObject::connect(&m_layerManager, SIGNAL(pluginSettingsChanged()),
parent, SIGNAL(pluginSettingsChanged()));
QObject::connect(&m_layerManager, SIGNAL(repaintNeeded(QRegion)),
parent, SIGNAL(repaintNeeded(QRegion)));
QObject::connect(&m_layerManager, SIGNAL(renderPluginInitialized(RenderPlugin*)),
parent, SIGNAL(renderPluginInitialized(RenderPlugin*)));
QObject::connect(&m_layerManager, SIGNAL(visibilityChanged(QString, bool)),
parent, SLOT(setPropertyValue(QString, bool)));
QObject::connect(&m_geometryLayer, SIGNAL(repaintNeeded()),
parent, SIGNAL(repaintNeeded()));
/*
* Slot handleHighlight finds all placemarks
* that contain the clicked point.
* The placemarks under the clicked position may
* have their styleUrl set to a style map which
* doesn't specify any highlight styleId. Such
* placemarks will be fletered out in GeoGraphicsScene
* and will not be highlighted.
*/
QObject::connect(parent, SIGNAL(highlightedPlacemarksChanged(qreal, qreal, GeoDataCoordinates::Unit)),
&m_geometryLayer, SLOT(handleHighlight(qreal, qreal, GeoDataCoordinates::Unit)));
QObject::connect(&m_floatItemsLayer, SIGNAL(repaintNeeded(QRegion)),
parent, SIGNAL(repaintNeeded(QRegion)));
QObject::connect(&m_floatItemsLayer, SIGNAL(renderPluginInitialized(RenderPlugin*)),
parent, SIGNAL(renderPluginInitialized(RenderPlugin*)));
QObject::connect(&m_floatItemsLayer, SIGNAL(visibilityChanged(QString, bool)),
parent, SLOT(setPropertyValue(QString, bool)));
QObject::connect(&m_floatItemsLayer, SIGNAL(pluginSettingsChanged()),
parent, SIGNAL(pluginSettingsChanged()));
QObject::connect(&m_textureLayer, SIGNAL(tileLevelChanged(int)),
parent, SLOT(updateTileLevel()));
QObject::connect(&m_vectorTileLayer, SIGNAL(tileLevelChanged(int)),
parent, SLOT(updateTileLevel()));
QObject::connect(parent, SIGNAL(radiusChanged(int)),
parent, SLOT(updateTileLevel()));
QObject::connect(&m_textureLayer, SIGNAL(repaintNeeded()),
parent, SIGNAL(repaintNeeded()));
QObject::connect(parent, SIGNAL(visibleLatLonAltBoxChanged(GeoDataLatLonAltBox)),
parent, SIGNAL(repaintNeeded()));
addPlugins();
QObject::connect(model->pluginManager(), SIGNAL(renderPluginsChanged()),
parent, SLOT(addPlugins()));
}
void MarbleMapPrivate::updateProperty(const QString& name, bool show)
{
// earth
if (name == QLatin1String("places"))
{
m_placemarkLayer.setShowPlaces(show);
}
else if (name == QLatin1String("cities"))
{
m_placemarkLayer.setShowCities(show);
}
else if (name == QLatin1String("terrain"))
{
m_placemarkLayer.setShowTerrain(show);
}
else if (name == QLatin1String("otherplaces"))
{
m_placemarkLayer.setShowOtherPlaces(show);
}
// other planets
else if (name == QLatin1String("landingsites"))
{
m_placemarkLayer.setShowLandingSites(show);
}
else if (name == QLatin1String("craters"))
{
m_placemarkLayer.setShowCraters(show);
}
else if (name == QLatin1String("maria"))
{
m_placemarkLayer.setShowMaria(show);
}
else if (name == QLatin1String("relief"))
{
m_textureLayer.setShowRelief(show);
}
for (RenderPlugin* renderPlugin : m_renderPlugins)
{
if (name == renderPlugin->nameId())
{
if (renderPlugin->visible() == show)
{
break;
}
renderPlugin->setVisible(show);
break;
}
}
}
void MarbleMapPrivate::addPlugins()
{
for (const RenderPlugin* factory : m_model->pluginManager()->renderPlugins())
{
bool alreadyCreated = false;
for (const RenderPlugin* existing : m_renderPlugins)
{
if (existing->nameId() == factory->nameId())
{
alreadyCreated = true;
break;
}
}
if (alreadyCreated)
{
continue;
}
RenderPlugin* const renderPlugin = factory->newInstance(m_model);
Q_ASSERT(renderPlugin && "Plugin must not return null when requesting a new instance.");
m_renderPlugins << renderPlugin;
if (AbstractFloatItem* const floatItem = qobject_cast<AbstractFloatItem*>(renderPlugin))
{
m_floatItemsLayer.addFloatItem(floatItem);
}
else
{
m_layerManager.addRenderPlugin(renderPlugin);
}
}
}
// ----------------------------------------------------------------
MarbleMap::MarbleMap()
: d(new MarbleMapPrivate(this, new MarbleModel(this)))
{
// nothing to do
}
MarbleMap::MarbleMap(MarbleModel* model)
: d(new MarbleMapPrivate(this, model))
{
d->m_modelIsOwned = false;
}
MarbleMap::~MarbleMap()
{
MarbleModel* model = d->m_modelIsOwned ? d->m_model : nullptr;
d->m_layerManager.removeLayer(&d->m_customPaintLayer);
d->m_layerManager.removeLayer(&d->m_geometryLayer);
d->m_layerManager.removeLayer(&d->m_floatItemsLayer);
d->m_layerManager.removeLayer(&d->m_fogLayer);
d->m_layerManager.removeLayer(&d->m_placemarkLayer);
d->m_layerManager.removeLayer(&d->m_textureLayer);
d->m_layerManager.removeLayer(&d->m_groundLayer);
qDeleteAll(d->m_renderPlugins);
delete d;
delete model; // delete the model after private data
}
MarbleModel* MarbleMap::model() const
{
return d->m_model;
}
ViewportParams* MarbleMap::viewport()
{
return &d->m_viewport;
}
const ViewportParams* MarbleMap::viewport() const
{
return &d->m_viewport;
}
void MarbleMap::setMapQualityForViewContext(MapQuality quality, ViewContext viewContext)
{
d->m_viewParams.setMapQualityForViewContext(quality, viewContext);
// Update texture map during the repaint that follows:
d->m_textureLayer.setNeedsUpdate();
}
MapQuality MarbleMap::mapQuality(ViewContext viewContext) const
{
return d->m_viewParams.mapQuality(viewContext);
}
MapQuality MarbleMap::mapQuality() const
{
return d->m_viewParams.mapQuality();
}
void MarbleMap::setViewContext(ViewContext viewContext)
{
if (d->m_viewParams.viewContext() == viewContext)
{
return;
}
const MapQuality oldQuality = d->m_viewParams.mapQuality();
d->m_viewParams.setViewContext(viewContext);
Q_EMIT viewContextChanged(viewContext);
if (d->m_viewParams.mapQuality() != oldQuality)
{
// Update texture map during the repaint that follows:
d->m_textureLayer.setNeedsUpdate();
Q_EMIT repaintNeeded();
}
}
ViewContext MarbleMap::viewContext() const
{
return d->m_viewParams.viewContext();
}
void MarbleMap::setSize(int width, int height)
{
setSize(QSize(width, height));
}
void MarbleMap::setSize(const QSize& size)
{
d->m_viewport.setSize(size);
Q_EMIT visibleLatLonAltBoxChanged(d->m_viewport.viewLatLonAltBox());
}
QSize MarbleMap::size() const
{
return QSize(d->m_viewport.width(), d->m_viewport.height());
}
int MarbleMap::width() const
{
return d->m_viewport.width();
}
int MarbleMap::height() const
{
return d->m_viewport.height();
}
int MarbleMap::radius() const
{
return d->m_viewport.radius();
}
void MarbleMap::setRadius(int radius)
{
const int oldRadius = d->m_viewport.radius();
d->m_viewport.setRadius(radius);
if (oldRadius != d->m_viewport.radius())
{
Q_EMIT radiusChanged(radius);
Q_EMIT visibleLatLonAltBoxChanged(d->m_viewport.viewLatLonAltBox());
}
}
int MarbleMap::preferredRadiusCeil(int radius) const
{
return d->m_textureLayer.preferredRadiusCeil(radius);
}
int MarbleMap::preferredRadiusFloor(int radius) const
{
return d->m_textureLayer.preferredRadiusFloor(radius);
}
int MarbleMap::tileZoomLevel() const
{
auto const tileZoomLevel = qMax(d->m_textureLayer.tileZoomLevel(), d->m_vectorTileLayer.tileZoomLevel());
return tileZoomLevel >= 0 ? tileZoomLevel : qMin<int>(qMax<int>(qLn(d->m_viewport.radius() * 4 / 256) / qLn(2.0), 1), d->m_styleBuilder.maximumZoomLevel());
}
qreal MarbleMap::centerLatitude() const
{
// Calculate translation of center point
const qreal centerLat = d->m_viewport.centerLatitude();
return centerLat * RAD2DEG;
}
bool MarbleMap::hasFeatureAt(const QPoint& position) const
{
return d->m_placemarkLayer.hasPlacemarkAt(position) || d->m_geometryLayer.hasFeatureAt(position, viewport());
}
qreal MarbleMap::centerLongitude() const
{
// Calculate translation of center point
const qreal centerLon = d->m_viewport.centerLongitude();
return centerLon * RAD2DEG;
}
int MarbleMap::minimumZoom() const
{
if (d->m_model->mapTheme())
{
return d->m_model->mapTheme()->head()->zoom()->minimum();
}
return 950;
}
int MarbleMap::maximumZoom() const
{
if (d->m_model->mapTheme())
{
return d->m_model->mapTheme()->head()->zoom()->maximum();
}
return 2100;
}
bool MarbleMap::discreteZoom() const
{
if (d->m_model->mapTheme())
{
return d->m_model->mapTheme()->head()->zoom()->discrete();
}
return false;
}
QVector<const GeoDataFeature*> MarbleMap::whichFeatureAt(const QPoint& curpos) const
{
return d->m_placemarkLayer.whichPlacemarkAt(curpos) + d->m_geometryLayer.whichFeatureAt(curpos, viewport());
}
void MarbleMap::reload()
{
d->m_textureLayer.reload();
d->m_vectorTileLayer.reload();
}
void MarbleMap::downloadRegion(QVector<TileCoordsPyramid> const& pyramid)
{
Q_ASSERT(textureLayer());
Q_ASSERT(!pyramid.isEmpty());
QElapsedTimer t;
t.start();
// When downloading a region (the author of these lines thinks) most users probably expect
// the download to begin with the low resolution tiles and then procede level-wise to
// higher resolution tiles. In order to achieve this, we start requesting downloads of
// high resolution tiles and request the low resolution tiles at the end because
// DownloadQueueSet (silly name) is implemented as stack.
int const first = 0;
int tilesCount = 0;
for (int level = pyramid[first].bottomLevel(); level >= pyramid[first].topLevel(); --level)
{
QSet<TileId> tileIdSet;
for (int i = 0; i < pyramid.size(); ++i)
{
QRect const coords = pyramid[i].coords(level);
qCDebug(DIGIKAM_MARBLE_LOG) << "MarbleMap::downloadRegion level:" << level << "tile coords:" << coords;
int x1, y1, x2, y2;
coords.getCoords(&x1, &y1, &x2, &y2);
for (int x = x1; x <= x2; ++x)
{
for (int y = y1; y <= y2; ++y)
{
TileId const stackedTileId(0, level, x, y);
tileIdSet.insert(stackedTileId);
// FIXME: use lazy evaluation to not generate up to 100k tiles in one go
// this can take considerable time even on very fast systems
// in contrast generating the TileIds on the fly when they are needed
// does not seem to affect download speed.
}
}
}
QSetIterator<TileId> i(tileIdSet);
while (i.hasNext())
{
TileId const tileId = i.next();
d->m_textureLayer.downloadStackedTile(tileId);
d->m_vectorTileLayer.downloadTile(tileId);
qCDebug(DIGIKAM_MARBLE_LOG) << "TileDownload" << tileId;
}
tilesCount += tileIdSet.count();
}
// Needed for downloading unique tiles only. Much faster than if tiles for each level is downloaded separately
int const elapsedMs = t.elapsed();
qCDebug(DIGIKAM_MARBLE_LOG) << "MarbleMap::downloadRegion:" << tilesCount << "tiles, " << elapsedMs << "ms";
}
void MarbleMap::highlightRouteRelation(qint64 osmId, bool enabled)
{
d->m_geometryLayer.highlightRouteRelation(osmId, enabled);
}
bool MarbleMap::propertyValue(const QString& name) const
{
bool value;
if (d->m_model->mapTheme())
{
d->m_model->mapTheme()->settings()->propertyValue(name, value);
}
else
{
value = false;
qCDebug(DIGIKAM_MARBLE_LOG) << "WARNING: Failed to access a map theme! Property: " << name;
}
return value;
}
bool MarbleMap::showOverviewMap() const
{
return propertyValue(QStringLiteral("overviewmap"));
}
bool MarbleMap::showScaleBar() const
{
return propertyValue(QStringLiteral("scalebar"));
}
bool MarbleMap::showCompass() const
{
return propertyValue(QStringLiteral("compass"));
}
bool MarbleMap::showGrid() const
{
return propertyValue(QStringLiteral("coordinate-grid"));
}
bool MarbleMap::showClouds() const
{
return d->m_viewParams.showClouds();
}
bool MarbleMap::showSunShading() const
{
return d->m_textureLayer.showSunShading();
}
bool MarbleMap::showCityLights() const
{
return d->m_textureLayer.showCityLights();
}
bool MarbleMap::isLockedToSubSolarPoint() const
{
return d->m_isLockedToSubSolarPoint;
}
bool MarbleMap::isSubSolarPointIconVisible() const
{
return d->m_isSubSolarPointIconVisible;
}
bool MarbleMap::showAtmosphere() const
{
return d->m_viewParams.showAtmosphere();
}
bool MarbleMap::showCrosshairs() const
{
bool visible = false;
QList<RenderPlugin*> pluginList = renderPlugins();
QList<RenderPlugin*>::const_iterator i = pluginList.constBegin();
QList<RenderPlugin*>::const_iterator const end = pluginList.constEnd();
for (; i != end; ++i)
{
if ((*i)->nameId() == QLatin1String("crosshairs"))
{
visible = (*i)->visible();
}
}
return visible;
}
bool MarbleMap::showPlaces() const
{
return propertyValue(QStringLiteral("places"));
}
bool MarbleMap::showCities() const
{
return propertyValue(QStringLiteral("cities"));
}
bool MarbleMap::showTerrain() const
{
return propertyValue(QStringLiteral("terrain"));
}
bool MarbleMap::showOtherPlaces() const
{
return propertyValue(QStringLiteral("otherplaces"));
}
bool MarbleMap::showRelief() const
{
return propertyValue(QStringLiteral("relief"));
}
bool MarbleMap::showIceLayer() const
{
return propertyValue(QStringLiteral("ice"));
}
bool MarbleMap::showBorders() const
{
return propertyValue(QStringLiteral("borders"));
}
bool MarbleMap::showRivers() const
{
return propertyValue(QStringLiteral("rivers"));
}
bool MarbleMap::showLakes() const
{
return propertyValue(QStringLiteral("lakes"));
}
bool MarbleMap::showFrameRate() const
{
return d->m_showFrameRate;
}
bool MarbleMap::showBackground() const
{
return d->m_layerManager.showBackground();
}
GeoDataRelation::RelationTypes MarbleMap::visibleRelationTypes() const
{
return d->m_visibleRelationTypes;
}
quint64 MarbleMap::volatileTileCacheLimit() const
{
return d->m_textureLayer.volatileCacheLimit();
}
void MarbleMap::rotateBy(qreal deltaLon, qreal deltaLat)
{
centerOn(d->m_viewport.centerLongitude() * RAD2DEG + deltaLon,
d->m_viewport.centerLatitude() * RAD2DEG + deltaLat);
}
void MarbleMap::centerOn(const qreal lon, const qreal lat)
{
d->m_viewport.centerOn(lon * DEG2RAD, lat * DEG2RAD);
Q_EMIT visibleLatLonAltBoxChanged(d->m_viewport.viewLatLonAltBox());
}
void MarbleMap::setCenterLatitude(qreal lat)
{
centerOn(centerLongitude(), lat);
}
void MarbleMap::setCenterLongitude(qreal lon)
{
centerOn(lon, centerLatitude());
}
Projection MarbleMap::projection() const
{
return d->m_viewport.projection();
}
void MarbleMap::setProjection(Projection projection)
{
if (d->m_viewport.projection() == projection)
{
return;
}
Q_EMIT projectionChanged(projection);
d->m_viewport.setProjection(projection);
d->m_textureLayer.setProjection(projection);
Q_EMIT visibleLatLonAltBoxChanged(d->m_viewport.viewLatLonAltBox());
}
bool MarbleMap::screenCoordinates(qreal lon, qreal lat,
qreal& x, qreal& y) const
{
return d->m_viewport.screenCoordinates(lon * DEG2RAD, lat * DEG2RAD, x, y);
}
bool MarbleMap::geoCoordinates(int x, int y,
qreal& lon, qreal& lat,
GeoDataCoordinates::Unit unit) const
{
return d->m_viewport.geoCoordinates(x, y, lon, lat, unit);
}
void MarbleMapPrivate::setDocument(const QString& key)
{
if (!m_model->mapTheme())
{
// Happens if no valid map theme is set or at application startup
// if a file is passed via command line parameters and the last
// map theme has not been loaded yet
/**
* @todo Do we need to queue the document and process it once a map
* theme becomes available?
*/
return;
}
GeoDataDocument* doc = m_model->fileManager()->at(key);
for (const GeoSceneLayer* layer : m_model->mapTheme()->map()->layers())
{
if (layer->backend() != QString::fromUtf8(dgml::dgmlValue_geodata)
&& layer->backend() != QString::fromUtf8(dgml::dgmlValue_vector))
{
continue;
}
// look for documents
for (const GeoSceneAbstractDataset* dataset : layer->datasets())
{
const GeoSceneGeodata* data = static_cast<const GeoSceneGeodata*>(dataset);
QString containername = data->sourceFile();
QString colorize = data->colorize();
if (key == containername)
{
if (colorize == QLatin1String("land"))
{
m_textureLayer.addLandDocument(doc);
}
if (colorize == QLatin1String("sea"))
{
m_textureLayer.addSeaDocument(doc);
}
// set visibility according to theme property
if (!data->property().isEmpty())
{
bool value;
m_model->mapTheme()->settings()->propertyValue(data->property(), value);
doc->setVisible(value);
m_model->treeModel()->updateFeature(doc);
}
}
}
}
}
void MarbleMapPrivate::updateTileLevel()
{
auto const tileZoomLevel = q->tileZoomLevel();
m_geometryLayer.setTileLevel(tileZoomLevel);
m_placemarkLayer.setTileLevel(tileZoomLevel);
Q_EMIT q->tileLevelChanged(tileZoomLevel);
}
// Used to be paintEvent()
void MarbleMap::paint(GeoPainter& painter, const QRect& dirtyRect)
{
Q_UNUSED(dirtyRect);
if (d->m_showDebugPolygons)
{
if (viewContext() == Animation)
{
painter.setDebugPolygonsLevel(1);
}
else
{
painter.setDebugPolygonsLevel(2);
}
}
painter.setDebugBatchRender(d->m_showDebugBatchRender);
if (!d->m_model->mapTheme())
{
qCDebug(DIGIKAM_MARBLE_LOG) << "No theme yet!";
d->m_marbleSplashLayer.render(&painter, &d->m_viewport);
return;
}
QElapsedTimer t;
t.start();
RenderStatus const oldRenderStatus = d->m_renderState.status();
d->m_layerManager.renderLayers(&painter, &d->m_viewport);
d->m_renderState = d->m_layerManager.renderState();
bool const parsing = d->m_model->fileManager()->pendingFiles() > 0;
d->m_renderState.addChild(RenderState(QStringLiteral("Files"), parsing ? WaitingForData : Complete));
RenderStatus const newRenderStatus = d->m_renderState.status();
if (oldRenderStatus != newRenderStatus)
{
Q_EMIT renderStatusChanged(newRenderStatus);
}
Q_EMIT renderStateChanged(d->m_renderState);
if (d->m_showFrameRate)
{
FpsLayer fpsPainter(&t);
fpsPainter.paint(&painter);
}
const qreal fps = 1000.0 / (qreal)(t.elapsed());
Q_EMIT framesPerSecond(fps);
}
void MarbleMap::customPaint(GeoPainter* painter)
{
Q_UNUSED(painter);
}
QString MarbleMap::mapThemeId() const
{
return d->m_model->mapThemeId();
}
void MarbleMap::setMapThemeId(const QString& mapThemeId)
{
d->m_model->setMapThemeId(mapThemeId);
}
void MarbleMapPrivate::updateMapTheme()
{
m_layerManager.removeLayer(&m_textureLayer);
// FIXME Find a better way to do this reset. Maybe connect to themeChanged SIGNAL?
m_vectorTileLayer.reset();
m_layerManager.removeLayer(&m_vectorTileLayer);
m_layerManager.removeLayer(&m_groundLayer);
QObject::connect(m_model->mapTheme()->settings(), SIGNAL(valueChanged(QString, bool)),
q, SLOT(updateProperty(QString, bool)));
QObject::connect(m_model->mapTheme()->settings(), SIGNAL(valueChanged(QString, bool)),
m_model, SLOT(updateProperty(QString, bool)));
q->setPropertyValue(QStringLiteral("clouds_data"), m_viewParams.showClouds());
QColor backgroundColor = m_styleBuilder.effectColor(m_model->mapTheme()->map()->backgroundColor());
m_groundLayer.setColor(backgroundColor);
// Check whether there is a texture layer and vectortile layer available:
if (m_model->mapTheme()->map()->hasTextureLayers())
{
const GeoSceneSettings* const settings = m_model->mapTheme()->settings();
const GeoSceneGroup* const textureLayerSettings = settings ? settings->group(QString::fromUtf8("Texture Layers")) : nullptr;
const GeoSceneGroup* const vectorTileLayerSettings = settings ? settings->group(QString::fromUtf8("VectorTile Layers")) : nullptr;
bool textureLayersOk = true;
bool vectorTileLayersOk = true;
// textures will contain texture layers and
// vectorTiles vectortile layers
QVector<const GeoSceneTextureTileDataset*> textures;
QVector<const GeoSceneVectorTileDataset*> vectorTiles;
for (GeoSceneLayer* layer : m_model->mapTheme()->map()->layers())
{
if (layer->backend() == QString::fromUtf8(dgml::dgmlValue_texture))
{
for (const GeoSceneAbstractDataset* pos : layer->datasets())
{
const GeoSceneTextureTileDataset* const texture = dynamic_cast<GeoSceneTextureTileDataset const*>(pos);
if (!texture)
{
continue;
}
const QString sourceDir = texture->sourceDir();
const QString installMap = texture->installMap();
const QString role = layer->role();
// If the tiles aren't already there, put up a progress dialog
// while creating them.
if (!TileLoader::baseTilesAvailable(*texture)<--- Assuming that condition '!TileLoader::baseTilesAvailable(*texture)' is not redundant
&& !installMap.isEmpty())
{
qCDebug(DIGIKAM_MARBLE_LOG) << "Base tiles not available. Creating Tiles ... \n"
<< "SourceDir: " << sourceDir << "InstallMap:" << installMap;
TileCreator* tileCreator = new TileCreator(
sourceDir,
installMap,
(role == QLatin1String("dem")) ? QString::fromUtf8("true") : QString::fromUtf8("false"));
tileCreator->setTileFormat(texture->fileFormat().toLower());
QPointer<TileCreatorDialog> tileCreatorDlg = new TileCreatorDialog(tileCreator, nullptr);
tileCreatorDlg->setSummary(m_model->mapTheme()->head()->name(),
m_model->mapTheme()->head()->description());
tileCreatorDlg->exec();
if (TileLoader::baseTilesAvailable(*texture))<--- Condition 'TileLoader::baseTilesAvailable(*texture)' is always false
{
qCDebug(DIGIKAM_MARBLE_LOG) << "Base tiles for" << sourceDir << "successfully created.";
}
else
{
qCWarning(DIGIKAM_MARBLE_LOG) << "Some or all base tiles for" << sourceDir << "could not be created.";
}
delete tileCreatorDlg;
}
if (TileLoader::baseTilesAvailable(*texture))
{
textures.append(texture);
}
else
{
qCWarning(DIGIKAM_MARBLE_LOG) << "Base tiles for" << sourceDir << "not available. Skipping all texture layers.";
textureLayersOk = false;
}
}
}
else if (layer->backend() == QString::fromUtf8(dgml::dgmlValue_vectortile))
{
for (const GeoSceneAbstractDataset* pos : layer->datasets())
{
const GeoSceneVectorTileDataset* const vectorTile = dynamic_cast<GeoSceneVectorTileDataset const*>(pos);
if (!vectorTile)
{
continue;
}
const QString sourceDir = vectorTile->sourceDir();
const QString installMap = vectorTile->installMap();
const QString role = layer->role();
// If the tiles aren't already there, put up a progress dialog
// while creating them.
if (!TileLoader::baseTilesAvailable(*vectorTile)<--- Assuming that condition '!TileLoader::baseTilesAvailable(*vectorTile)' is not redundant
&& !installMap.isEmpty())
{
qCDebug(DIGIKAM_MARBLE_LOG) << "Base tiles not available. Creating Tiles ... \n"
<< "SourceDir: " << sourceDir << "InstallMap:" << installMap;
TileCreator* tileCreator = new TileCreator(
sourceDir,
installMap,
(role == QLatin1String("dem")) ? QString::fromUtf8("true") : QString::fromUtf8("false"));
tileCreator->setTileFormat(vectorTile->fileFormat().toLower());
QPointer<TileCreatorDialog> tileCreatorDlg = new TileCreatorDialog(tileCreator, nullptr);
tileCreatorDlg->setSummary(m_model->mapTheme()->head()->name(),
m_model->mapTheme()->head()->description());
tileCreatorDlg->exec();
if (TileLoader::baseTilesAvailable(*vectorTile))<--- Condition 'TileLoader::baseTilesAvailable(*vectorTile)' is always false
{
qCDebug(DIGIKAM_MARBLE_LOG) << "Base tiles for" << sourceDir << "successfully created.";
}
else
{
qCDebug(DIGIKAM_MARBLE_LOG) << "Some or all base tiles for" << sourceDir << "could not be created.";
}
delete tileCreatorDlg;
}
if (TileLoader::baseTilesAvailable(*vectorTile))
{
vectorTiles.append(vectorTile);
}
else
{
qCWarning(DIGIKAM_MARBLE_LOG) << "Base tiles for" << sourceDir << "not available. Skipping all texture layers.";
vectorTileLayersOk = false;
}
}
}
}
QString seafile, landfile;
if (!m_model->mapTheme()->map()->filters().isEmpty())
{
const GeoSceneFilter* filter = m_model->mapTheme()->map()->filters().first();
if (filter->type() == QLatin1String("colorize"))
{
//no need to look up with MarbleDirs twice so they are left null for now
QList<const GeoScenePalette*> palette = filter->palette();
for (const GeoScenePalette* curPalette : palette)
{
if (curPalette->type() == QLatin1String("sea"))
{
seafile = MarbleDirs::path(curPalette->file());
}
else if (curPalette->type() == QLatin1String("land"))
{
landfile = MarbleDirs::path(curPalette->file());
}
}
//look up locations if they are empty
if (seafile.isEmpty())
{
seafile = MarbleDirs::path(QStringLiteral("seacolors.leg"));
}
if (landfile.isEmpty())
{
landfile = MarbleDirs::path(QStringLiteral("landcolors.leg"));
}
}
}
m_textureLayer.setMapTheme(textures, textureLayerSettings, seafile, landfile);
m_textureLayer.setProjection(m_viewport.projection());
m_textureLayer.setShowRelief(q->showRelief());
m_vectorTileLayer.setMapTheme(vectorTiles, vectorTileLayerSettings);
if (m_textureLayer.layerCount() == 0)
{
m_layerManager.addLayer(&m_groundLayer);
}
if (textureLayersOk)
{
m_layerManager.addLayer(&m_textureLayer);
}
if (vectorTileLayersOk && !vectorTiles.isEmpty())
{
m_layerManager.addLayer(&m_vectorTileLayer);
}
}
else
{
m_layerManager.addLayer(&m_groundLayer);
m_textureLayer.setMapTheme(QVector<const GeoSceneTextureTileDataset*>(), nullptr, QString::fromUtf8(""), QString::fromUtf8(""));
m_vectorTileLayer.setMapTheme(QVector<const GeoSceneVectorTileDataset*>(), nullptr);
}
// earth
m_placemarkLayer.setShowPlaces(q->showPlaces());
m_placemarkLayer.setShowCities(q->showCities());
m_placemarkLayer.setShowTerrain(q->showTerrain());
m_placemarkLayer.setShowOtherPlaces(q->showOtherPlaces());
m_placemarkLayer.setShowLandingSites(q->propertyValue(QStringLiteral("landingsites")));
m_placemarkLayer.setShowCraters(q->propertyValue(QStringLiteral("craters")));
m_placemarkLayer.setShowMaria(q->propertyValue(QStringLiteral("maria")));
m_styleBuilder.setDefaultLabelColor(m_model->mapTheme()->map()->labelColor());
m_placemarkLayer.requestStyleReset();
for (RenderPlugin* renderPlugin : m_renderPlugins)
{
bool propertyAvailable = false;
m_model->mapTheme()->settings()->propertyAvailable(renderPlugin->nameId(), propertyAvailable);
bool propertyValue = false;
m_model->mapTheme()->settings()->propertyValue(renderPlugin->nameId(), propertyValue);
if (propertyAvailable)
{
renderPlugin->setVisible(propertyValue);
}
}
Q_EMIT q->themeChanged(m_model->mapTheme()->head()->mapThemeId());
}
void MarbleMap::setPropertyValue(const QString& name, bool value)
{
qCDebug(DIGIKAM_MARBLE_LOG) << "In MarbleMap the property " << name << "was set to " << value;
if (d->m_model->mapTheme())
{
d->m_model->mapTheme()->settings()->setPropertyValue(name, value);
d->m_textureLayer.setNeedsUpdate();
Q_EMIT propertyValueChanged(name, value);
}
else
{
qCDebug(DIGIKAM_MARBLE_LOG) << "WARNING: Failed to access a map theme! Property: " << name;
}
if (d->m_textureLayer.layerCount() == 0)
{
d->m_layerManager.addLayer(&d->m_groundLayer);
}
else
{
d->m_layerManager.removeLayer(&d->m_groundLayer);
}
}
void MarbleMap::setShowOverviewMap(bool visible)
{
setPropertyValue(QStringLiteral("overviewmap"), visible);
}
void MarbleMap::setShowScaleBar(bool visible)
{
setPropertyValue(QStringLiteral("scalebar"), visible);
}
void MarbleMap::setShowCompass(bool visible)
{
setPropertyValue(QStringLiteral("compass"), visible);
}
void MarbleMap::setShowAtmosphere(bool visible)
{
for (RenderPlugin* plugin : renderPlugins())
{
if (plugin->nameId() == QLatin1String("atmosphere"))
{
plugin->setVisible(visible);
}
}
d->m_viewParams.setShowAtmosphere(visible);
}
void MarbleMap::setShowCrosshairs(bool visible)
{
QList<RenderPlugin*> pluginList = renderPlugins();
QList<RenderPlugin*>::const_iterator i = pluginList.constBegin();
QList<RenderPlugin*>::const_iterator const end = pluginList.constEnd();
for (; i != end; ++i)
{
if ((*i)->nameId() == QLatin1String("crosshairs"))
{
(*i)->setVisible(visible);
}
}
}
void MarbleMap::setShowClouds(bool visible)
{
d->m_viewParams.setShowClouds(visible);
setPropertyValue(QStringLiteral("clouds_data"), visible);
}
void MarbleMap::setShowSunShading(bool visible)
{
d->m_textureLayer.setShowSunShading(visible);
}
void MarbleMap::setShowCityLights(bool visible)
{
d->m_textureLayer.setShowCityLights(visible);
setPropertyValue(QStringLiteral("citylights"), visible);
}
void MarbleMap::setLockToSubSolarPoint(bool visible)
{
disconnect(d->m_model->sunLocator(), SIGNAL(positionChanged(qreal, qreal)),
this, SLOT(centerOn(qreal, qreal)));
if (isLockedToSubSolarPoint() != visible)
{
d->m_isLockedToSubSolarPoint = visible;
}
if (isLockedToSubSolarPoint())
{
connect(d->m_model->sunLocator(), SIGNAL(positionChanged(qreal, qreal)),
this, SLOT(centerOn(qreal, qreal)));
centerOn(d->m_model->sunLocator()->getLon(), d->m_model->sunLocator()->getLat());
}
else if (visible)
{
qCDebug(DIGIKAM_MARBLE_LOG) << "Ignoring centering on sun, since the sun plugin is not loaded.";
}
}
void MarbleMap::setSubSolarPointIconVisible(bool visible)
{
if (isSubSolarPointIconVisible() != visible)
{
d->m_isSubSolarPointIconVisible = visible;
}
}
void MarbleMap::setShowTileId(bool visible)
{
d->m_textureLayer.setShowTileId(visible);
}
void MarbleMap::setShowGrid(bool visible)
{
setPropertyValue(QStringLiteral("coordinate-grid"), visible);
}
void MarbleMap::setShowPlaces(bool visible)
{
setPropertyValue(QStringLiteral("places"), visible);
}
void MarbleMap::setShowCities(bool visible)
{
setPropertyValue(QStringLiteral("cities"), visible);
}
void MarbleMap::setShowTerrain(bool visible)
{
setPropertyValue(QStringLiteral("terrain"), visible);
}
void MarbleMap::setShowOtherPlaces(bool visible)
{
setPropertyValue(QStringLiteral("otherplaces"), visible);
}
void MarbleMap::setShowRelief(bool visible)
{
setPropertyValue(QStringLiteral("relief"), visible);
}
void MarbleMap::setShowIceLayer(bool visible)
{
setPropertyValue(QStringLiteral("ice"), visible);
}
void MarbleMap::setShowBorders(bool visible)
{
setPropertyValue(QStringLiteral("borders"), visible);
}
void MarbleMap::setShowRivers(bool visible)
{
setPropertyValue(QStringLiteral("rivers"), visible);
}
void MarbleMap::setShowLakes(bool visible)
{
setPropertyValue(QStringLiteral("lakes"), visible);
}
void MarbleMap::setShowFrameRate(bool visible)
{
d->m_showFrameRate = visible;
}
void MarbleMap::setShowRuntimeTrace(bool visible)
{
if (visible != d->m_layerManager.showRuntimeTrace())
{
d->m_layerManager.setShowRuntimeTrace(visible);
Q_EMIT repaintNeeded();
}
}
bool MarbleMap::showRuntimeTrace() const
{
return d->m_layerManager.showRuntimeTrace();
}
void MarbleMap::setShowDebugPolygons(bool visible)
{
if (visible != d->m_showDebugPolygons)
{
d->m_showDebugPolygons = visible;
Q_EMIT repaintNeeded();
}
}
bool MarbleMap::showDebugPolygons() const
{
return d->m_showDebugPolygons;
}
void MarbleMap::setShowDebugBatchRender(bool visible)
{
qCDebug(DIGIKAM_MARBLE_LOG) << Q_FUNC_INFO << visible;
if (visible != d->m_showDebugBatchRender)
{
d->m_showDebugBatchRender = visible;
Q_EMIT repaintNeeded();
}
}
bool MarbleMap::showDebugBatchRender() const
{
return d->m_showDebugBatchRender;
}
void MarbleMap::setShowDebugPlacemarks(bool visible)
{
if (visible != d->m_placemarkLayer.isDebugModeEnabled())
{
d->m_placemarkLayer.setDebugModeEnabled(visible);
Q_EMIT repaintNeeded();
}
}
bool MarbleMap::showDebugPlacemarks() const
{
return d->m_placemarkLayer.isDebugModeEnabled();
}
void MarbleMap::setLevelTagDebugModeEnabled(bool visible)
{
if (visible != d->m_geometryLayer.levelTagDebugModeEnabled())
{
d->m_geometryLayer.setLevelTagDebugModeEnabled(visible);
d->m_placemarkLayer.setLevelTagDebugModeEnabled(visible);
Q_EMIT repaintNeeded();
}
}
bool MarbleMap::levelTagDebugModeEnabled() const
{
return d->m_geometryLayer.levelTagDebugModeEnabled() &&
d->m_placemarkLayer.levelTagDebugModeEnabled();
}
void MarbleMap::setDebugLevelTag(int level)
{
d->m_geometryLayer.setDebugLevelTag(level);
d->m_placemarkLayer.setDebugLevelTag(level);
}
int MarbleMap::debugLevelTag() const
{
return d->m_geometryLayer.debugLevelTag();
}
void MarbleMap::setShowBackground(bool visible)
{
d->m_layerManager.setShowBackground(visible);
}
void MarbleMap::setVisibleRelationTypes(GeoDataRelation::RelationTypes relationTypes)
{
if (d->m_visibleRelationTypes != relationTypes)
{
d->m_visibleRelationTypes = relationTypes;
d->m_geometryLayer.setVisibleRelationTypes(relationTypes);
Q_EMIT visibleRelationTypesChanged(d->m_visibleRelationTypes);
}
}
void MarbleMap::notifyMouseClick(int x, int y)
{
qreal lon = 0;
qreal lat = 0;
const bool valid = geoCoordinates(x, y, lon, lat, GeoDataCoordinates::Radian);
if (valid)
{
Q_EMIT mouseClickGeoPosition(lon, lat, GeoDataCoordinates::Radian);
}
}
void MarbleMap::clearVolatileTileCache()
{
d->m_vectorTileLayer.reset();
d->m_textureLayer.reset();
qCDebug(DIGIKAM_MARBLE_LOG) << "Cleared Volatile Cache!";
}
void MarbleMap::setVolatileTileCacheLimit(quint64 kilobytes)
{
qCDebug(DIGIKAM_MARBLE_LOG) << "kiloBytes" << kilobytes;
d->m_textureLayer.setVolatileCacheLimit(kilobytes);
}
AngleUnit MarbleMap::defaultAngleUnit() const
{
if (GeoDataCoordinates::defaultNotation() == GeoDataCoordinates::Decimal)
{
return DecimalDegree;
}
else if (GeoDataCoordinates::defaultNotation() == GeoDataCoordinates::UTM)
{
return UTM;
}
return DMSDegree;
}
void MarbleMap::setDefaultAngleUnit(AngleUnit angleUnit)
{
if (angleUnit == DecimalDegree)
{
GeoDataCoordinates::setDefaultNotation(GeoDataCoordinates::Decimal);
return;
}
else if (angleUnit == UTM)
{
GeoDataCoordinates::setDefaultNotation(GeoDataCoordinates::UTM);
return;
}
GeoDataCoordinates::setDefaultNotation(GeoDataCoordinates::DMS);
}
QFont MarbleMap::defaultFont() const
{
return d->m_styleBuilder.defaultFont();
}
void MarbleMap::setDefaultFont(const QFont& font)
{
d->m_styleBuilder.setDefaultFont(font);
d->m_placemarkLayer.requestStyleReset();
}
QList<RenderPlugin*> MarbleMap::renderPlugins() const
{
return d->m_renderPlugins;
}
QList<AbstractFloatItem*> MarbleMap::floatItems() const
{
return d->m_floatItemsLayer.floatItems();
}
AbstractFloatItem* MarbleMap::floatItem(const QString& nameId) const
{
for (AbstractFloatItem* floatItem : floatItems())
{
if (floatItem && floatItem->nameId() == nameId)
{
return floatItem;
}
}
return nullptr; // No item found
}
QList<AbstractDataPlugin*> MarbleMap::dataPlugins() const
{
return d->m_layerManager.dataPlugins();
}
QList<AbstractDataPluginItem*> MarbleMap::whichItemAt(const QPoint& curpos) const
{
return d->m_layerManager.whichItemAt(curpos);
}
void MarbleMap::addLayer(LayerInterface* layer)
{
d->m_layerManager.addLayer(layer);
}
void MarbleMap::removeLayer(LayerInterface* layer)
{
d->m_layerManager.removeLayer(layer);
}
RenderStatus MarbleMap::renderStatus() const
{
return d->m_layerManager.renderState().status();
}
RenderState MarbleMap::renderState() const
{
return d->m_layerManager.renderState();
}
QString MarbleMap::addTextureLayer(GeoSceneTextureTileDataset* texture)
{
return textureLayer()->addTextureLayer(texture);
}
void MarbleMap::removeTextureLayer(const QString& key)
{
textureLayer()->removeTextureLayer(key);
}
// this method will only temporarily "pollute" the MarbleModel class
TextureLayer* MarbleMap::textureLayer() const
{
return &d->m_textureLayer;
}
VectorTileLayer* MarbleMap::vectorTileLayer() const
{
return &d->m_vectorTileLayer;
}
const StyleBuilder* MarbleMap::styleBuilder() const
{
return &d->m_styleBuilder;
}
qreal MarbleMap::heading() const
{
return d->m_viewport.heading() * RAD2DEG;
}
void MarbleMap::setHeading(qreal heading)
{
d->m_viewport.setHeading(heading * DEG2RAD);
d->m_textureLayer.setNeedsUpdate();
Q_EMIT visibleLatLonAltBoxChanged(d->m_viewport.viewLatLonAltBox());
}
} // namespace Marble
#include "moc_MarbleMap.cpp"
|