Marble

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

KDE's Doxygen guidelines are available online.