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{
25 // nothing to do
26}
27
28qint64 OsmPlacemarkData::id() const
29{
30 return m_id;
31}
32
33qint64 OsmPlacemarkData::oid() const
34{
35 auto const value = m_tags.value(QStringLiteral("mx:oid")).toLong();
36 return value > 0 ? value : m_id;
37}
38
39QString OsmPlacemarkData::changeset() const
40{
41 return m_tags.value(QStringLiteral("mx:changeset"));
42}
43
44QString OsmPlacemarkData::version() const
45{
46 return m_tags.value(QStringLiteral("mx:version"));
47}
48
49QString OsmPlacemarkData::uid() const
50{
51 return m_tags.value(QStringLiteral("mx:uid"));
52}
53
54QString OsmPlacemarkData::isVisible() const
55{
56 return m_tags.value(QStringLiteral("mx:visible"));
57}
58
59QString OsmPlacemarkData::user() const
60{
61 return m_tags.value(QStringLiteral("mx:user"));
62}
63
64QString OsmPlacemarkData::timestamp() const
65{
66 return m_tags.value(QStringLiteral("mx:timestamp"));
67}
68
69QString OsmPlacemarkData::action() const
70{
71 return m_tags.value(QStringLiteral("mx:action"));
72}
73
74void OsmPlacemarkData::setId( qint64 id )
75{
76 m_id = id;
77}
78
79void OsmPlacemarkData::setVersion( const QString& version )
80{
81 m_tags[QStringLiteral("mx:version")] = version;
82}
83
84void OsmPlacemarkData::setChangeset( const QString& changeset )
85{
86 m_tags[QStringLiteral("mx:changeset")] = changeset;
87}
88
89void OsmPlacemarkData::setUid( const QString& uid )
90{
91 m_tags[QStringLiteral("mx:uid")] = uid;
92}
93
94void OsmPlacemarkData::setVisible( const QString& visible )
95{
96 m_tags[QStringLiteral("mx:visible")] = visible;
97}
98
99void OsmPlacemarkData::setUser( const QString& user )
100{
101 m_tags[QStringLiteral("mx:user")] = user;
102}
103
104void OsmPlacemarkData::setTimestamp( const QString& timestamp )
105{
106 m_tags[QStringLiteral("mx:timestamp")] = timestamp;
107}
108
109void OsmPlacemarkData::setAction( const QString& action )
110{
111 m_tags[QStringLiteral("mx:action")] = action;
112}
113
114
115
116QString OsmPlacemarkData::tagValue( const QString& key ) const
117{
118 return m_tags.value( key );
119}
120
121void OsmPlacemarkData::addTag( const QString& key, const QString& value )
122{
123 m_tags.insert( key, value );
124}
125
126void OsmPlacemarkData::removeTag( const QString &key )
127{
128 m_tags.remove( key );
129}
130
131bool 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
137bool OsmPlacemarkData::containsTagKey( const QString &key ) const
138{
139 return m_tags.contains( key );
140}
141
142QHash<QString, QString>::const_iterator OsmPlacemarkData::findTag(const QString &key) const
143{
144 return m_tags.constFind(key);
145}
146
147QHash< QString, QString >::const_iterator OsmPlacemarkData::tagsBegin() const
148{
149 return m_tags.begin();
150}
151
152QHash< QString, QString >::const_iterator OsmPlacemarkData::tagsEnd() const
153{
154 return m_tags.constEnd();
155}
156
157
158
159
160
161OsmPlacemarkData &OsmPlacemarkData::nodeReference( const GeoDataCoordinates &coordinates )
162{
163 return m_nodeReferences[ coordinates ];
164}
165
166OsmPlacemarkData OsmPlacemarkData::nodeReference( const GeoDataCoordinates &coordinates ) const
167{
168 return m_nodeReferences.value( coordinates );
169}
170
171void OsmPlacemarkData::addNodeReference( const GeoDataCoordinates &key, const OsmPlacemarkData &value )
172{
173 m_nodeReferences.insert( key, value );
174}
175
176void OsmPlacemarkData::removeNodeReference( const GeoDataCoordinates &key )
177{
178 m_nodeReferences.remove( key );
179}
180
181bool OsmPlacemarkData::containsNodeReference( const GeoDataCoordinates &key ) const
182{
183 return m_nodeReferences.contains( key );
184}
185
186void OsmPlacemarkData::changeNodeReference( const GeoDataCoordinates &oldKey, const GeoDataCoordinates &newKey )
187{
188 m_nodeReferences.insert( newKey, m_nodeReferences.value( oldKey ) );
189 m_nodeReferences.remove( oldKey );
190}
191
192QHash<GeoDataCoordinates, OsmPlacemarkData> &OsmPlacemarkData::nodeReferences()
193{
194 return m_nodeReferences;
195}
196
197QHash< GeoDataCoordinates, OsmPlacemarkData >::const_iterator OsmPlacemarkData::nodeReferencesBegin() const
198{
199 return m_nodeReferences.begin();
200}
201
202QHash< GeoDataCoordinates, OsmPlacemarkData >::const_iterator OsmPlacemarkData::nodeReferencesEnd() const
203{
204 return m_nodeReferences.constEnd();
205}
206
207
208OsmPlacemarkData &OsmPlacemarkData::memberReference( int key )
209{
210 return m_memberReferences[ key ];
211}
212
213OsmPlacemarkData OsmPlacemarkData::memberReference( int key ) const
214{
215 return m_memberReferences.value( key );
216}
217
218
219void OsmPlacemarkData::addMemberReference( int key, const OsmPlacemarkData &value )
220{
221 m_memberReferences.insert( key, value );
222}
223
224void 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
243bool OsmPlacemarkData::containsMemberReference( int key ) const
244{
245 return m_memberReferences.contains( key );
246}
247
248QHash<int, OsmPlacemarkData> &OsmPlacemarkData::memberReferences()
249{
250 return m_memberReferences;
251}
252
253QHash< int, OsmPlacemarkData >::const_iterator OsmPlacemarkData::memberReferencesBegin() const
254{
255 return m_memberReferences.begin();
256}
257
258QHash< int, OsmPlacemarkData >::const_iterator OsmPlacemarkData::memberReferencesEnd() const
259{
260 return m_memberReferences.constEnd();
261}
262
263void OsmPlacemarkData::addRelation( qint64 id, OsmType type, const QString &role )
264{
265 m_relationReferences.insert( { id, type }, role );
266}
267
268void OsmPlacemarkData::removeRelation( qint64 id )
269{
270 /// ### this is wrong and just done this way for backward behavior compatible
271 /// ### this method should probably take type as an additional argument
272 m_relationReferences.remove( { id, OsmType::Node } );
273 m_relationReferences.remove( { id, OsmType::Way } );
274 m_relationReferences.remove( { id, OsmType::Relation } );
275}
276
277bool OsmPlacemarkData::containsRelation( qint64 id ) const
278{
279 /// ### this is wrong and just done this way for backward behavior compatible
280 /// ### this method should probably take type as an additional argument
281 return m_relationReferences.contains( { id, OsmType::Node } )
282 || m_relationReferences.contains( { id, OsmType::Way } )
283 || m_relationReferences.contains( { id, OsmType::Relation } );
284}
285
286QHash< OsmIdentifier, QString >::const_iterator OsmPlacemarkData::relationReferencesBegin() const
287{
288 return m_relationReferences.begin();
289}
290
291QHash< OsmIdentifier, QString >::const_iterator OsmPlacemarkData::relationReferencesEnd() const
292{
293 return m_relationReferences.constEnd();
294}
295
296bool OsmPlacemarkData::isNull() const
297{
298 return !m_id;
299}
300
301bool OsmPlacemarkData::isEmpty() const
302{
303 return m_tags.isEmpty() &&
304 m_nodeReferences.isEmpty() &&
305 m_memberReferences.isEmpty() &&
306 m_relationReferences.isEmpty();
307}
308
309OsmPlacemarkData OsmPlacemarkData::fromParserAttributes( const QXmlStreamAttributes &attributes )
310{
311 OsmPlacemarkData osmData;
312 osmData.setId(attributes.value(QLatin1String("id")).toLongLong());
313 if (const auto s = attributes.value(QLatin1String("version")); !s.isEmpty()) {
314 osmData.setVersion(s.toString());
315 }
316 if (const auto s = attributes.value(QLatin1String("changeset")); !s.isEmpty()) {
317 osmData.setChangeset(s.toString());
318 }
319 if (const auto s = attributes.value(QLatin1String("user")); !s.isEmpty()) {
320 osmData.setUser(s.toString());
321 }
322 if (const auto s = attributes.value(QLatin1String("uid")); !s.isEmpty()) {
323 osmData.setUid(s.toString());
324 }
325 if (const auto s = attributes.value(QLatin1String("visible")); !s.isEmpty()) {
326 osmData.setVisible(s.toString());
327 }
328 if (const auto s = attributes.value(QLatin1String("timestamp")); !s.isEmpty()) {
329 osmData.setTimestamp(s.toString());
330 }
331 if (const auto s = attributes.value(QLatin1String("action")); !s.isEmpty()) {
332 osmData.setAction(s.toString());
333 }
334 return osmData;
335}
336
337const char *OsmPlacemarkData::nodeType() const
338{
339 return "OsmPlacemarkDataType";
340}
341
342}
A 3d point representation.
This class is used to encapsulate the osm data fields kept within a placemark's extendedData.
KTEXTEDITOR_EXPORT size_t qHash(KTextEditor::Cursor cursor, size_t seed=0) noexcept
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)
const_iterator constEnd() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString & insert(qsizetype position, QChar ch)
QString & remove(QChar ch, Qt::CaseSensitivity cs)
bool isEmpty() const const
QStringView value(QAnyStringView namespaceUri, QAnyStringView name) const const
Identifier for an OSM element.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.