Marble

OsmPlacemarkData.cpp
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2015 Marius-Valeriu Stanciu <[email protected]>
9 //
10 
11 // Self
12 #include "osm/OsmPlacemarkData.h"
13 
14 // Marble
15 #include "GeoDataExtendedData.h"
16 
17 #include <QXmlStreamAttributes>
18 
19 namespace Marble
20 {
21 
22 OsmPlacemarkData::OsmPlacemarkData():
23  m_id( 0 )
24 {
25  // nothing to do
26 }
27 
28 qint64 OsmPlacemarkData::id() const
29 {
30  return m_id;
31 }
32 
33 qint64 OsmPlacemarkData::oid() const
34 {
35  auto const value = m_tags.value(QStringLiteral("mx:oid")).toLong();
36  return value > 0 ? value : m_id;
37 }
38 
39 QString OsmPlacemarkData::changeset() const
40 {
41  return m_tags.value(QStringLiteral("mx:changeset"));
42 }
43 
44 QString OsmPlacemarkData::version() const
45 {
46  return m_tags.value(QStringLiteral("mx:version"));
47 }
48 
49 QString OsmPlacemarkData::uid() const
50 {
51  return m_tags.value(QStringLiteral("mx:uid"));
52 }
53 
54 QString OsmPlacemarkData::isVisible() const
55 {
56  return m_tags.value(QStringLiteral("mx:visible"));
57 }
58 
59 QString OsmPlacemarkData::user() const
60 {
61  return m_tags.value(QStringLiteral("mx:user"));
62 }
63 
64 QString OsmPlacemarkData::timestamp() const
65 {
66  return m_tags.value(QStringLiteral("mx:timestamp"));
67 }
68 
69 QString OsmPlacemarkData::action() const
70 {
71  return m_tags.value(QStringLiteral("mx:action"));
72 }
73 
74 void OsmPlacemarkData::setId( qint64 id )
75 {
76  m_id = id;
77 }
78 
79 void OsmPlacemarkData::setVersion( const QString& version )
80 {
81  m_tags[QStringLiteral("mx:version")] = version;
82 }
83 
84 void OsmPlacemarkData::setChangeset( const QString& changeset )
85 {
86  m_tags[QStringLiteral("mx:changeset")] = changeset;
87 }
88 
89 void OsmPlacemarkData::setUid( const QString& uid )
90 {
91  m_tags[QStringLiteral("mx:uid")] = uid;
92 }
93 
94 void OsmPlacemarkData::setVisible( const QString& visible )
95 {
96  m_tags[QStringLiteral("mx:visible")] = visible;
97 }
98 
99 void OsmPlacemarkData::setUser( const QString& user )
100 {
101  m_tags[QStringLiteral("mx:user")] = user;
102 }
103 
104 void OsmPlacemarkData::setTimestamp( const QString& timestamp )
105 {
106  m_tags[QStringLiteral("mx:timestamp")] = timestamp;
107 }
108 
109 void OsmPlacemarkData::setAction( const QString& action )
110 {
111  m_tags[QStringLiteral("mx:action")] = action;
112 }
113 
114 
115 
117 {
118  return m_tags.value( key );
119 }
120 
121 void OsmPlacemarkData::addTag( const QString& key, const QString& value )
122 {
123  m_tags.insert( key, value );
124 }
125 
127 {
128  m_tags.remove( key );
129 }
130 
131 bool OsmPlacemarkData::containsTag( const QString &key, const QString &value ) const
132 {
133  auto const iter = m_tags.constFind(key);
134  return iter == m_tags.constEnd() ? false : iter.value() == value;
135 }
136 
138 {
139  return m_tags.contains( key );
140 }
141 
143 {
144  return m_tags.constFind(key);
145 }
146 
148 {
149  return m_tags.begin();
150 }
151 
152 QHash< QString, QString >::const_iterator OsmPlacemarkData::tagsEnd() const
153 {
154  return m_tags.constEnd();
155 }
156 
157 
158 
159 
160 
162 {
163  return m_nodeReferences[ coordinates ];
164 }
165 
167 {
168  return m_nodeReferences.value( coordinates );
169 }
170 
172 {
173  m_nodeReferences.insert( key, value );
174 }
175 
176 void OsmPlacemarkData::removeNodeReference( const GeoDataCoordinates &key )
177 {
178  m_nodeReferences.remove( key );
179 }
180 
181 bool OsmPlacemarkData::containsNodeReference( const GeoDataCoordinates &key ) const
182 {
183  return m_nodeReferences.contains( key );
184 }
185 
187 {
188  m_nodeReferences.insert( newKey, m_nodeReferences.value( oldKey ) );
189  m_nodeReferences.remove( oldKey );
190 }
191 
193 {
194  return m_nodeReferences;
195 }
196 
197 QHash< GeoDataCoordinates, OsmPlacemarkData >::const_iterator OsmPlacemarkData::nodeReferencesBegin() const
198 {
199  return m_nodeReferences.begin();
200 }
201 
202 QHash< GeoDataCoordinates, OsmPlacemarkData >::const_iterator OsmPlacemarkData::nodeReferencesEnd() const
203 {
204  return m_nodeReferences.constEnd();
205 }
206 
207 
209 {
210  return m_memberReferences[ key ];
211 }
212 
214 {
215  return m_memberReferences.value( key );
216 }
217 
218 
220 {
221  m_memberReferences.insert( key, value );
222 }
223 
224 void OsmPlacemarkData::removeMemberReference( int key )
225 {
226  // If an inner boundary is deleted, all indexes higher than the deleted one
227  // must be lowered by 1 to keep order.
229  QHash< int, OsmPlacemarkData >::iterator it = m_memberReferences.begin();
230  QHash< int, OsmPlacemarkData >::iterator end = m_memberReferences.end();
231 
232  for ( ; it != end; ++it ) {
233  if ( it.key() > key ) {
234  newHash.insert( it.key() - 1, it.value() );
235  }
236  else if ( it.key() < key ) {
237  newHash.insert( it.key(), it.value() );
238  }
239  }
240  m_memberReferences = newHash;
241 }
242 
243 bool OsmPlacemarkData::containsMemberReference( int key ) const
244 {
245  return m_memberReferences.contains( key );
246 }
247 
248 QHash<int, OsmPlacemarkData> &OsmPlacemarkData::memberReferences()
249 {
250  return m_memberReferences;
251 }
252 
253 QHash< int, OsmPlacemarkData >::const_iterator OsmPlacemarkData::memberReferencesBegin() const
254 {
255  return m_memberReferences.begin();
256 }
257 
258 QHash< int, OsmPlacemarkData >::const_iterator OsmPlacemarkData::memberReferencesEnd() const
259 {
260  return m_memberReferences.constEnd();
261 }
262 
263 void OsmPlacemarkData::addRelation( qint64 id, const QString &role )
264 {
265  m_relationReferences.insert( id, role );
266 }
267 
268 void OsmPlacemarkData::removeRelation( qint64 id )
269 {
270  m_relationReferences.remove( id );
271 }
272 
273 bool OsmPlacemarkData::containsRelation( qint64 id ) const
274 {
275  return m_relationReferences.contains( id );
276 }
277 
278 QHash< qint64, QString >::const_iterator OsmPlacemarkData::relationReferencesBegin() const
279 {
280  return m_relationReferences.begin();
281 }
282 
283 QHash< qint64, QString >::const_iterator OsmPlacemarkData::relationReferencesEnd() const
284 {
285  return m_relationReferences.constEnd();
286 }
287 
289 {
290  return !m_id;
291 }
292 
294 {
295  return m_tags.isEmpty() &&
296  m_nodeReferences.isEmpty() &&
297  m_memberReferences.isEmpty() &&
298  m_relationReferences.isEmpty();
299 }
300 
302 {
303  OsmPlacemarkData osmData;
304  osmData.setId(attributes.value(QLatin1String("id")).toLongLong());
305  osmData.setVersion(attributes.value(QLatin1String("version")).toString());
306  osmData.setChangeset(attributes.value(QLatin1String("changeset")).toString());
307  osmData.setUser(attributes.value(QLatin1String("user")).toString());
308  osmData.setUid(attributes.value(QLatin1String("uid")).toString());
309  osmData.setVisible(attributes.value(QLatin1String("visible")).toString());
310  osmData.setTimestamp(attributes.value(QLatin1String("timestamp")).toString());
311  osmData.setAction(attributes.value(QLatin1String("action")).toString());
312  return osmData;
313 }
314 
315 const char *OsmPlacemarkData::nodeType() const
316 {
317  return "OsmPlacemarkDataType";
318 }
319 
320 }
QHash< QString, QString >::const_iterator findTag(const QString &key) const
tagValue returns a pointer to the tag that has key as key or the end iterator if there is no such tag...
A 3d point representation.
QHash::iterator insert(const Key &key, const T &value)
This class is used to encapsulate the osm data fields kept within a placemark&#39;s extendedData.
bool containsTagKey(const QString &key) const
containsTagKey returns true if the tag hash contains an entry with the key as key ...
bool isEmpty() const
isEmpty returns true if no attribute other than the id has been set
Binds a QML item to a specific geodetic location in screen coordinates.
QString toString() const const
QHash::const_iterator constFind(const Key &key) const const
QStringRef value(const QString &namespaceUri, const QString &name) const const
const char * nodeType() const override
Provides type information for downcasting a GeoNode.
void addMemberReference(int key, const OsmPlacemarkData &value)
addRef this function inserts a int = OsmplacemarkData mapping into the reference hash, equivalent to the osm <nd ref="@p boundary of index @key" > core data element
QHash::const_iterator constEnd() const const
QHash< GeoDataCoordinates, OsmPlacemarkData > & nodeReferences()
iterators for the reference hashes.
QHash::iterator begin()
OsmPlacemarkData & nodeReference(const GeoDataCoordinates &coordinates)
this function returns the osmData associated with a nd
void addRelation(qint64 id, const QString &role)
addRelation calling this makes the osm placemark a member of the relation with id as id...
qlonglong toLongLong(bool *ok, int base) const const
void changeNodeReference(const GeoDataCoordinates &oldKey, const GeoDataCoordinates &newKey)
changeNodeReference is a convenience function that allows the quick change of a node hash entry...
bool isNull() const
isNull returns false if the osmData is loaded from a source or true if its just default constructed ...
OsmPlacemarkData & memberReference(int key)
this function returns the osmData associated with a member boundary&#39;s index -1 represents the outer b...
QString tagValue(const QString &key) const
tagValue returns the value of the tag that has key as key or an empty qstring if there is no such tag...
bool containsTag(const QString &key, const QString &value) const
containsTag returns true if the tag hash contains an entry with the key as key and value as value ...
void addNodeReference(const GeoDataCoordinates &key, const OsmPlacemarkData &value)
addRef this function inserts a GeoDataCoordinates = OsmPlacemarkData mapping into the reference hash...
bool contains(const Key &key) const const
QHash< QString, QString >::const_iterator tagsBegin() const
iterators for the tags hash.
void removeTag(const QString &key)
removeTag removes the tag from the tag hash
void addTag(const QString &key, const QString &value)
addTag this function inserts a string key=value mapping, equivalent to the <tag k="@p key" v="@p valu...
static OsmPlacemarkData fromParserAttributes(const QXmlStreamAttributes &attributes)
fromParserAttributes is a convenience function that parses all osm-related arguments of a tag ...
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jul 6 2020 23:19:00 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.