Marble

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

KDE's Doxygen guidelines are available online.