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

KDE's Doxygen guidelines are available online.