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 "GeoSceneTypes.h"
10#include "GeoSceneLayer.h"
11#include "GeoSceneFilter.h"
12#include "DgmlAuxillaryDictionary.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{
25 public:
26 GeoSceneMapPrivate()
27 {
28 }
29
30 ~GeoSceneMapPrivate()
31 {
32 qDeleteAll( m_layers );
33 qDeleteAll( m_filters );
34 }
35
36 QVariantList m_center;
37
38 /// The vector holding all the sections in the legend.
39 /// (We want to preserve the order and don't care
40 /// much about speed here), so we don't use a hash
42
43 /// The vector holding all the filters in the map.
45
46 QColor m_backgroundColor;
47 QColor m_labelColor;
48
49 /// This color will be used to highlight
50 /// a region when it's clicked on.
51 QColor m_highlightBrushColor;
52 QColor m_highlightPenColor;
53};
54
55
56GeoSceneMap::GeoSceneMap()
57 : d ( new GeoSceneMapPrivate )
58{
59}
60
61GeoSceneMap::~GeoSceneMap()
62{
63 delete d;
64}
65
66const char* GeoSceneMap::nodeType() const
67{
68 return GeoSceneTypes::GeoSceneMapType;
69}
70
71void GeoSceneMap::addLayer( GeoSceneLayer* layer )
72{
73 // Remove any layer that has the same name
74 QVector<GeoSceneLayer*>::iterator it = d->m_layers.begin();
75 while (it != d->m_layers.end()) {
76 GeoSceneLayer* currentLayer = *it;
77 if ( currentLayer->name() == layer->name() ) {
78 delete currentLayer;
79 d->m_layers.erase(it);
80 break;
81 }
82 else {
83 ++it;
84 }
85 }
86
87 if ( layer ) {
88 d->m_layers.append( layer );
89 }
90}
91
92GeoSceneLayer* GeoSceneMap::layer( const QString& name )
93{
94 GeoSceneLayer* layer = nullptr;
95
96 QVector<GeoSceneLayer*>::const_iterator it = d->m_layers.constBegin();
97 QVector<GeoSceneLayer*>::const_iterator end = d->m_layers.constEnd();
98 for (; it != end; ++it) {
99 if ( (*it)->name() == name ) {
100 layer = *it;
101 break;
102 }
103 }
104
105 if ( !layer ) {
106 layer = new GeoSceneLayer( name );
107 addLayer( layer );
108 }
109
110 return layer;
111}
112
113const GeoSceneLayer* GeoSceneMap::layer( const QString& name ) const
114{
115 const GeoSceneLayer* layer = nullptr;
116
117 QVector<GeoSceneLayer*>::const_iterator it = d->m_layers.constBegin();
118 QVector<GeoSceneLayer*>::const_iterator end = d->m_layers.constEnd();
119 for (; it != end; ++it) {
120 if ( (*it)->name() == name ) {
121 layer = *it;
122 break;
123 }
124 }
125 return layer;
126}
127
128QVector<GeoSceneLayer*> GeoSceneMap::layers() const
129{
130 return d->m_layers;
131}
132
133void GeoSceneMap::addFilter( GeoSceneFilter* filter )
134{
135 // Remove any filter that has the same name
136 QVector<GeoSceneFilter*>::iterator it = d->m_filters.begin();
137 while (it != d->m_filters.end()) {
138 GeoSceneFilter* currentFilter = *it;
139 if ( currentFilter->name() == filter->name() ) {
140 delete currentFilter;
141 d->m_filters.erase(it);
142 break;
143 }
144 else {
145 ++it;
146 }
147 }
148
149 if ( filter ) {
150 d->m_filters.append( filter );
151 }
152}
153
154QVariantList GeoSceneMap::center() const
155{
156 return d->m_center;
157}
158
159void GeoSceneMap::setCenter(const QString & coordinatesString)
160{
161 QStringList coordinatesList = coordinatesString.split(",");
162 if (coordinatesList.count() == 2) {
163 bool success = false;
164 const GeoDataCoordinates coordinates = GeoDataCoordinates::fromString(coordinatesString, success);
165
166 if ( success ) {
167 QVariantList lonLat;
168 lonLat << QVariant( coordinates.longitude(GeoDataCoordinates::Degree) )
169 << QVariant( coordinates.latitude(GeoDataCoordinates::Degree) );
170 d->m_center = lonLat;
171 }
172 }
173 // LatLonBox
174 else if (coordinatesList.count() == 4) {
175 QVariantList northSouthEastWest;
176 d->m_center << QVariant(coordinatesList.at(0)) << QVariant(coordinatesList.at(1))
177 << QVariant(coordinatesList.at(2)) << QVariant(coordinatesList.at(3));
178 }
179}
180
181GeoSceneFilter* GeoSceneMap::filter( const QString& name )
182{
183 GeoSceneFilter* filter = nullptr;
184
185 QVector<GeoSceneFilter*>::const_iterator it = d->m_filters.constBegin();
186 QVector<GeoSceneFilter*>::const_iterator end = d->m_filters.constEnd();
187 for (; it != end; ++it) {
188 if ( (*it)->name() == name ) {
189 filter = *it;
190 break;
191 }
192 }
193
194 if ( !filter ) {
195 filter = new GeoSceneFilter( name );
196 addFilter( filter );
197 }
198
199 return filter;
200}
201
202QVector<GeoSceneFilter*> GeoSceneMap::filters() const
203{
204 return d->m_filters;
205}
206
207bool GeoSceneMap::hasTextureLayers() const
208{
209 QVector<GeoSceneLayer*>::const_iterator it = d->m_layers.constBegin();
210 QVector<GeoSceneLayer*>::const_iterator end = d->m_layers.constEnd();
211 for (; it != end; ++it) {
212 if (((*it)->backend() == QLatin1String(dgml::dgmlValue_texture) ||
213 (*it)->backend() == QLatin1String(dgml::dgmlValue_vectortile)) && (*it)->datasets().count() > 0)
214 return true;
215 }
216
217 return false;
218}
219
220bool GeoSceneMap::hasVectorLayers() const
221{
222 QVector<GeoSceneLayer*>::const_iterator it = d->m_layers.constBegin();
223 QVector<GeoSceneLayer*>::const_iterator end = d->m_layers.constEnd();
224 for (; it != end; ++it) {
225 if (((*it)->backend() == QLatin1String(dgml::dgmlValue_vectortile) ||
226 (*it)->backend() == QLatin1String(dgml::dgmlValue_vector)) && (*it)->datasets().count() > 0)
227 return true;
228 }
229
230 return false;
231}
232
233QColor GeoSceneMap::backgroundColor() const
234{
235 return d->m_backgroundColor;
236}
237
238void GeoSceneMap::setBackgroundColor( const QColor& backgroundColor )
239{
240 d->m_backgroundColor = backgroundColor;
241}
242
243
244QColor GeoSceneMap::labelColor() const
245{
246 return d->m_labelColor;
247}
248
249void GeoSceneMap::setLabelColor( const QColor& backgroundColor )
250{
251 d->m_labelColor = backgroundColor;
252}
253
254QColor GeoSceneMap::highlightBrushColor() const
255{
256 return d->m_highlightBrushColor;
257}
258
259void GeoSceneMap::setHighlightBrushColor( const QColor & highlightBrushColor )
260{
261 d->m_highlightBrushColor = highlightBrushColor;
262}
263
264QColor GeoSceneMap::highlightPenColor() const
265{
266 return d->m_highlightPenColor;
267}
268
269void GeoSceneMap::setHighlightPenColor( const QColor &highlightPenColor )
270{
271 d->m_highlightPenColor = highlightPenColor;
272}
273
274}
A 3d point representation.
qreal longitude(GeoDataCoordinates::Unit unit) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
qreal latitude(GeoDataCoordinates::Unit unit) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
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 Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.