Marble

GeoSceneMap.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Torsten Rahn <[email protected]>
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 namespace Marble
17 {
18 
19 // FIXME: Filters are a Dataset.
20 
21 class GeoSceneMapPrivate
22 {
23  public:
24  GeoSceneMapPrivate()
25  {
26  }
27 
28  ~GeoSceneMapPrivate()
29  {
30  qDeleteAll( m_layers );
31  qDeleteAll( m_filters );
32  }
33 
34  /// The vector holding all the sections in the legend.
35  /// (We want to preserve the order and don't care
36  /// much about speed here), so we don't use a hash
37  QVector<GeoSceneLayer*> m_layers;
38 
39  /// The vector holding all the filters in the map.
40  QVector<GeoSceneFilter*> m_filters;
41 
42  QColor m_backgroundColor;
43  QColor m_labelColor;
44 
45  /// This color will be used to highlight
46  /// a region when it's clicked on.
47  QColor m_highlightBrushColor;
48  QColor m_highlightPenColor;
49 };
50 
51 
52 GeoSceneMap::GeoSceneMap()
53  : d ( new GeoSceneMapPrivate )
54 {
55 }
56 
57 GeoSceneMap::~GeoSceneMap()
58 {
59  delete d;
60 }
61 
62 const char* GeoSceneMap::nodeType() const
63 {
64  return GeoSceneTypes::GeoSceneMapType;
65 }
66 
68 {
69  // Remove any layer that has the same name
70  QVector<GeoSceneLayer*>::iterator it = d->m_layers.begin();
71  while (it != d->m_layers.end()) {
72  GeoSceneLayer* currentLayer = *it;
73  if ( currentLayer->name() == layer->name() ) {
74  delete currentLayer;
75  d->m_layers.erase(it);
76  break;
77  }
78  else {
79  ++it;
80  }
81  }
82 
83  if ( layer ) {
84  d->m_layers.append( layer );
85  }
86 }
87 
89 {
90  GeoSceneLayer* layer = nullptr;
91 
92  QVector<GeoSceneLayer*>::const_iterator it = d->m_layers.constBegin();
93  QVector<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 
109 const GeoSceneLayer* GeoSceneMap::layer( const QString& name ) const
110 {
111  const GeoSceneLayer* layer = nullptr;
112 
113  QVector<GeoSceneLayer*>::const_iterator it = d->m_layers.constBegin();
114  QVector<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 
125 {
126  return d->m_layers;
127 }
128 
130 {
131  // Remove any filter that has the same name
132  QVector<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  }
140  else {
141  ++it;
142  }
143  }
144 
145  if ( filter ) {
146  d->m_filters.append( filter );
147  }
148 }
149 
151 {
152  GeoSceneFilter* filter = nullptr;
153 
154  QVector<GeoSceneFilter*>::const_iterator it = d->m_filters.constBegin();
155  QVector<GeoSceneFilter*>::const_iterator end = d->m_filters.constEnd();
156  for (; it != end; ++it) {
157  if ( (*it)->name() == name ) {
158  filter = *it;
159  break;
160  }
161  }
162 
163  if ( !filter ) {
164  filter = new GeoSceneFilter( name );
165  addFilter( filter );
166  }
167 
168  return filter;
169 }
170 
172 {
173  return d->m_filters;
174 }
175 
177 {
178  QVector<GeoSceneLayer*>::const_iterator it = d->m_layers.constBegin();
179  QVector<GeoSceneLayer*>::const_iterator end = d->m_layers.constEnd();
180  for (; it != end; ++it) {
181  if (((*it)->backend() == QLatin1String(dgml::dgmlValue_texture) ||
182  (*it)->backend() == QLatin1String(dgml::dgmlValue_vectortile)) && (*it)->datasets().count() > 0)
183  return true;
184  }
185 
186  return false;
187 }
188 
190 {
191  QVector<GeoSceneLayer*>::const_iterator it = d->m_layers.constBegin();
192  QVector<GeoSceneLayer*>::const_iterator end = d->m_layers.constEnd();
193  for (; it != end; ++it) {
194  if (((*it)->backend() == QLatin1String(dgml::dgmlValue_vector)) && (*it)->datasets().count() > 0)
195  return true;
196  }
197 
198  return false;
199 }
200 
201 QColor GeoSceneMap::backgroundColor() const
202 {
203  return d->m_backgroundColor;
204 }
205 
206 void GeoSceneMap::setBackgroundColor( const QColor& backgroundColor )
207 {
208  d->m_backgroundColor = backgroundColor;
209 }
210 
211 
212 QColor GeoSceneMap::labelColor() const
213 {
214  return d->m_labelColor;
215 }
216 
217 void GeoSceneMap::setLabelColor( const QColor& backgroundColor )
218 {
219  d->m_labelColor = backgroundColor;
220 }
221 
222 QColor GeoSceneMap::highlightBrushColor() const
223 {
224  return d->m_highlightBrushColor;
225 }
226 
227 void GeoSceneMap::setHighlightBrushColor( const QColor & highlightBrushColor )
228 {
229  d->m_highlightBrushColor = highlightBrushColor;
230 }
231 
232 QColor GeoSceneMap::highlightPenColor() const
233 {
234  return d->m_highlightPenColor;
235 }
236 
237 void GeoSceneMap::setHighlightPenColor( const QColor &highlightPenColor )
238 {
239  d->m_highlightPenColor = highlightPenColor;
240 }
241 
242 }
GeoSceneFilter * filter(const QString &name)
Return a filter by its name.
Binds a QML item to a specific geodetic location in screen coordinates.
GeoSceneLayer * layer(const QString &name)
Return a layer by its name.
Definition: GeoSceneMap.cpp:88
const QLatin1String name
QVector< GeoSceneFilter * > filters() const
Return all filters.
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:28
void addFilter(GeoSceneFilter *)
Add a new filter to the map.
void addLayer(GeoSceneLayer *)
Add a new layer to the map.
Definition: GeoSceneMap.cpp:67
Filter of a GeoScene document.
bool hasVectorLayers() const
Checks for valid layers that contain vector data.
const char * nodeType() const override
Provides type information for downcasting a GeoNode.
Definition: GeoSceneMap.cpp:62
QVector< GeoSceneLayer * > layers() const
Return all layers.
bool hasTextureLayers() const
Checks for valid layers that contain texture data.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Dec 5 2021 23:10:38 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.