Marble

GeoDataDocument.cpp
1/*
2 SPDX-FileCopyrightText: 2007 Murad Tagirov <tmurad@gmail.com>
3 SPDX-FileCopyrightText: 2007 Nikolas Zimmermann <zimmermann@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "GeoDataDocument.h"
9#include "GeoDataDocument_p.h"
10
11#include "GeoDataNetworkLinkControl.h"
12#include "GeoDataSchema.h"
13#include "GeoDataStyleMap.h"
14
15#include "MarbleDebug.h"
16
17#include <QDataStream>
18
19namespace Marble
20{
21
22GeoDataDocument::GeoDataDocument()
23 : GeoDataContainer(new GeoDataDocumentPrivate)
24{
25}
26
27GeoDataDocument::GeoDataDocument(const GeoDataDocument &other)
28 : GeoDocument()
29 , GeoDataContainer(other, new GeoDataDocumentPrivate(*other.d_func()))
30{
31}
32
33GeoDataDocument::~GeoDataDocument() = default;
34
35GeoDataDocument &GeoDataDocument::operator=(const GeoDataDocument &other)
36{
37 if (this != &other) {
38 Q_D(GeoDataDocument);
39 *d = *other.d_func();
40 }
41
42 return *this;
43}
44
45bool GeoDataDocument::operator==(const GeoDataDocument &other) const
46{
47 if (!GeoDataContainer::equals(other)) {
48 return false;
49 }
50
51 Q_D(const GeoDataDocument);
52 const GeoDataDocumentPrivate *const other_d = other.d_func();
53 if (!(d->m_styleHash.size() == other_d->m_styleHash.size() && d->m_styleMapHash == other_d->m_styleMapHash && d->m_schemaHash == other_d->m_schemaHash
54 && d->m_filename == other_d->m_filename && d->m_baseUri == other_d->m_baseUri && d->m_networkLinkControl == other_d->m_networkLinkControl
55 && d->m_property == other_d->m_property && d->m_documentRole == other_d->m_documentRole)) {
56 return false;
57 }
58
59 auto iter = d->m_styleHash.constBegin();
60 auto const end = d->m_styleHash.constEnd();
61 for (; iter != end; ++iter) {
62 if (!other_d->m_styleHash.contains(iter.key())) {
63 return false;
64 }
65
66 if (*iter.value() != *other_d->m_styleHash[iter.key()]) {
67 return false;
68 }
69 }
70
71 return true;
72}
73
74bool GeoDataDocument::operator!=(const GeoDataDocument &other) const
75{
76 return !this->operator==(other);
77}
78
79const char *GeoDataDocument::nodeType() const
80{
81 return GeoDataTypes::GeoDataDocumentType;
82}
83
84GeoDataFeature *GeoDataDocument::clone() const
85{
86 return new GeoDataDocument(*this);
87}
88
89DocumentRole GeoDataDocument::documentRole() const
90{
91 Q_D(const GeoDataDocument);
92 return d->m_documentRole;
93}
94
95void GeoDataDocument::setDocumentRole(DocumentRole role)
96{
97 Q_D(GeoDataDocument);
98 d->m_documentRole = role;
99}
100
101QString GeoDataDocument::property() const
102{
103 Q_D(const GeoDataDocument);
104 return d->m_property;
105}
106
107void GeoDataDocument::setProperty(const QString &property)
108{
109 Q_D(GeoDataDocument);
110 d->m_property = property;
111}
112
113QString GeoDataDocument::fileName() const
114{
115 Q_D(const GeoDataDocument);
116 return d->m_filename;
117}
118
119void GeoDataDocument::setFileName(const QString &value)
120{
122 d->m_filename = value;
123}
124
125QString GeoDataDocument::baseUri() const
126{
127 Q_D(const GeoDataDocument);
128 return d->m_baseUri;
129}
130
131void GeoDataDocument::setBaseUri(const QString &baseUrl)
132{
134 d->m_baseUri = baseUrl;
135}
136
137GeoDataNetworkLinkControl GeoDataDocument::networkLinkControl() const
138{
139 Q_D(const GeoDataDocument);
140 return d->m_networkLinkControl;
141}
142
143void GeoDataDocument::setNetworkLinkControl(const GeoDataNetworkLinkControl &networkLinkControl)
144{
146 d->m_networkLinkControl = networkLinkControl;
147}
148
149void GeoDataDocument::addStyle(const GeoDataStyle::Ptr &style)
150{
152 d->m_styleHash.insert(style->id(), style);
153 d->m_styleHash[style->id()]->setParent(this);
154}
155
156void GeoDataDocument::removeStyle(const QString &styleId)
157{
159 d->m_styleHash.remove(styleId);
160}
161
162GeoDataStyle::Ptr GeoDataDocument::style(const QString &styleId)
163{
164 /*
165 * FIXME: m_styleHash always should contain at least default
166 * GeoDataStyle element
167 */
169 return d->m_styleHash[styleId];
170}
171
172GeoDataStyle::ConstPtr GeoDataDocument::style(const QString &styleId) const
173{
174 Q_D(const GeoDataDocument);
175 return d->m_styleHash.value(styleId);
176}
177
178QList<GeoDataStyle::ConstPtr> GeoDataDocument::styles() const
179{
180 Q_D(const GeoDataDocument);
182 for (auto const &style : d->m_styleHash.values()) {
183 result << style;
184 }
185
186 return result;
187}
188
189QList<GeoDataStyle::Ptr> GeoDataDocument::styles()
190{
192 return d->m_styleHash.values();
193}
194
195void GeoDataDocument::addStyleMap(const GeoDataStyleMap &map)
196{
198 d->m_styleMapHash.insert(map.id(), map);
199 d->m_styleMapHash[map.id()].setParent(this);
200}
201
202void GeoDataDocument::removeStyleMap(const QString &mapId)
203{
205 d->m_styleMapHash.remove(mapId);
206}
207
208GeoDataStyleMap &GeoDataDocument::styleMap(const QString &styleId)
209{
211 return d->m_styleMapHash[styleId];
212}
213
214GeoDataStyleMap GeoDataDocument::styleMap(const QString &styleId) const
215{
216 Q_D(const GeoDataDocument);
217 return d->m_styleMapHash.value(styleId);
218}
219
220QList<GeoDataStyleMap> GeoDataDocument::styleMaps() const
221{
222 Q_D(const GeoDataDocument);
223 return d->m_styleMapHash.values();
224}
225
226void GeoDataDocument::addSchema(const GeoDataSchema &schema)
227{
229 d->m_schemaHash.insert(schema.id(), schema);
230 d->m_schemaHash[schema.id()].setParent(this);
231}
232
233void GeoDataDocument::removeSchema(const QString &schemaId)
234{
236 GeoDataSchema schema = d->m_schemaHash.take(schemaId);
237 schema.setParent(nullptr);
238}
239
240GeoDataSchema GeoDataDocument::schema(const QString &schemaId) const
241{
242 Q_D(const GeoDataDocument);
243 return d->m_schemaHash.value(schemaId);
244}
245
246GeoDataSchema &GeoDataDocument::schema(const QString &schemaId)
247{
249 return d->m_schemaHash[schemaId];
250}
251
252QList<GeoDataSchema> GeoDataDocument::schemas() const
253{
254 Q_D(const GeoDataDocument);
255 return d->m_schemaHash.values();
256}
257
258void GeoDataDocument::pack(QDataStream &stream) const
259{
260 Q_D(const GeoDataDocument);
261 GeoDataContainer::pack(stream);
262
263 stream << d->m_styleHash.size();
264
265 for (QMap<QString, GeoDataStyle::Ptr>::const_iterator iterator = d->m_styleHash.constBegin(); iterator != d->m_styleHash.constEnd(); ++iterator) {
266 iterator.value()->pack(stream);
267 }
268}
269
270void GeoDataDocument::unpack(QDataStream &stream)
271{
272 Q_D(GeoDataDocument);
273 GeoDataContainer::unpack(stream);
274
275 int size = 0;
276
277 stream >> size;
278 for (int i = 0; i < size; i++) {
279 GeoDataStyle::Ptr style(new GeoDataStyle);
280 style->unpack(stream);
281 d->m_styleHash.insert(style->id(), style);
282 }
283}
284
285}
A container for Features, Styles and in the future Schemas.
A base class for all geodata features.
void setParent(GeoDataObject *parent)
Sets the parent of the object.
QString id() const
Get the id of the object.
a class to map different styles to one style
QAction * end(const QObject *recvr, const char *slot, QObject *parent)
KIOCORE_EXPORT bool operator==(const UDSEntry &entry, const UDSEntry &other)
Binds a QML item to a specific geodetic location in screen coordinates.
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.