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 "GeoDataStyleMap.h"
12#include "GeoDataNetworkLinkControl.h"
13#include "GeoDataSchema.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()
34{
35}
36
37GeoDataDocument& GeoDataDocument::operator=(const GeoDataDocument& other)
38{
39 if (this != &other) {
40 Q_D(GeoDataDocument);
41 *d = *other.d_func();
42 }
43
44 return *this;
45}
46
47bool GeoDataDocument::operator==( const GeoDataDocument &other ) const
48{
49 if (!GeoDataContainer::equals(other)) {
50 return false;
51 }
52
53 Q_D(const GeoDataDocument);
54 const GeoDataDocumentPrivate* const other_d = other.d_func();
55 if (!(d->m_styleHash.size() == other_d->m_styleHash.size() &&
56 d->m_styleMapHash == other_d->m_styleMapHash &&
57 d->m_schemaHash == other_d->m_schemaHash &&
58 d->m_filename == other_d->m_filename &&
59 d->m_baseUri == other_d->m_baseUri &&
60 d->m_networkLinkControl == other_d->m_networkLinkControl &&
61 d->m_property == other_d->m_property &&
62 d->m_documentRole == other_d->m_documentRole)) {
63 return false;
64 }
65
66 auto iter = d->m_styleHash.constBegin();
67 auto const end = d->m_styleHash.constEnd();
68 for (; iter != end; ++iter) {
69 if (!other_d->m_styleHash.contains(iter.key())) {
70 return false;
71 }
72
73 if (*iter.value() != *other_d->m_styleHash[iter.key()]) {
74 return false;
75 }
76 }
77
78 return true;
79}
80
81bool GeoDataDocument::operator!=( const GeoDataDocument &other ) const
82{
83 return !this->operator==( other );
84}
85
86const char* GeoDataDocument::nodeType() const
87{
88 return GeoDataTypes::GeoDataDocumentType;
89}
90
91
92GeoDataFeature * GeoDataDocument::clone() const
93{
94 return new GeoDataDocument(*this);
95}
96
97DocumentRole GeoDataDocument::documentRole() const
98{
99 Q_D(const GeoDataDocument);
100 return d->m_documentRole;
101}
102
103void GeoDataDocument::setDocumentRole( DocumentRole role )
104{
105 Q_D(GeoDataDocument);
106 d->m_documentRole = role;
107}
108
109QString GeoDataDocument::property() const
110{
111 Q_D(const GeoDataDocument);
112 return d->m_property;
113}
114
115void GeoDataDocument::setProperty( const QString& property )
116{
117 Q_D(GeoDataDocument);
118 d->m_property = property;
119}
120
121QString GeoDataDocument::fileName() const
122{
123 Q_D(const GeoDataDocument);
124 return d->m_filename;
125}
126
127void GeoDataDocument::setFileName( const QString &value )
128{
130 d->m_filename = value;
131}
132
133QString GeoDataDocument::baseUri() const
134{
135 Q_D(const GeoDataDocument);
136 return d->m_baseUri;
137}
138
139void GeoDataDocument::setBaseUri( const QString &baseUrl )
140{
142 d->m_baseUri = baseUrl;
143}
144
145GeoDataNetworkLinkControl GeoDataDocument::networkLinkControl() const
146{
147 Q_D(const GeoDataDocument);
148 return d->m_networkLinkControl;
149}
150
151void GeoDataDocument::setNetworkLinkControl( const GeoDataNetworkLinkControl &networkLinkControl )
152{
154 d->m_networkLinkControl = networkLinkControl;
155}
156
157void GeoDataDocument::addStyle( const GeoDataStyle::Ptr &style )
158{
160 d->m_styleHash.insert(style->id(), style);
161 d->m_styleHash[style->id()]->setParent(this);
162}
163
164void GeoDataDocument::removeStyle( const QString& styleId )
165{
167 d->m_styleHash.remove(styleId);
168}
169
170GeoDataStyle::Ptr GeoDataDocument::style( const QString& styleId )
171{
172 /*
173 * FIXME: m_styleHash always should contain at least default
174 * GeoDataStyle element
175 */
177 return d->m_styleHash[styleId];
178}
179
180GeoDataStyle::ConstPtr GeoDataDocument::style( const QString &styleId ) const
181{
182 Q_D(const GeoDataDocument);
183 return d->m_styleHash.value(styleId);
184}
185
186QList<GeoDataStyle::ConstPtr> GeoDataDocument::styles() const
187{
188 Q_D(const GeoDataDocument);
190 for(auto const & style: d->m_styleHash.values()) {
191 result << style;
192 }
193
194 return result;
195}
196
197QList<GeoDataStyle::Ptr> GeoDataDocument::styles()
198{
200 return d->m_styleHash.values();
201}
202
203void GeoDataDocument::addStyleMap( const GeoDataStyleMap& map )
204{
206 d->m_styleMapHash.insert(map.id(), map);
207 d->m_styleMapHash[map.id()].setParent(this);
208}
209
210void GeoDataDocument::removeStyleMap( const QString& mapId )
211{
213 d->m_styleMapHash.remove(mapId);
214}
215
216GeoDataStyleMap& GeoDataDocument::styleMap( const QString& styleId )
217{
219 return d->m_styleMapHash[styleId];
220}
221
222GeoDataStyleMap GeoDataDocument::styleMap( const QString &styleId ) const
223{
224 Q_D(const GeoDataDocument);
225 return d->m_styleMapHash.value(styleId);
226}
227
228QList<GeoDataStyleMap> GeoDataDocument::styleMaps() const
229{
230 Q_D(const GeoDataDocument);
231 return d->m_styleMapHash.values();
232}
233
234void GeoDataDocument::addSchema( const GeoDataSchema& schema )
235{
237 d->m_schemaHash.insert(schema.id(), schema);
238 d->m_schemaHash[schema.id()].setParent(this);
239}
240
241void GeoDataDocument::removeSchema( const QString& schemaId )
242{
244 GeoDataSchema schema = d->m_schemaHash.take(schemaId);
245 schema.setParent( nullptr );
246}
247
248GeoDataSchema GeoDataDocument::schema( const QString& schemaId ) const
249{
250 Q_D(const GeoDataDocument);
251 return d->m_schemaHash.value(schemaId);
252}
253
254GeoDataSchema &GeoDataDocument::schema( const QString &schemaId )
255{
257 return d->m_schemaHash[schemaId];
258}
259
260QList<GeoDataSchema> GeoDataDocument::schemas() const
261{
262 Q_D(const GeoDataDocument);
263 return d->m_schemaHash.values();
264}
265
266void GeoDataDocument::pack( QDataStream& stream ) const
267{
268 Q_D(const GeoDataDocument);
269 GeoDataContainer::pack( stream );
270
271 stream << d->m_styleHash.size();
272
274 = d->m_styleHash.constBegin();
275 iterator != d->m_styleHash.constEnd();
276 ++iterator ) {
277 iterator.value()->pack( stream );
278 }
279}
280
281
282void GeoDataDocument::unpack( QDataStream& stream )
283{
284 Q_D(GeoDataDocument);
285 GeoDataContainer::unpack( stream );
286
287 int size = 0;
288
289 stream >> size;
290 for( int i = 0; i < size; i++ ) {
291 GeoDataStyle::Ptr style;
292 style->unpack( stream );
293 d->m_styleHash.insert(style->id(), style);
294 }
295}
296
297}
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
const QList< QKeySequence > & end()
Binds a QML item to a specific geodetic location in screen coordinates.
bool operator==(const QGraphicsApiFilter &reference, const QGraphicsApiFilter &sample)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:50:52 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.