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 "GeoDataStyleMap.h"
27 #include "GeoDataNetworkLinkControl.h"
28 #include "GeoDataSchema.h"
29 
30 #include "MarbleDebug.h"
31 
32 #include <QDataStream>
33 
34 namespace Marble
35 {
36 
37 GeoDataDocument::GeoDataDocument()
38  : GeoDataContainer( new GeoDataDocumentPrivate )
39 {
40 }
41 
42 GeoDataDocument::GeoDataDocument( const GeoDataDocument& other )
43  : GeoDocument(),
44  GeoDataContainer(other, new GeoDataDocumentPrivate(*other.d_func()))
45 {
46 }
47 
48 GeoDataDocument::~GeoDataDocument()
49 {
50 }
51 
52 GeoDataDocument& GeoDataDocument::operator=(const GeoDataDocument& other)
53 {
54  if (this != &other) {
55  Q_D(GeoDataDocument);
56  *d = *other.d_func();
57  }
58 
59  return *this;
60 }
61 
62 bool GeoDataDocument::operator==( const GeoDataDocument &other ) const
63 {
64  if (!GeoDataContainer::equals(other)) {
65  return false;
66  }
67 
68  Q_D(const GeoDataDocument);
69  const GeoDataDocumentPrivate* const other_d = other.d_func();
70  if (!(d->m_styleHash.size() == other_d->m_styleHash.size() &&
71  d->m_styleMapHash == other_d->m_styleMapHash &&
72  d->m_schemaHash == other_d->m_schemaHash &&
73  d->m_filename == other_d->m_filename &&
74  d->m_baseUri == other_d->m_baseUri &&
75  d->m_networkLinkControl == other_d->m_networkLinkControl &&
76  d->m_property == other_d->m_property &&
77  d->m_documentRole == other_d->m_documentRole)) {
78  return false;
79  }
80 
81  auto iter = d->m_styleHash.constBegin();
82  auto const end = d->m_styleHash.constEnd();
83  for (; iter != end; ++iter) {
84  if (!other_d->m_styleHash.contains(iter.key())) {
85  return false;
86  }
87 
88  if (*iter.value() != *other_d->m_styleHash[iter.key()]) {
89  return false;
90  }
91  }
92 
93  return true;
94 }
95 
96 bool GeoDataDocument::operator!=( const GeoDataDocument &other ) const
97 {
98  return !this->operator==( other );
99 }
100 
101 const char* GeoDataDocument::nodeType() const
102 {
103  return GeoDataTypes::GeoDataDocumentType;
104 }
105 
106 
108 {
109  return new GeoDataDocument(*this);
110 }
111 
112 DocumentRole GeoDataDocument::documentRole() const
113 {
114  Q_D(const GeoDataDocument);
115  return d->m_documentRole;
116 }
117 
118 void GeoDataDocument::setDocumentRole( DocumentRole role )
119 {
120  Q_D(GeoDataDocument);
121  d->m_documentRole = role;
122 }
123 
124 QString GeoDataDocument::property() const
125 {
126  Q_D(const GeoDataDocument);
127  return d->m_property;
128 }
129 
130 void GeoDataDocument::setProperty( const QString& property )
131 {
132  Q_D(GeoDataDocument);
133  d->m_property = property;
134 }
135 
137 {
138  Q_D(const GeoDataDocument);
139  return d->m_filename;
140 }
141 
143 {
144  Q_D(GeoDataDocument);
145  d->m_filename = value;
146 }
147 
149 {
150  Q_D(const GeoDataDocument);
151  return d->m_baseUri;
152 }
153 
154 void GeoDataDocument::setBaseUri( const QString &baseUrl )
155 {
156  Q_D(GeoDataDocument);
157  d->m_baseUri = baseUrl;
158 }
159 
160 GeoDataNetworkLinkControl GeoDataDocument::networkLinkControl() const
161 {
162  Q_D(const GeoDataDocument);
163  return d->m_networkLinkControl;
164 }
165 
166 void GeoDataDocument::setNetworkLinkControl( const GeoDataNetworkLinkControl &networkLinkControl )
167 {
168  Q_D(GeoDataDocument);
169  d->m_networkLinkControl = networkLinkControl;
170 }
171 
173 {
174  Q_D(GeoDataDocument);
175  d->m_styleHash.insert(style->id(), style);
176  d->m_styleHash[style->id()]->setParent(this);
177 }
178 
179 void GeoDataDocument::removeStyle( const QString& styleId )
180 {
181  Q_D(GeoDataDocument);
182  d->m_styleHash.remove(styleId);
183 }
184 
186 {
187  /*
188  * FIXME: m_styleHash always should contain at least default
189  * GeoDataStyle element
190  */
191  Q_D(GeoDataDocument);
192  return d->m_styleHash[styleId];
193 }
194 
196 {
197  Q_D(const GeoDataDocument);
198  return d->m_styleHash.value(styleId);
199 }
200 
202 {
203  Q_D(const GeoDataDocument);
205  for(auto const & style: d->m_styleHash.values()) {
206  result << style;
207  }
208 
209  return result;
210 }
211 
213 {
214  Q_D(GeoDataDocument);
215  return d->m_styleHash.values();
216 }
217 
219 {
220  Q_D(GeoDataDocument);
221  d->m_styleMapHash.insert(map.id(), map);
222  d->m_styleMapHash[map.id()].setParent(this);
223 }
224 
226 {
227  Q_D(GeoDataDocument);
228  d->m_styleMapHash.remove(mapId);
229 }
230 
232 {
233  Q_D(GeoDataDocument);
234  return d->m_styleMapHash[styleId];
235 }
236 
237 GeoDataStyleMap GeoDataDocument::styleMap( const QString &styleId ) const
238 {
239  Q_D(const GeoDataDocument);
240  return d->m_styleMapHash.value(styleId);
241 }
242 
244 {
245  Q_D(const GeoDataDocument);
246  return d->m_styleMapHash.values();
247 }
248 
249 void GeoDataDocument::addSchema( const GeoDataSchema& schema )
250 {
251  Q_D(GeoDataDocument);
252  d->m_schemaHash.insert(schema.id(), schema);
253  d->m_schemaHash[schema.id()].setParent(this);
254 }
255 
256 void GeoDataDocument::removeSchema( const QString& schemaId )
257 {
258  Q_D(GeoDataDocument);
259  GeoDataSchema schema = d->m_schemaHash.take(schemaId);
260  schema.setParent( nullptr );
261 }
262 
263 GeoDataSchema GeoDataDocument::schema( const QString& schemaId ) const
264 {
265  Q_D(const GeoDataDocument);
266  return d->m_schemaHash.value(schemaId);
267 }
268 
269 GeoDataSchema &GeoDataDocument::schema( const QString &schemaId )
270 {
271  Q_D(GeoDataDocument);
272  return d->m_schemaHash[schemaId];
273 }
274 
276 {
277  Q_D(const GeoDataDocument);
278  return d->m_schemaHash.values();
279 }
280 
281 void GeoDataDocument::pack( QDataStream& stream ) const
282 {
283  Q_D(const GeoDataDocument);
284  GeoDataContainer::pack( stream );
285 
286  stream << d->m_styleHash.size();
287 
289  = d->m_styleHash.constBegin();
290  iterator != d->m_styleHash.constEnd();
291  ++iterator ) {
292  iterator.value()->pack( stream );
293  }
294 }
295 
296 
297 void GeoDataDocument::unpack( QDataStream& stream )
298 {
299  Q_D(GeoDataDocument);
300  GeoDataContainer::unpack( stream );
301 
302  int size = 0;
303 
304  stream >> size;
305  for( int i = 0; i < size; i++ ) {
306  GeoDataStyle::Ptr style;
307  style->unpack( stream );
308  d->m_styleHash.insert(style->id(), style);
309  }
310 }
311 
312 }
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 Sat Oct 24 2020 23:25:22 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.