Marble

GeoDataObject.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2007 Murad Tagirov <tmurad@gmail.com>
4// SPDX-FileCopyrightText: 2008 Jens-Michael Hoffmann <jensmh@gmx.de>
5//
6
7
8#ifndef MARBLE_GEODATAOBJECT_H
9#define MARBLE_GEODATAOBJECT_H
10
11#include "geodata_export.h"
12
13#include "GeoDocument.h"
14#include "Serializable.h"
15
16#include <QMetaType>
17
18namespace Marble
19{
20
21class GeoDataObjectPrivate;
22
23/**
24 * @short A base class for all geodata objects
25 *
26 * GeoDataObject is the base class for all geodata classes. It is
27 * never instantiated by itself, but is always used as part of a
28 * derived object.
29 *
30 * The Geodata objects are all modeled after the Google KML files as
31 * defined in
32 * https://developers.google.com/kml/documentation/kmlreference.
33 *
34 * A GeoDataObject contains 2 properties, both corresponding directly
35 * to tags in the KML files: the <b>id</b>, which is a unique
36 * identifier of the object, and a <b>targetId</b> which is used to
37 * reference other objects that have already been loaded.
38 *
39 * The <b>id</b> property must only be set if the <b>Update</b>
40 * mechanism of KML is used, which is currently not supported by
41 * Marble.
42 */
43class GEODATA_EXPORT GeoDataObject : public GeoNode,
44 public Serializable
45{
46public:
49 GeoDataObject & operator=( const GeoDataObject & );
50 ~GeoDataObject() override;
51
52 /// Provides the parent of the object in GeoDataContainers
53 const GeoDataObject *parent() const;
54 GeoDataObject *parent();
55
56 /// Sets the parent of the object
57 void setParent(GeoDataObject *parent);
58
59 /**
60 * @brief Get the id of the object.
61 */
62 QString id() const;
63 /**
64 * @brief Set the id of the object
65 * @param value the new id value
66 */
67 void setId( const QString &value );
68
69 /**
70 * @brief Get the targetId of the object to be replaced
71 */
72 QString targetId() const;
73 /**
74 * @brief set a new targetId of this object
75 * @param value the new targetId value
76 */
77 void setTargetId( const QString &value );
78
79 QString resolvePath( const QString &relativePath ) const;
80
81 /// Reimplemented from Serializable
82 void pack( QDataStream& stream ) const override;
83 /// Reimplemented from Serializable
84 void unpack( QDataStream& steam ) override;
85
86 private:
87
88 GeoDataObjectPrivate * d;
89
90 protected:
91 /**
92 * @brief Compares the value of id and targetId of the two objects
93 * @return true if they these values are equal or false otherwise
94 */
95 virtual bool equals(const GeoDataObject &other) const;
96};
97
98
99/**
100 * Returns the given node cast to type T if the node was instantiated as type T; otherwise returns 0.
101 * If node is 0 then it will also return 0.
102 *
103 * @param node pointer to GeoNode object to be casted
104 * @return the given node as type T if cast is successful, otherwise 0
105 */
106template<typename T>
108{
109 if (node == nullptr) {
110 return nullptr;
111 }
112
113 if (typeid(*node) == typeid(T)) {
114 return static_cast<T *>(node);
115 }
116
117 return nullptr;
118}
119
120/**
121 * Returns the given node cast to type const T if the node was instantiated as type T; otherwise returns 0.
122 * If node is 0 then it will also return 0.
123 *
124 * @param node pointer to GeoNode object to be casted
125 * @return the given node as type const T if cast is successful, otherwise 0
126 */
127template<typename T>
128const T *geodata_cast(const GeoDataObject *node)
129{
130 if (node == nullptr) {
131 return nullptr;
132 }
133
134 if (typeid(*node) == typeid(T)) {
135 return static_cast<const T *>(node);
136 }
137
138 return nullptr;
139}
140
141}
142
143Q_DECLARE_METATYPE( Marble::GeoDataObject* )
144
145#endif
A base class for all geodata objects.
A shared base class for all classes that are mapped to a specific tag (ie.
Definition GeoDocument.h:35
Binds a QML item to a specific geodetic location in screen coordinates.
T * geodata_cast(GeoDataObject *node)
Returns the given node cast to type T if the node was instantiated as type T; otherwise returns 0.
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.