Marble

GeoSceneLayer.cpp
1 /*
2  SPDX-FileCopyrightText: 2008 Torsten Rahn <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "GeoSceneLayer.h"
8 
9 #include "GeoSceneAbstractDataset.h"
10 #include "GeoSceneFilter.h"
11 #include "GeoSceneTypes.h"
12 
13 namespace Marble
14 {
15 
16 class GeoSceneLayerPrivate
17 {
18  public:
19  GeoSceneLayerPrivate(const QString &name);
20  ~GeoSceneLayerPrivate();
21 
22  /// The vector holding all the data in the layer.
23  /// (We want to preserve the order and don't care
24  /// much about speed here), so we don't use a hash
26 
27  GeoSceneFilter *m_filter;
28 
29  QString m_name;
30  QString m_backend;
31  QString m_role;
32 
33  bool m_tiled;
34 };
35 
36 GeoSceneLayerPrivate::GeoSceneLayerPrivate(const QString &name) :
37  m_filter(nullptr),
38  m_name(name),
39  m_backend(),
40  m_role(),
41  m_tiled(true)
42 {
43 }
44 
45 GeoSceneLayerPrivate::~GeoSceneLayerPrivate()
46 {
47  qDeleteAll(m_datasets);
48 }
49 
50 GeoSceneLayer::GeoSceneLayer(const QString &name) :
51  d(new GeoSceneLayerPrivate(name))
52 {
53 }
54 
55 GeoSceneLayer::~GeoSceneLayer()
56 {
57  delete d;
58 }
59 
60 const char* GeoSceneLayer::nodeType() const
61 {
62  return GeoSceneTypes::GeoSceneLayerType;
63 }
64 
66 {
67  // Remove any dataset that has the same name
69  while (it != d->m_datasets.end()) {
70  GeoSceneAbstractDataset * currentAbstractDataset = *it;
71  if ( currentAbstractDataset->name() == dataset->name() ) {
72  delete currentAbstractDataset;
73  d->m_datasets.erase(it);
74  break;
75  }
76  else {
77  ++it;
78  }
79  }
80 
81  if ( dataset ) {
82  d->m_datasets.append( dataset );
83  }
84 }
85 
86 const GeoSceneAbstractDataset* GeoSceneLayer::dataset( const QString& name ) const
87 {
88  GeoSceneAbstractDataset* dataset = nullptr;
89 
91  QVector<GeoSceneAbstractDataset*>::const_iterator end = d->m_datasets.constEnd();
92  for (; it != end; ++it) {
93  if ( (*it)->name() == name ) {
94  dataset = *it;
95  break;
96  }
97  }
98  return dataset;
99 }
100 
101 // implement non-const method by means of const method,
102 // for details, see "Effective C++" (third edition)
103 GeoSceneAbstractDataset* GeoSceneLayer::dataset( const QString& name )
104 {
105  return const_cast<GeoSceneAbstractDataset*>
106  ( static_cast<GeoSceneLayer const *>( this )->dataset( name ));
107 }
108 
109 const GeoSceneAbstractDataset * GeoSceneLayer::groundDataset() const
110 {
111  if (d->m_datasets.isEmpty())
112  return nullptr;
113 
114  return d->m_datasets.first();
115 }
116 
117 // implement non-const method by means of const method,
118 // for details, see "Effective C++" (third edition)
119 GeoSceneAbstractDataset * GeoSceneLayer::groundDataset()
120 {
121  return const_cast<GeoSceneAbstractDataset*>
122  ( static_cast<GeoSceneLayer const *>( this )->groundDataset() );
123 }
124 
125 QVector<GeoSceneAbstractDataset *> GeoSceneLayer::datasets() const
126 {
127  return d->m_datasets;
128 }
129 
130 QString GeoSceneLayer::name() const
131 {
132  return d->m_name;
133 }
134 
135 QString GeoSceneLayer::backend() const
136 {
137  return d->m_backend;
138 }
139 
140 void GeoSceneLayer::setBackend( const QString& backend )
141 {
142  d->m_backend = backend;
143 }
144 
146 {
147  return d->m_tiled;
148 }
149 
150 void GeoSceneLayer::setTiled( bool tiled )
151 {
152  d->m_tiled = tiled;
153 }
154 
155 QString GeoSceneLayer::role() const
156 {
157  return d->m_role;
158 }
159 
160 void GeoSceneLayer::setRole( const QString& role )
161 {
162  d->m_role = role;
163 }
164 
165 const GeoSceneFilter* GeoSceneLayer::filter() const
166 {
167  return d->m_filter;
168 }
169 
170 GeoSceneFilter* GeoSceneLayer::filter()
171 {
172  return d->m_filter;
173 }
174 
175 void GeoSceneLayer::addFilter( GeoSceneFilter * filter )
176 {
177  d->m_filter = filter;
178 }
179 
180 void GeoSceneLayer::removeFilter( GeoSceneFilter * filter )
181 {
182  if (filter == d->m_filter) {
183  d->m_filter = nullptr;
184  }
185 }
186 
187 }
bool isTiled() const
returns whether the data is organized in quad tiles.
void append(const T &value)
QVector::iterator begin()
Binds a QML item to a specific geodetic location in screen coordinates.
const char * nodeType() const override
Provides type information for downcasting a GeoNode.
void addDataset(GeoSceneAbstractDataset *)
Add a data set to the legend.
Contents used inside a layer.
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:28
QVector::const_iterator constBegin() const const
Filter of a GeoScene document.
QVector::iterator end()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Dec 6 2021 23:10:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.