Marble

GeoDataDocument.cpp
1 /*
2  SPDX-FileCopyrightText: 2007 Murad Tagirov <[email protected]>
3  SPDX-FileCopyrightText: 2007 Nikolas Zimmermann <[email protected]>
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 
19 namespace Marble
20 {
21 
22 GeoDataDocument::GeoDataDocument()
23  : GeoDataContainer( new GeoDataDocumentPrivate )
24 {
25 }
26 
27 GeoDataDocument::GeoDataDocument( const GeoDataDocument& other )
28  : GeoDocument(),
29  GeoDataContainer(other, new GeoDataDocumentPrivate(*other.d_func()))
30 {
31 }
32 
33 GeoDataDocument::~GeoDataDocument()
34 {
35 }
36 
37 GeoDataDocument& 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 
47 bool 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 
81 bool GeoDataDocument::operator!=( const GeoDataDocument &other ) const
82 {
83  return !this->operator==( other );
84 }
85 
86 const char* GeoDataDocument::nodeType() const
87 {
88  return GeoDataTypes::GeoDataDocumentType;
89 }
90 
91 
93 {
94  return new GeoDataDocument(*this);
95 }
96 
97 DocumentRole GeoDataDocument::documentRole() const
98 {
99  Q_D(const GeoDataDocument);
100  return d->m_documentRole;
101 }
102 
103 void GeoDataDocument::setDocumentRole( DocumentRole role )
104 {
105  Q_D(GeoDataDocument);
106  d->m_documentRole = role;
107 }
108 
109 QString GeoDataDocument::property() const
110 {
111  Q_D(const GeoDataDocument);
112  return d->m_property;
113 }
114 
115 void GeoDataDocument::setProperty( const QString& property )
116 {
117  Q_D(GeoDataDocument);
118  d->m_property = property;
119 }
120 
122 {
123  Q_D(const GeoDataDocument);
124  return d->m_filename;
125 }
126 
128 {
130  d->m_filename = value;
131 }
132 
134 {
135  Q_D(const GeoDataDocument);
136  return d->m_baseUri;
137 }
138 
139 void GeoDataDocument::setBaseUri( const QString &baseUrl )
140 {
142  d->m_baseUri = baseUrl;
143 }
144 
145 GeoDataNetworkLinkControl GeoDataDocument::networkLinkControl() const
146 {
147  Q_D(const GeoDataDocument);
148  return d->m_networkLinkControl;
149 }
150 
151 void GeoDataDocument::setNetworkLinkControl( const GeoDataNetworkLinkControl &networkLinkControl )
152 {
154  d->m_networkLinkControl = networkLinkControl;
155 }
156 
158 {
160  d->m_styleHash.insert(style->id(), style);
161  d->m_styleHash[style->id()]->setParent(this);
162 }
163 
164 void GeoDataDocument::removeStyle( const QString& styleId )
165 {
167  d->m_styleHash.remove(styleId);
168 }
169 
171 {
172  /*
173  * FIXME: m_styleHash always should contain at least default
174  * GeoDataStyle element
175  */
177  return d->m_styleHash[styleId];
178 }
179 
181 {
182  Q_D(const GeoDataDocument);
183  return d->m_styleHash.value(styleId);
184 }
185 
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 
198 {
200  return d->m_styleHash.values();
201 }
202 
204 {
206  d->m_styleMapHash.insert(map.id(), map);
207  d->m_styleMapHash[map.id()].setParent(this);
208 }
209 
211 {
213  d->m_styleMapHash.remove(mapId);
214 }
215 
217 {
219  return d->m_styleMapHash[styleId];
220 }
221 
222 GeoDataStyleMap GeoDataDocument::styleMap( const QString &styleId ) const
223 {
224  Q_D(const GeoDataDocument);
225  return d->m_styleMapHash.value(styleId);
226 }
227 
229 {
230  Q_D(const GeoDataDocument);
231  return d->m_styleMapHash.values();
232 }
233 
234 void GeoDataDocument::addSchema( const GeoDataSchema& schema )
235 {
237  d->m_schemaHash.insert(schema.id(), schema);
238  d->m_schemaHash[schema.id()].setParent(this);
239 }
240 
241 void GeoDataDocument::removeSchema( const QString& schemaId )
242 {
244  GeoDataSchema schema = d->m_schemaHash.take(schemaId);
245  schema.setParent( nullptr );
246 }
247 
248 GeoDataSchema GeoDataDocument::schema( const QString& schemaId ) const
249 {
250  Q_D(const GeoDataDocument);
251  return d->m_schemaHash.value(schemaId);
252 }
253 
254 GeoDataSchema &GeoDataDocument::schema( const QString &schemaId )
255 {
257  return d->m_schemaHash[schemaId];
258 }
259 
261 {
262  Q_D(const GeoDataDocument);
263  return d->m_schemaHash.values();
264 }
265 
266 void 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 
282 void 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 }
void pack(QDataStream &stream) const override
Serialize the container to a stream.
QList< GeoDataSchema > schemas() const
dump a vector of all schemas
void removeStyleMap(const QString &mapId)
remove stylemap from storage
const GeoDataStyleMap * styleMap() const
Return a pointer to a GeoDataStyleMap object which represents the styleMap of this feature.
const char * nodeType() const override
Provides type information for downcasting a GeoNode.
void addStyleMap(const GeoDataStyleMap &map)
Add a stylemap to the stylemap storage.
void removeSchema(const QString &schemaId)
remove a schema from schema storage
GeoDataFeature * clone() const override
Duplicate into another equal instance.
void removeStyle(const QString &styleId)
Add a style to the style storage.
QString baseUri() const
The URI relative paths should be resolved against.
void addSchema(const GeoDataSchema &schema)
Add a schema to simplemap storage.
A base class for all geodata features.
void setFileName(const QString &value)
Set a new file name for this document.
A container for Features, Styles and in the future Schemas.
a class to map different styles to one style
Binds a QML item to a specific geodetic location in screen coordinates.
void unpack(QDataStream &stream) override
Unserialize the container from a stream.
void setBaseUri(const QString &baseUri)
Change the URI for resolving relative paths.
QList< GeoDataStyle::Ptr > styles()
dump a Vector of all styles
const QString role() const
Return the role of the placemark.
int size() const
size of the container
GeoDataSchema schema(const QString &schemaId) const
Returns a schema with id = schemaId form schema storage.
QString fileName() const
The filename of the document.
QList< GeoDataStyleMap > styleMaps() const
dump a Vector of all stylemaps
Q_D(Todo)
GeoDataNetworkLinkControl networkLinkControl() const
the NetworkLinkControl of the file
QSharedPointer< const GeoDataStyle > style() const
Return the style assigned to the placemark, or a default style if none has been set.
void setNetworkLinkControl(const GeoDataNetworkLinkControl &networkLinkControl)
set the NetworkLinkControl of the file
void addStyle(const GeoDataStyle::Ptr &style)
Add a style to the style storage.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 03:59:07 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.