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{
18public:
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 = nullptr;
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 QList<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 } else {
76 ++it;
77 }
78 }
79
80 if (dataset) {
81 d->m_datasets.append(dataset);
82 }
83}
84
85const GeoSceneAbstractDataset *GeoSceneLayer::dataset(const QString &name) const
86{
87 GeoSceneAbstractDataset *dataset = nullptr;
88
89 QList<GeoSceneAbstractDataset *>::const_iterator it = d->m_datasets.constBegin();
90 QList<GeoSceneAbstractDataset *>::const_iterator end = d->m_datasets.constEnd();
91 for (; it != end; ++it) {
92 if ((*it)->name() == name) {
93 dataset = *it;
94 break;
95 }
96 }
97 return dataset;
98}
99
100// implement non-const method by means of const method,
101// for details, see "Effective C++" (third edition)
102GeoSceneAbstractDataset *GeoSceneLayer::dataset(const QString &name)
103{
104 return const_cast<GeoSceneAbstractDataset *>(static_cast<GeoSceneLayer const *>(this)->dataset(name));
105}
106
107const GeoSceneAbstractDataset *GeoSceneLayer::groundDataset() const
108{
109 if (d->m_datasets.isEmpty())
110 return nullptr;
111
112 return d->m_datasets.first();
113}
114
115// implement non-const method by means of const method,
116// for details, see "Effective C++" (third edition)
117GeoSceneAbstractDataset *GeoSceneLayer::groundDataset()
118{
119 return const_cast<GeoSceneAbstractDataset *>(static_cast<GeoSceneLayer const *>(this)->groundDataset());
120}
121
122QList<GeoSceneAbstractDataset *> GeoSceneLayer::datasets() const
123{
124 return d->m_datasets;
125}
126
127QString GeoSceneLayer::name() const
128{
129 return d->m_name;
130}
131
132QString GeoSceneLayer::backend() const
133{
134 return d->m_backend;
135}
136
137void GeoSceneLayer::setBackend(const QString &backend)
138{
139 d->m_backend = backend;
140}
141
142bool GeoSceneLayer::isTiled() const
143{
144 return d->m_tiled;
145}
146
147void GeoSceneLayer::setTiled(bool tiled)
148{
149 d->m_tiled = tiled;
150}
151
152QString GeoSceneLayer::role() const
153{
154 return d->m_role;
155}
156
157void GeoSceneLayer::setRole(const QString &role)
158{
159 d->m_role = role;
160}
161
162const GeoSceneFilter *GeoSceneLayer::filter() const
163{
164 return d->m_filter;
165}
166
167GeoSceneFilter *GeoSceneLayer::filter()
168{
169 return d->m_filter;
170}
171
172void GeoSceneLayer::addFilter(GeoSceneFilter *filter)
173{
174 d->m_filter = filter;
175}
176
177void GeoSceneLayer::removeFilter(GeoSceneFilter *filter)
178{
179 if (filter == d->m_filter) {
180 d->m_filter = nullptr;
181 }
182}
183
184}
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 Mon Nov 18 2024 12:15:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.