Marble

GeoSceneMap.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Torsten Rahn <rahn@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "GeoSceneMap.h"
8
9#include "DgmlAuxillaryDictionary.h"
10#include "GeoSceneFilter.h"
11#include "GeoSceneLayer.h"
12#include "GeoSceneTypes.h"
13
14#include <QColor>
15
16#include <GeoDataCoordinates.h>
17
18namespace Marble
19{
20
21// FIXME: Filters are a Dataset.
22
23class GeoSceneMapPrivate
24{
25public:
26 GeoSceneMapPrivate() = default;
27
28 ~GeoSceneMapPrivate()
29 {
30 qDeleteAll(m_layers);
31 qDeleteAll(m_filters);
32 }
33
34 QVariantList m_center;
35
36 /// The vector holding all the sections in the legend.
37 /// (We want to preserve the order and don't care
38 /// much about speed here), so we don't use a hash
40
41 /// The vector holding all the filters in the map.
43
44 QColor m_backgroundColor;
45 QColor m_labelColor;
46
47 /// This color will be used to highlight
48 /// a region when it's clicked on.
49 QColor m_highlightBrushColor;
50 QColor m_highlightPenColor;
51};
52
53GeoSceneMap::GeoSceneMap()
54 : d(new GeoSceneMapPrivate)
55{
56}
57
58GeoSceneMap::~GeoSceneMap()
59{
60 delete d;
61}
62
63const char *GeoSceneMap::nodeType() const
64{
65 return GeoSceneTypes::GeoSceneMapType;
66}
67
68void GeoSceneMap::addLayer(GeoSceneLayer *layer)
69{
70 // Remove any layer that has the same name
71 QList<GeoSceneLayer *>::iterator it = d->m_layers.begin();
72 while (it != d->m_layers.end()) {
73 GeoSceneLayer *currentLayer = *it;
74 if (currentLayer->name() == layer->name()) {
75 delete currentLayer;
76 d->m_layers.erase(it);
77 break;
78 } else {
79 ++it;
80 }
81 }
82
83 if (layer) {
84 d->m_layers.append(layer);
85 }
86}
87
88GeoSceneLayer *GeoSceneMap::layer(const QString &name)
89{
90 GeoSceneLayer *layer = nullptr;
91
92 QList<GeoSceneLayer *>::const_iterator it = d->m_layers.constBegin();
93 QList<GeoSceneLayer *>::const_iterator end = d->m_layers.constEnd();
94 for (; it != end; ++it) {
95 if ((*it)->name() == name) {
96 layer = *it;
97 break;
98 }
99 }
100
101 if (!layer) {
102 layer = new GeoSceneLayer(name);
103 addLayer(layer);
104 }
105
106 return layer;
107}
108
109const GeoSceneLayer *GeoSceneMap::layer(const QString &name) const
110{
111 const GeoSceneLayer *layer = nullptr;
112
113 QList<GeoSceneLayer *>::const_iterator it = d->m_layers.constBegin();
114 QList<GeoSceneLayer *>::const_iterator end = d->m_layers.constEnd();
115 for (; it != end; ++it) {
116 if ((*it)->name() == name) {
117 layer = *it;
118 break;
119 }
120 }
121 return layer;
122}
123
124QList<GeoSceneLayer *> GeoSceneMap::layers() const
125{
126 return d->m_layers;
127}
128
129void GeoSceneMap::addFilter(GeoSceneFilter *filter)
130{
131 // Remove any filter that has the same name
132 QList<GeoSceneFilter *>::iterator it = d->m_filters.begin();
133 while (it != d->m_filters.end()) {
134 GeoSceneFilter *currentFilter = *it;
135 if (currentFilter->name() == filter->name()) {
136 delete currentFilter;
137 d->m_filters.erase(it);
138 break;
139 } else {
140 ++it;
141 }
142 }
143
144 if (filter) {
145 d->m_filters.append(filter);
146 }
147}
148
149QVariantList GeoSceneMap::center() const
150{
151 return d->m_center;
152}
153
154void GeoSceneMap::setCenter(const QString &coordinatesString)
155{
156 QStringList coordinatesList = coordinatesString.split(QStringLiteral(","));
157 if (coordinatesList.count() == 2) {
158 bool success = false;
159 const GeoDataCoordinates coordinates = GeoDataCoordinates::fromString(coordinatesString, success);
160
161 if (success) {
162 QVariantList lonLat;
163 lonLat << QVariant(coordinates.longitude(GeoDataCoordinates::Degree)) << QVariant(coordinates.latitude(GeoDataCoordinates::Degree));
164 d->m_center = lonLat;
165 }
166 }
167 // LatLonBox
168 else if (coordinatesList.count() == 4) {
169 QVariantList northSouthEastWest;
170 d->m_center << QVariant(coordinatesList.at(0)) << QVariant(coordinatesList.at(1)) << QVariant(coordinatesList.at(2)) << QVariant(coordinatesList.at(3));
171 }
172}
173
174GeoSceneFilter *GeoSceneMap::filter(const QString &name)
175{
176 GeoSceneFilter *filter = nullptr;
177
178 QList<GeoSceneFilter *>::const_iterator it = d->m_filters.constBegin();
179 QList<GeoSceneFilter *>::const_iterator end = d->m_filters.constEnd();
180 for (; it != end; ++it) {
181 if ((*it)->name() == name) {
182 filter = *it;
183 break;
184 }
185 }
186
187 if (!filter) {
188 filter = new GeoSceneFilter(name);
189 addFilter(filter);
190 }
191
192 return filter;
193}
194
195QList<GeoSceneFilter *> GeoSceneMap::filters() const
196{
197 return d->m_filters;
198}
199
200bool GeoSceneMap::hasTextureLayers() const
201{
202 QList<GeoSceneLayer *>::const_iterator it = d->m_layers.constBegin();
203 QList<GeoSceneLayer *>::const_iterator end = d->m_layers.constEnd();
204 for (; it != end; ++it) {
205 if (((*it)->backend() == QLatin1StringView(dgml::dgmlValue_texture) || (*it)->backend() == QLatin1StringView(dgml::dgmlValue_vectortile))
206 && (*it)->datasets().count() > 0)
207 return true;
208 }
209
210 return false;
211}
212
213bool GeoSceneMap::hasVectorLayers() const
214{
215 QList<GeoSceneLayer *>::const_iterator it = d->m_layers.constBegin();
216 QList<GeoSceneLayer *>::const_iterator end = d->m_layers.constEnd();
217 for (; it != end; ++it) {
218 if (((*it)->backend() == QLatin1StringView(dgml::dgmlValue_vectortile) || (*it)->backend() == QLatin1StringView(dgml::dgmlValue_vector))
219 && (*it)->datasets().count() > 0)
220 return true;
221 }
222
223 return false;
224}
225
226QColor GeoSceneMap::backgroundColor() const
227{
228 return d->m_backgroundColor;
229}
230
231void GeoSceneMap::setBackgroundColor(const QColor &backgroundColor)
232{
233 d->m_backgroundColor = backgroundColor;
234}
235
236QColor GeoSceneMap::labelColor() const
237{
238 return d->m_labelColor;
239}
240
241void GeoSceneMap::setLabelColor(const QColor &backgroundColor)
242{
243 d->m_labelColor = backgroundColor;
244}
245
246QColor GeoSceneMap::highlightBrushColor() const
247{
248 return d->m_highlightBrushColor;
249}
250
251void GeoSceneMap::setHighlightBrushColor(const QColor &highlightBrushColor)
252{
253 d->m_highlightBrushColor = highlightBrushColor;
254}
255
256QColor GeoSceneMap::highlightPenColor() const
257{
258 return d->m_highlightPenColor;
259}
260
261void GeoSceneMap::setHighlightPenColor(const QColor &highlightPenColor)
262{
263 d->m_highlightPenColor = highlightPenColor;
264}
265
266}
A 3d point representation.
Filter of a GeoScene document.
Layer of a GeoScene document.
Binds a QML item to a specific geodetic location in screen coordinates.
const_reference at(qsizetype i) const const
qsizetype count() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.