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 "GeoDocument.h"
17#include <marble_export.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)
38 : id(_id)
39 , type(_type)
40 {
41 }
42
43 qint64 id = 0;
44 OsmType type = OsmType::Way;
45
46 inline bool operator==(OsmIdentifier other) const
47 {
48 return id == other.id && type == other.type;
49 }
50};
51
52/** Forward declaration */
54
55/**
56 * This class is used to encapsulate the osm data fields kept within a placemark's extendedData.
57 * It stores OSM server generated data: id, version, changeset, uid, visible, user, timestamp;
58 * It also stores a hash map of <tags> ( key-value mappings ) and a hash map of component osm
59 * placemarks @see m_nodeReferences @see m_memberReferences
60 *
61 * The usual workflow with osmData goes as follows:
62 *
63 * Parsing stage:
64 * The OsmParser parses tags (they have server-generated attributes), creates new placemarks and
65 * assigns them new OsmPlacemarkData objects with all the needed information.
66 *
67 * Editing stage:
68 * While editing placemarks that have OsmPlacemarkData, all relevant changes reflect on the
69 * OsmPlacemarkData object as well, so as not to uncorrelate data from the actual placemarks.
70 *
71 * Writing stage:
72 * The OsmObjectManager assigns OsmPlacemarkData objects to placemarks that do not have it
73 * ( these are usually newly created placemarks within the editor, or placemarks loaded from
74 * ".kml" files ). Placemarks that already have it, are simply written as-is.
75 */
76class MARBLE_EXPORT OsmPlacemarkData : public GeoNode
77{
78public:
80 ~OsmPlacemarkData() override;
81
82 qint64 id() const;
83 qint64 oid() const;
84 QString version() const;
85 QString changeset() const;
86 QString uid() const;
87 QString isVisible() const;
88 QString user() const;
89 QString timestamp() const;
90 QString action() const;
91 const char *nodeType() const override;
92
93 void setId(qint64 id);
94 void setVersion(const QString &version);
95 void setChangeset(const QString &changeset);
96 void setUid(const QString &uid);
97 void setVisible(const QString &visible);
98 void setUser(const QString &user);
99 void setTimestamp(const QString &timestamp);
100 void setAction(const QString &action);
101
102 /**
103 * @brief tagValue returns the value of the tag that has @p key as key
104 * or an empty qstring if there is no such tag
105 */
106 QString tagValue(const QString &key) const;
107
108 /**
109 * @brief addTag this function inserts a string key=value mapping,
110 * equivalent to the <tag k="@p key" v="@p value"> osm core data
111 * element
112 */
113 void addTag(const QString &key, const QString &value);
114
115 /**
116 * @brief removeTag removes the tag from the tag hash
117 */
118 void removeTag(const QString &key);
119
120 /**
121 * @brief containsTag returns true if the tag hash contains an entry with
122 * the @p key as key and @p value as value
123 */
124 bool containsTag(const QString &key, const QString &value) const;
125
126 /**
127 * @brief containsTagKey returns true if the tag hash contains an entry with
128 * the @p key as key
129 */
130 bool containsTagKey(const QString &key) const;
131
132 /**
133 * @brief tagValue returns a pointer to the tag that has @p key as key
134 * or the end iterator if there is no such tag
135 */
136 QHash<QString, QString>::const_iterator findTag(const QString &key) const;
137
138 /**
139 * @brief iterators for the tags hash.
140 */
143
144 /**
145 * @brief this function returns the osmData associated with a nd
146 */
147 OsmPlacemarkData &nodeReference(const GeoDataCoordinates &coordinates);
148 OsmPlacemarkData nodeReference(const GeoDataCoordinates &coordinates) const;
149
150 /**
151 * @brief addRef this function inserts a GeoDataCoordinates = OsmPlacemarkData
152 * mapping into the reference hash, equivalent to the <member ref="@p key" >
153 * osm core data element
154 */
155 void addNodeReference(const GeoDataCoordinates &key, const OsmPlacemarkData &value);
156 void removeNodeReference(const GeoDataCoordinates &key);
157 bool containsNodeReference(const GeoDataCoordinates &key) const;
158
159 /**
160 * @brief changeNodeReference is a convenience function that allows the quick change of
161 * a node hash entry. This is generally used to update the osm data in case
162 * nodes are being moved in the editor.
163 */
164 void changeNodeReference(const GeoDataCoordinates &oldKey, const GeoDataCoordinates &newKey);
165
166 /**
167 * @brief this function returns the osmData associated with a member boundary's index
168 * -1 represents the outer boundary of a polygon, and 0,1,2... the inner boundaries,
169 * in the order provided by polygon->innerBoundaries();
170 */
171 OsmPlacemarkData &memberReference(int key);
172 OsmPlacemarkData memberReference(int key) const;
173
174 /**
175 * @brief addRef this function inserts a int = OsmplacemarkData
176 * mapping into the reference hash, equivalent to the osm <nd ref="@p boundary of index @key" >
177 * core data element
178 * @see m_memberReferences
179 */
180 void addMemberReference(int key, const OsmPlacemarkData &value);
181 void removeMemberReference(int key);
182 bool containsMemberReference(int key) const;
183
184 /**
185 * @brief addRelation calling this makes the osm placemark a member of the relation
186 * with @p id as id, while having the role @p role
187 */
188 void addRelation(qint64 id, OsmType type, const QString &role);
189 void removeRelation(qint64 id);
190 bool containsRelation(qint64 id) const;
191
192 QHash<OsmIdentifier, QString>::const_iterator relationReferencesBegin() const;
193 QHash<OsmIdentifier, QString>::const_iterator relationReferencesEnd() const;
194
195 /**
196 * @brief isNull returns false if the osmData is loaded from a source
197 * or true if its just default constructed
198 */
199 bool isNull() const;
200
201 /**
202 * @brief isEmpty returns true if no attribute other than the id has been set
203 */
204 bool isEmpty() const;
205
206 /**
207 * @brief fromParserAttributes is a convenience function that parses all osm-related
208 * arguments of a tag
209 * @return an OsmPlacemarkData object containing all the necessary data
210 */
211 static OsmPlacemarkData fromParserAttributes(const QXmlStreamAttributes &attributes);
212
213 /**
214 * Return the insternal instance of the hash-table functions container.
215 */
216 OsmPlacemarkDataHashRef *hRef() const;
217
218private:
219 qint64 m_id;
221
222 /**
223 * @brief m_relationReferences is used to store the relations the placemark is part of
224 * and the role it has within them.
225 * Eg. an entry ( "123", "stop" ) means that the parent placemark is a member of
226 * the relation with id "123", while having the "stop" role
227 */
228 QHash<OsmIdentifier, QString> m_relationReferences;
229
230 /**
231 * Store the insternal instance of the hash-table functions container.
232 */
233 std::shared_ptr<OsmPlacemarkDataHashRef> m_href;
234};
235
236/**
237 * Container to host hash-table functions with OsmPlacemarkData as values.
238 * This container is necessary with Qt 6.6 under MSVC 2022 as compiler refuse to build
239 * a QHash of a not fully defined class as value.
240 *
241 * E:\dk\x64-windows\include\Qt6\QtCore/qhash.h(76,7): error C2079: 'QHashPrivate::Node<Key,T>::value' uses undefined class 'Marble::OsmPlacemarkData'
242 * [C:\Users\gilles\Documents\marble\build.vcpkg\src\lib\marble\marblewidget.vcxproj] with
243 * [
244 * Key=Marble::GeoDataCoordinates,
245 * T=Marble::OsmPlacemarkData
246 * ]
247 * E:\dk\x64-windows\include\Qt6\QtCore/qhash.h(858,1): message : see reference to class template instantiation 'QHashPrivate::Node<Key,T>' being compiled
248 * [C:\Users\gilles\Documents\marble\build.vcpkg\src\lib\marble\marblewidget.vcxproj] with
249 * [
250 * Key=Marble::GeoDataCoordinates,
251 * T=Marble::OsmPlacemarkData
252 * ]
253 *
254 */
255class MARBLE_EXPORT OsmPlacemarkDataHashRef
256{
257public:
259
260 /**
261 * @brief iterators for the reference hashes.
262 */
266
267 QHash<int, OsmPlacemarkData> &memberReferences();
268 QHash<int, OsmPlacemarkData>::const_iterator memberReferencesBegin() const;
269 QHash<int, OsmPlacemarkData>::const_iterator memberReferencesEnd() const;
270
271 /**
272 * @brief m_ndRefs is used to store a way's component nodes
273 * ( It is empty for other placemark types )
274 */
276
277 /**
278 * @brief m_memberRefs is used to store a polygon's member boundaries
279 * the key represents the index of the boundary within the polygon geometry:
280 * -1 represents the outerBoundary, and 0,1,2... its innerBoundaries, in the
281 * order provided by polygon->innerBoundaries()
282 */
284};
285
286}
287
288// Makes qvariant_cast possible for OsmPlacemarkData objects
289Q_DECLARE_METATYPE(Marble::OsmPlacemarkData)
290
291#endif
A 3d point representation.
A shared base class for all classes that are mapped to a specific tag (ie.
Definition GeoDocument.h:35
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< int, OsmPlacemarkData > m_memberReferences
m_memberRefs is used to store a polygon's member boundaries the key represents the index of the bound...
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 Sat Dec 21 2024 17:04:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.