Marble

OsmPlacemarkData.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2015 Marius-Valeriu Stanciu <stanciumarius94@gmail.com>
4//
5
6// Self
7#include "osm/OsmPlacemarkData.h"
8
9// Marble
10#include "GeoDataExtendedData.h"
11
12#include <QXmlStreamAttributes>
13
14namespace Marble
15{
16
17inline uint qHash(Marble::OsmIdentifier ident, uint seed)
18{
19 return ::qHash(ident.id, seed) ^ ::qHash((int)ident.type, seed);
20}
21
22OsmPlacemarkData::OsmPlacemarkData()
23 : m_id(0)
24 , m_href(std::make_shared<OsmPlacemarkDataHashRef>())
25{
26 // nothing to do
27}
28
29OsmPlacemarkData::~OsmPlacemarkData() = default;
30
32{
33 return m_href.get();
34}
35
36qint64 OsmPlacemarkData::id() const
37{
38 return m_id;
39}
40
41qint64 OsmPlacemarkData::oid() const
42{
43 auto const value = m_tags.value(QStringLiteral("mx:oid")).toLong();
44 return value > 0 ? value : m_id;
45}
46
47QString OsmPlacemarkData::changeset() const
48{
49 return m_tags.value(QStringLiteral("mx:changeset"));
50}
51
52QString OsmPlacemarkData::version() const
53{
54 return m_tags.value(QStringLiteral("mx:version"));
55}
56
57QString OsmPlacemarkData::uid() const
58{
59 return m_tags.value(QStringLiteral("mx:uid"));
60}
61
62QString OsmPlacemarkData::isVisible() const
63{
64 return m_tags.value(QStringLiteral("mx:visible"));
65}
66
67QString OsmPlacemarkData::user() const
68{
69 return m_tags.value(QStringLiteral("mx:user"));
70}
71
72QString OsmPlacemarkData::timestamp() const
73{
74 return m_tags.value(QStringLiteral("mx:timestamp"));
75}
76
77QString OsmPlacemarkData::action() const
78{
79 return m_tags.value(QStringLiteral("mx:action"));
80}
81
82void OsmPlacemarkData::setId(qint64 id)
83{
84 m_id = id;
85}
86
87void OsmPlacemarkData::setVersion(const QString &version)
88{
89 m_tags[QStringLiteral("mx:version")] = version;
90}
91
92void OsmPlacemarkData::setChangeset(const QString &changeset)
93{
94 m_tags[QStringLiteral("mx:changeset")] = changeset;
95}
96
97void OsmPlacemarkData::setUid(const QString &uid)
98{
99 m_tags[QStringLiteral("mx:uid")] = uid;
100}
101
102void OsmPlacemarkData::setVisible(const QString &visible)
103{
104 m_tags[QStringLiteral("mx:visible")] = visible;
105}
106
107void OsmPlacemarkData::setUser(const QString &user)
108{
109 m_tags[QStringLiteral("mx:user")] = user;
110}
111
112void OsmPlacemarkData::setTimestamp(const QString &timestamp)
113{
114 m_tags[QStringLiteral("mx:timestamp")] = timestamp;
115}
116
117void OsmPlacemarkData::setAction(const QString &action)
118{
119 m_tags[QStringLiteral("mx:action")] = action;
120}
121
123{
124 return m_tags.value(key);
125}
126
127void OsmPlacemarkData::addTag(const QString &key, const QString &value)
128{
129 m_tags.insert(key, value);
130}
131
133{
134 m_tags.remove(key);
135}
136
137bool OsmPlacemarkData::containsTag(const QString &key, const QString &value) const
138{
139 auto const iter = m_tags.constFind(key);
140 return iter == m_tags.constEnd() ? false : iter.value() == value;
141}
142
144{
145 return m_tags.contains(key);
146}
147
149{
150 return m_tags.constFind(key);
151}
152
154{
155 return m_tags.begin();
156}
157
158QHash<QString, QString>::const_iterator OsmPlacemarkData::tagsEnd() const
159{
160 return m_tags.constEnd();
161}
162
163OsmPlacemarkData &OsmPlacemarkData::nodeReference(const GeoDataCoordinates &coordinates)
164{
165 return m_href->m_nodeReferences[coordinates];
166}
167
169{
170 return m_href->m_nodeReferences.value(coordinates);
171}
172
173void OsmPlacemarkData::addNodeReference(const GeoDataCoordinates &key, const OsmPlacemarkData &value)
174{
175 m_href->m_nodeReferences.insert(key, value);
176}
177
178void OsmPlacemarkData::removeNodeReference(const GeoDataCoordinates &key)
179{
180 m_href->m_nodeReferences.remove(key);
181}
182
183bool OsmPlacemarkData::containsNodeReference(const GeoDataCoordinates &key) const
184{
185 return m_href->m_nodeReferences.contains(key);
186}
187
189{
190 m_href->m_nodeReferences.insert(newKey, m_href->m_nodeReferences.value(oldKey));
191 m_href->m_nodeReferences.remove(oldKey);
192}
193
194OsmPlacemarkData &OsmPlacemarkData::memberReference(int key)
195{
196 return m_href->m_memberReferences[key];
197}
198
200{
201 return m_href->m_memberReferences.value(key);
202}
203
204void OsmPlacemarkData::addMemberReference(int key, const OsmPlacemarkData &value)
205{
206 m_href->m_memberReferences.insert(key, value);
207}
208
209void OsmPlacemarkData::removeMemberReference(int key)
210{
211 // If an inner boundary is deleted, all indexes higher than the deleted one
212 // must be lowered by 1 to keep order.
214 QHash<int, OsmPlacemarkData>::iterator it = m_href->m_memberReferences.begin();
215 QHash<int, OsmPlacemarkData>::iterator end = m_href->m_memberReferences.end();
216
217 for (; it != end; ++it) {
218 if (it.key() > key) {
219 newHash.insert(it.key() - 1, it.value());
220 } else if (it.key() < key) {
221 newHash.insert(it.key(), it.value());
222 }
223 }
224 m_href->m_memberReferences = newHash;
225}
226
227bool OsmPlacemarkData::containsMemberReference(int key) const
228{
229 return m_href->m_memberReferences.contains(key);
230}
231
232void OsmPlacemarkData::addRelation(qint64 id, OsmType type, const QString &role)
233{
234 m_relationReferences.insert({id, type}, role);
235}
236
238{
239 /// ### this is wrong and just done this way for backward behavior compatible
240 /// ### this method should probably take type as an additional argument
241 m_relationReferences.remove({id, OsmType::Node});
242 m_relationReferences.remove({id, OsmType::Way});
243 m_relationReferences.remove({id, OsmType::Relation});
244}
245
247{
248 /// ### this is wrong and just done this way for backward behavior compatible
249 /// ### this method should probably take type as an additional argument
250 return m_relationReferences.contains({id, OsmType::Node}) || m_relationReferences.contains({id, OsmType::Way})
251 || m_relationReferences.contains({id, OsmType::Relation});
252}
253
254QHash<OsmIdentifier, QString>::const_iterator OsmPlacemarkData::relationReferencesBegin() const
255{
256 return m_relationReferences.begin();
257}
258
259QHash<OsmIdentifier, QString>::const_iterator OsmPlacemarkData::relationReferencesEnd() const
260{
261 return m_relationReferences.constEnd();
262}
263
265{
266 return !m_id;
267}
268
270{
271 return m_tags.isEmpty() && m_href->m_nodeReferences.isEmpty() && m_href->m_memberReferences.isEmpty() && m_relationReferences.isEmpty();
272}
273
275{
276 OsmPlacemarkData osmData;
277 osmData.setId(attributes.value(QLatin1StringView("id")).toLongLong());
278 if (const auto s = attributes.value(QLatin1StringView("version")); !s.isEmpty()) {
279 osmData.setVersion(s.toString());
280 }
281 if (const auto s = attributes.value(QLatin1StringView("changeset")); !s.isEmpty()) {
282 osmData.setChangeset(s.toString());
283 }
284 if (const auto s = attributes.value(QLatin1StringView("user")); !s.isEmpty()) {
285 osmData.setUser(s.toString());
286 }
287 if (const auto s = attributes.value(QLatin1StringView("uid")); !s.isEmpty()) {
288 osmData.setUid(s.toString());
289 }
290 if (const auto s = attributes.value(QLatin1StringView("visible")); !s.isEmpty()) {
291 osmData.setVisible(s.toString());
292 }
293 if (const auto s = attributes.value(QLatin1StringView("timestamp")); !s.isEmpty()) {
294 osmData.setTimestamp(s.toString());
295 }
296 if (const auto s = attributes.value(QLatin1StringView("action")); !s.isEmpty()) {
297 osmData.setAction(s.toString());
298 }
299 return osmData;
300}
301
302const char *OsmPlacemarkData::nodeType() const
303{
304 return "OsmPlacemarkDataType";
305}
306
307// ---------------------------------------------------------------------------------------------------------
308
309OsmPlacemarkDataHashRef::OsmPlacemarkDataHashRef() = default;
310
315
316QHash<GeoDataCoordinates, OsmPlacemarkData>::const_iterator OsmPlacemarkDataHashRef::nodeReferencesBegin() const
317{
318 return m_nodeReferences.begin();
319}
320
321QHash<GeoDataCoordinates, OsmPlacemarkData>::const_iterator OsmPlacemarkDataHashRef::nodeReferencesEnd() const
322{
323 return m_nodeReferences.constEnd();
324}
325
326QHash<int, OsmPlacemarkData> &OsmPlacemarkDataHashRef::memberReferences()
327{
328 return m_memberReferences;
329}
330
331QHash<int, OsmPlacemarkData>::const_iterator OsmPlacemarkDataHashRef::memberReferencesBegin() const
332{
333 return m_memberReferences.begin();
334}
335
336QHash<int, OsmPlacemarkData>::const_iterator OsmPlacemarkDataHashRef::memberReferencesEnd() const
337{
338 return m_memberReferences.constEnd();
339}
340
341}
A 3d point representation.
A 3d point representation.
Container to host hash-table functions with OsmPlacemarkData as values.
QHash< GeoDataCoordinates, OsmPlacemarkData > m_nodeReferences
m_ndRefs is used to store a way's component nodes ( It is empty for other placemark types )
QHash< GeoDataCoordinates, OsmPlacemarkData > & nodeReferences()
iterators for the reference hashes.
This class is used to encapsulate the osm data fields kept within a placemark's extendedData.
OsmPlacemarkData & nodeReference(const GeoDataCoordinates &coordinates)
this function returns the osmData associated with a nd
const char * nodeType() const override
Provides type information for downcasting a GeoNode.
OsmPlacemarkData & memberReference(int key)
this function returns the osmData associated with a member boundary's index -1 represents the outer b...
void removeTag(const QString &key)
removeTag removes the tag from the tag hash
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 addMemberReference(int key, const OsmPlacemarkData &value)
addRef this function inserts a int = OsmplacemarkData mapping into the reference hash,...
bool isEmpty() const
isEmpty returns true if no attribute other than the id has been set
bool isNull() const
isNull returns false if the osmData is loaded from a source or true if its just default constructed
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...
bool containsRelation(qint64 id) const
void changeNodeReference(const GeoDataCoordinates &oldKey, const GeoDataCoordinates &newKey)
changeNodeReference is a convenience function that allows the quick change of a node hash entry.
static OsmPlacemarkData fromParserAttributes(const QXmlStreamAttributes &attributes)
fromParserAttributes is a convenience function that parses all osm-related arguments of a tag
bool containsTagKey(const QString &key) const
containsTagKey returns true if the tag hash contains an entry with the key as key
void addNodeReference(const GeoDataCoordinates &key, const OsmPlacemarkData &value)
addRef this function inserts a GeoDataCoordinates = OsmPlacemarkData mapping into the reference hash,...
QHash< QString, QString >::const_iterator tagsBegin() const
iterators for the tags hash.
void addRelation(qint64 id, OsmType type, const QString &role)
addRelation calling this makes the osm placemark a member of the relation with id as id,...
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
OsmPlacemarkDataHashRef * hRef() const
Return the insternal instance of the hash-table functions container.
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
Binds a QML item to a specific geodetic location in screen coordinates.
OsmType
Type of OSM element.
NETWORKMANAGERQT_EXPORT QString version()
bool contains(const Key &key) const const
iterator insert(const Key &key, const T &value)
bool isEmpty() const const
QStringView value(QAnyStringView namespaceUri, QAnyStringView name) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:52:10 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.