Marble

GeoSceneLayer.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 "GeoSceneLayer.h"
8
9#include "GeoSceneAbstractDataset.h"
10#include "GeoSceneFilter.h"
11#include "GeoSceneTypes.h"
12
13namespace Marble
14{
15
16class 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
36GeoSceneLayerPrivate::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
45GeoSceneLayerPrivate::~GeoSceneLayerPrivate()
46{
47 qDeleteAll(m_datasets);
48}
49
50GeoSceneLayer::GeoSceneLayer(const QString &name) :
51 d(new GeoSceneLayerPrivate(name))
52{
53}
54
55GeoSceneLayer::~GeoSceneLayer()
56{
57 delete d;
58}
59
60const char* GeoSceneLayer::nodeType() const
61{
62 return GeoSceneTypes::GeoSceneLayerType;
63}
64
65void GeoSceneLayer::addDataset( GeoSceneAbstractDataset* dataset )
66{
67 // Remove any dataset that has the same name
68 QVector<GeoSceneAbstractDataset *>::iterator it = d->m_datasets.begin();
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
86const GeoSceneAbstractDataset* GeoSceneLayer::dataset( const QString& name ) const
87{
88 GeoSceneAbstractDataset* dataset = nullptr;
89
90 QVector<GeoSceneAbstractDataset*>::const_iterator it = d->m_datasets.constBegin();
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)
103GeoSceneAbstractDataset* GeoSceneLayer::dataset( const QString& name )
104{
105 return const_cast<GeoSceneAbstractDataset*>
106 ( static_cast<GeoSceneLayer const *>( this )->dataset( name ));
107}
108
109const 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)
119GeoSceneAbstractDataset * GeoSceneLayer::groundDataset()
120{
121 return const_cast<GeoSceneAbstractDataset*>
122 ( static_cast<GeoSceneLayer const *>( this )->groundDataset() );
123}
124
125QVector<GeoSceneAbstractDataset *> GeoSceneLayer::datasets() const
126{
127 return d->m_datasets;
128}
129
130QString GeoSceneLayer::name() const
131{
132 return d->m_name;
133}
134
135QString GeoSceneLayer::backend() const
136{
137 return d->m_backend;
138}
139
140void GeoSceneLayer::setBackend( const QString& backend )
141{
142 d->m_backend = backend;
143}
144
145bool GeoSceneLayer::isTiled() const
146{
147 return d->m_tiled;
148}
149
150void GeoSceneLayer::setTiled( bool tiled )
151{
152 d->m_tiled = tiled;
153}
154
155QString GeoSceneLayer::role() const
156{
157 return d->m_role;
158}
159
160void GeoSceneLayer::setRole( const QString& role )
161{
162 d->m_role = role;
163}
164
165const GeoSceneFilter* GeoSceneLayer::filter() const
166{
167 return d->m_filter;
168}
169
170GeoSceneFilter* GeoSceneLayer::filter()
171{
172 return d->m_filter;
173}
174
175void GeoSceneLayer::addFilter( GeoSceneFilter * filter )
176{
177 d->m_filter = filter;
178}
179
180void GeoSceneLayer::removeFilter( GeoSceneFilter * filter )
181{
182 if (filter == d->m_filter) {
183 d->m_filter = nullptr;
184 }
185}
186
187}
Contents used inside a layer.
QString name(StandardAction id)
Binds a QML item to a specific geodetic location in screen coordinates.
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.