Marble

GeoDataDocument.cpp
1 /*
2  Copyright (C) 2007 Murad Tagirov <[email protected]>
3  Copyright (C) 2007 Nikolas Zimmermann <[email protected]>
4 
5  This file is part of the KDE project
6 
7  This library is free software you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  aint with this library see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "GeoDataDocument.h"
24 #include "GeoDataDocument_p.h"
25 
26 #include "GeoDataStyle.h"
27 #include "GeoDataStyleMap.h"
28 #include "GeoDataNetworkLinkControl.h"
29 #include "GeoDataSchema.h"
30 
31 #include "MarbleDebug.h"
32 
33 #include <QDataStream>
34 
35 namespace Marble
36 {
37 
38 GeoDataDocument::GeoDataDocument()
39  : GeoDataContainer( new GeoDataDocumentPrivate )
40 {
41 }
42 
43 GeoDataDocument::GeoDataDocument( const GeoDataDocument& other )
44  : GeoDocument(),
45  GeoDataContainer(other, new GeoDataDocumentPrivate(*other.d_func()))
46 {
47 }
48 
49 GeoDataDocument::~GeoDataDocument()
50 {
51 }
52 
53 GeoDataDocument& GeoDataDocument::operator=(const GeoDataDocument& other)
54 {
55  if (this != &other) {
56  Q_D(GeoDataDocument);
57  *d = *other.d_func();
58  }
59 
60  return *this;
61 }
62 
63 bool GeoDataDocument::operator==( const GeoDataDocument &other ) const
64 {
65  if (!GeoDataContainer::equals(other)) {
66  return false;
67  }
68 
69  Q_D(const GeoDataDocument);
70  const GeoDataDocumentPrivate* const other_d = other.d_func();
71  if (!(d->m_styleHash.size() == other_d->m_styleHash.size() &&
72  d->m_styleMapHash == other_d->m_styleMapHash &&
73  d->m_schemaHash == other_d->m_schemaHash &&
74  d->m_filename == other_d->m_filename &&
75  d->m_baseUri == other_d->m_baseUri &&
76  d->m_networkLinkControl == other_d->m_networkLinkControl &&
77  d->m_property == other_d->m_property &&
78  d->m_documentRole == other_d->m_documentRole)) {
79  return false;
80  }
81 
82  auto iter = d->m_styleHash.constBegin();
83  auto const end = d->m_styleHash.constEnd();
84  for (; iter != end; ++iter) {
85  if (!other_d->m_styleHash.contains(iter.key())) {
86  return false;
87  }
88 
89  if (*iter.value() != *other_d->m_styleHash[iter.key()]) {
90  return false;
91  }
92  }
93 
94  return true;
95 }
96 
97 bool GeoDataDocument::operator!=( const GeoDataDocument &other ) const
98 {
99  return !this->operator==( other );
100 }
101 
102 const char* GeoDataDocument::nodeType() const
103 {
104  return GeoDataTypes::GeoDataDocumentType;
105 }
106 
107 
109 {
110  return new GeoDataDocument(*this);
111 }
112 
113 DocumentRole GeoDataDocument::documentRole() const
114 {
115  Q_D(const GeoDataDocument);
116  return d->m_documentRole;
117 }
118 
119 void GeoDataDocument::setDocumentRole( DocumentRole role )
120 {
121  Q_D(GeoDataDocument);
122  d->m_documentRole = role;
123 }
124 
125 QString GeoDataDocument::property() const
126 {
127  Q_D(const GeoDataDocument);
128  return d->m_property;
129 }
130 
131 void GeoDataDocument::setProperty( const QString& property )
132 {
133  Q_D(GeoDataDocument);
134  d->m_property = property;
135 }
136 
138 {
139  Q_D(const GeoDataDocument);
140  return d->m_filename;
141 }
142 
144 {
145  Q_D(GeoDataDocument);
146  d->m_filename = value;
147 }
148 
150 {
151  Q_D(const GeoDataDocument);
152  return d->m_baseUri;
153 }
154 
155 void GeoDataDocument::setBaseUri( const QString &baseUrl )
156 {
157  Q_D(GeoDataDocument);
158  d->m_baseUri = baseUrl;
159 }
160 
161 GeoDataNetworkLinkControl GeoDataDocument::networkLinkControl() const
162 {
163  Q_D(const GeoDataDocument);
164  return d->m_networkLinkControl;
165 }
166 
167 void GeoDataDocument::setNetworkLinkControl( const GeoDataNetworkLinkControl &networkLinkControl )
168 {
169  Q_D(GeoDataDocument);
170  d->m_networkLinkControl = networkLinkControl;
171 }
172 
174 {
175  Q_D(GeoDataDocument);
176  d->m_styleHash.insert(style->id(), style);
177  d->m_styleHash[style->id()]->setParent(this);
178 }
179 
180 void GeoDataDocument::removeStyle( const QString& styleId )
181 {
182  Q_D(GeoDataDocument);
183  d->m_styleHash.remove(styleId);
184 }
185 
187 {
188  /*
189  * FIXME: m_styleHash always should contain at least default
190  * GeoDataStyle element
191  */
192  Q_D(GeoDataDocument);
193  return d->m_styleHash[styleId];
194 }
195 
197 {
198  Q_D(const GeoDataDocument);
199  return d->m_styleHash.value(styleId);
200 }
201 
203 {
204  Q_D(const GeoDataDocument);
206  for(auto const & style: d->m_styleHash.values()) {
207  result << style;
208  }
209 
210  return result;
211 }
212 
214 {
215  Q_D(GeoDataDocument);
216  return d->m_styleHash.values();
217 }
218 
220 {
221  Q_D(GeoDataDocument);
222  d->m_styleMapHash.insert(map.id(), map);
223  d->m_styleMapHash[map.id()].setParent(this);
224 }
225 
227 {
228  Q_D(GeoDataDocument);
229  d->m_styleMapHash.remove(mapId);
230 }
231 
233 {
234  Q_D(GeoDataDocument);
235  return d->m_styleMapHash[styleId];
236 }
237 
238 GeoDataStyleMap GeoDataDocument::styleMap( const QString &styleId ) const
239 {
240  Q_D(const GeoDataDocument);
241  return d->m_styleMapHash.value(styleId);
242 }
243 
245 {
246  Q_D(const GeoDataDocument);
247  return d->m_styleMapHash.values();
248 }
249 
250 void GeoDataDocument::addSchema( const GeoDataSchema& schema )
251 {
252  Q_D(GeoDataDocument);
253  d->m_schemaHash.insert(schema.id(), schema);
254  d->m_schemaHash[schema.id()].setParent(this);
255 }
256 
257 void GeoDataDocument::removeSchema( const QString& schemaId )
258 {
259  Q_D(GeoDataDocument);
260  GeoDataSchema schema = d->m_schemaHash.take(schemaId);
261  schema.setParent( nullptr );
262 }
263 
264 GeoDataSchema GeoDataDocument::schema( const QString& schemaId ) const
265 {
266  Q_D(const GeoDataDocument);
267  return d->m_schemaHash.value(schemaId);
268 }
269 
270 GeoDataSchema &GeoDataDocument::schema( const QString &schemaId )
271 {
272  Q_D(GeoDataDocument);
273  return d->m_schemaHash[schemaId];
274 }
275 
277 {
278  Q_D(const GeoDataDocument);
279  return d->m_schemaHash.values();
280 }
281 
282 void GeoDataDocument::pack( QDataStream& stream ) const
283 {
284  Q_D(const GeoDataDocument);
285  GeoDataContainer::pack( stream );
286 
287  stream << d->m_styleHash.size();
288 
290  = d->m_styleHash.constBegin();
291  iterator != d->m_styleHash.constEnd();
292  ++iterator ) {
293  iterator.value()->pack( stream );
294  }
295 }
296 
297 
298 void GeoDataDocument::unpack( QDataStream& stream )
299 {
300  Q_D(GeoDataDocument);
301  GeoDataContainer::unpack( stream );
302 
303  int size = 0;
304 
305  stream >> size;
306  for( int i = 0; i < size; i++ ) {
307  GeoDataStyle::Ptr style;
308  style->unpack( stream );
309  d->m_styleHash.insert(style->id(), style);
310  }
311 }
312 
313 }
void pack(QDataStream &stream) const override
Serialize the container to a stream.
void removeSchema(const QString &schemaId)
remove a schema from schema storage
GeoDataFeature * clone() const override
Duplicate into another equal instance.
void addStyleMap(const GeoDataStyleMap &map)
Add a stylemap to the stylemap storage.
A container for Features, Styles and in the future Schemas.
void setNetworkLinkControl(const GeoDataNetworkLinkControl &networkLinkControl)
set the NetworkLinkControl of the file
void removeStyle(const QString &styleId)
Add a style to the style storage.
Binds a QML item to a specific geodetic location in screen coordinates.
QSharedPointer< const GeoDataStyle > style() const
Return the style assigned to the placemark, or a default style if none has been set.
a class to map different styles to one style
void removeStyleMap(const QString &mapId)
remove stylemap from storage
QString baseUri() const
The URI relative paths should be resolved against.
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.
QList< GeoDataStyle::Ptr > styles()
dump a Vector of all styles
void unpack(QDataStream &stream) override
Unserialize the container from a stream.
const QList< QKeySequence > & end()
QString id() const
Get the id of the object.
void setBaseUri(const QString &baseUri)
Change the URI for resolving relative paths.
void setFileName(const QString &value)
Set a new file name for this document.
QString fileName() const
The filename of the document.
GeoDataSchema schema(const QString &schemaId) const
Returns a schema with id = schemaId form schema storage.
A base class for all geodata features.
GeoDataNetworkLinkControl networkLinkControl() const
the NetworkLinkControl of the file
QList< GeoDataStyleMap > styleMaps() const
dump a Vector of all stylemaps
void addStyle(const GeoDataStyle::Ptr &style)
Add a style to the style storage.
void addSchema(const GeoDataSchema &schema)
Add a schema to simplemap storage.
QList< GeoDataSchema > schemas() const
dump a vector of all schemas
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun May 24 2020 22:38:23 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.