Marble

OsmPlacemarkData.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2015 Marius-Valeriu Stanciu <stanciumarius94@gmail.com>
4//
5
6#ifndef MARBLE_OSMPLACEMARKDATA_H
7#define MARBLE_OSMPLACEMARKDATA_H
8
9// Qt
10#include <QHash>
11#include <QMetaType>
12#include <QString>
13
14// Marble
15#include "GeoDataCoordinates.h"
16#include <marble_export.h>
17#include "GeoDocument.h"
18
20
21namespace Marble
22{
23
24/** Type of OSM element. */
25enum class OsmType {
26 Node,
27 Way,
28 Relation
29};
30
31/** Identifier for an OSM element.
32 * @note OSM uses distinct id spaces for all its three basic element types, so just the numeric id
33 * on its own doesn't identify an element without knowing its type.
34 */
36 inline OsmIdentifier() = default;
37 inline OsmIdentifier(qint64 _id, OsmType _type) : id(_id), type(_type) {}
38
39 qint64 id = 0;
40 OsmType type = OsmType::Way;
41
42 inline bool operator==(OsmIdentifier other) const { return id == other.id && type == other.type; }
43};
44
45/**
46 * This class is used to encapsulate the osm data fields kept within a placemark's extendedData.
47 * It stores OSM server generated data: id, version, changeset, uid, visible, user, timestamp;
48 * It also stores a hash map of <tags> ( key-value mappings ) and a hash map of component osm
49 * placemarks @see m_nodeReferences @see m_memberReferences
50 *
51 * The usual workflow with osmData goes as follows:
52 *
53 * Parsing stage:
54 * The OsmParser parses tags (they have server-generated attributes), creates new placemarks and
55 * assigns them new OsmPlacemarkData objects with all the needed information.
56 *
57 * Editing stage:
58 * While editing placemarks that have OsmPlacemarkData, all relevant changes reflect on the
59 * OsmPlacemarkData object as well, so as not to uncorrelate data from the actual placemarks.
60 *
61 * Writing stage:
62 * The OsmObjectManager assigns OsmPlacemarkData objects to placemarks that do not have it
63 * ( these are usually newly created placemarks within the editor, or placemarks loaded from
64 * ".kml" files ). Placemarks that already have it, are simply written as-is.
65 */
66class MARBLE_EXPORT OsmPlacemarkData: public GeoNode
67{
68
69public:
71
72 qint64 id() const;
73 qint64 oid() const;
74 QString version() const;
75 QString changeset() const;
76 QString uid() const;
77 QString isVisible() const;
78 QString user() const;
79 QString timestamp() const;
80 QString action() const;
81 const char* nodeType() const override;
82
83 void setId( qint64 id );
84 void setVersion( const QString& version );
85 void setChangeset( const QString& changeset );
86 void setUid( const QString& uid );
87 void setVisible( const QString& visible );
88 void setUser( const QString& user );
89 void setTimestamp( const QString& timestamp );
90 void setAction( const QString& action );
91
92
93 /**
94 * @brief tagValue returns the value of the tag that has @p key as key
95 * or an empty qstring if there is no such tag
96 */
97 QString tagValue( const QString &key ) const;
98
99 /**
100 * @brief addTag this function inserts a string key=value mapping,
101 * equivalent to the <tag k="@p key" v="@p value"> osm core data
102 * element
103 */
104 void addTag( const QString& key, const QString& value );
105
106 /**
107 * @brief removeTag removes the tag from the tag hash
108 */
109 void removeTag( const QString& key );
110
111 /**
112 * @brief containsTag returns true if the tag hash contains an entry with
113 * the @p key as key and @p value as value
114 */
115 bool containsTag( const QString& key, const QString& value ) const;
116
117 /**
118 * @brief containsTagKey returns true if the tag hash contains an entry with
119 * the @p key as key
120 */
121 bool containsTagKey( const QString& key ) const;
122
123 /**
124 * @brief tagValue returns a pointer to the tag that has @p key as key
125 * or the end iterator if there is no such tag
126 */
127 QHash<QString, QString>::const_iterator findTag(const QString &key) const;
128
129 /**
130 * @brief iterators for the tags hash.
131 */
132 QHash< QString, QString >::const_iterator tagsBegin() const;
133 QHash< QString, QString >::const_iterator tagsEnd() const;
134
135
136 /**
137 * @brief this function returns the osmData associated with a nd
138 */
139 OsmPlacemarkData &nodeReference( const GeoDataCoordinates& coordinates );
140 OsmPlacemarkData nodeReference( const GeoDataCoordinates& coordinates ) const;
141
142 /**
143 * @brief addRef this function inserts a GeoDataCoordinates = OsmPlacemarkData
144 * mapping into the reference hash, equivalent to the <member ref="@p key" >
145 * osm core data element
146 */
147 void addNodeReference( const GeoDataCoordinates& key, const OsmPlacemarkData &value );
148 void removeNodeReference( const GeoDataCoordinates& key );
149 bool containsNodeReference( const GeoDataCoordinates& key ) const;
150
151 /**
152 * @brief changeNodeReference is a convenience function that allows the quick change of
153 * a node hash entry. This is generally used to update the osm data in case
154 * nodes are being moved in the editor.
155 */
156 void changeNodeReference( const GeoDataCoordinates& oldKey, const GeoDataCoordinates &newKey );
157
158 /**
159 * @brief iterators for the reference hashes.
160 */
164
165
166
167 /**
168 * @brief this function returns the osmData associated with a member boundary's index
169 * -1 represents the outer boundary of a polygon, and 0,1,2... the inner boundaries,
170 * in the order provided by polygon->innerBoundaries();
171 */
172 OsmPlacemarkData &memberReference( int key );
173 OsmPlacemarkData memberReference( int key ) const;
174
175 /**
176 * @brief addRef this function inserts a int = OsmplacemarkData
177 * mapping into the reference hash, equivalent to the osm <nd ref="@p boundary of index @key" >
178 * core data element
179 * @see m_memberReferences
180 */
181 void addMemberReference( int key, const OsmPlacemarkData &value );
182 void removeMemberReference( int key );
183 bool containsMemberReference( int key ) const;
184
185 QHash< int, OsmPlacemarkData > & memberReferences();
186 QHash< int, OsmPlacemarkData >::const_iterator memberReferencesBegin() const;
187 QHash< int, OsmPlacemarkData >::const_iterator memberReferencesEnd() const;
188
189 /**
190 * @brief addRelation calling this makes the osm placemark a member of the relation
191 * with @p id as id, while having the role @p role
192 */
193 void addRelation( qint64 id, OsmType type, const QString &role );
194 void removeRelation( qint64 id );
195 bool containsRelation( qint64 id ) const;
196
197 QHash< OsmIdentifier, QString >::const_iterator relationReferencesBegin() const;
198 QHash< OsmIdentifier, QString >::const_iterator relationReferencesEnd() const;
199
200 /**
201 * @brief isNull returns false if the osmData is loaded from a source
202 * or true if its just default constructed
203 */
204 bool isNull() const;
205
206 /**
207 * @brief isEmpty returns true if no attribute other than the id has been set
208 */
209 bool isEmpty() const;
210
211 /**
212 * @brief fromParserAttributes is a convenience function that parses all osm-related
213 * arguments of a tag
214 * @return an OsmPlacemarkData object containing all the necessary data
215 */
216 static OsmPlacemarkData fromParserAttributes( const QXmlStreamAttributes &attributes );
217
218private:
219 qint64 m_id;
221
222 /**
223 * @brief m_ndRefs is used to store a way's component nodes
224 * ( It is empty for other placemark types )
225 */
227
228 /**
229 * @brief m_memberRefs is used to store a polygon's member boundaries
230 * the key represents the index of the boundary within the polygon geometry:
231 * -1 represents the outerBoundary, and 0,1,2... its innerBoundaries, in the
232 * order provided by polygon->innerBoundaries()
233 */
234 QHash<int, OsmPlacemarkData> m_memberReferences;
235
236 /**
237 * @brief m_relationReferences is used to store the relations the placemark is part of
238 * and the role it has within them.
239 * Eg. an entry ( "123", "stop" ) means that the parent placemark is a member of
240 * the relation with id "123", while having the "stop" role
241 */
242 QHash<OsmIdentifier, QString> m_relationReferences;
243
244};
245
246}
247
248// Makes qvariant_cast possible for OsmPlacemarkData objects
249Q_DECLARE_METATYPE( Marble::OsmPlacemarkData )
250
251#endif
A 3d point representation.
A shared base class for all classes that are mapped to a specific tag (ie.
Definition GeoDocument.h:35
This class is used to encapsulate the osm data fields kept within a placemark's extendedData.
Binds a QML item to a specific geodetic location in screen coordinates.
OsmType
Type of OSM element.
Identifier for an OSM element.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.