File indexing completed on 2024-04-28 03:49:01

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2007 Murad Tagirov <tmurad@gmail.com>
0004 // SPDX-FileCopyrightText: 2008 Jens-Michael Hoffmann <jensmh@gmx.de>
0005 //
0006 
0007 
0008 #ifndef MARBLE_GEODATAOBJECT_H
0009 #define MARBLE_GEODATAOBJECT_H
0010 
0011 #include "geodata_export.h"
0012 
0013 #include "GeoDocument.h" 
0014 #include "Serializable.h"
0015 
0016 #include <QMetaType>
0017 
0018 namespace Marble
0019 {
0020 
0021 class GeoDataObjectPrivate;
0022 
0023 /**
0024  * @short A base class for all geodata objects
0025  *
0026  * GeoDataObject is the base class for all geodata classes. It is
0027  * never instantiated by itself, but is always used as part of a
0028  * derived object.
0029  *
0030  * The Geodata objects are all modeled after the Google KML files as
0031  * defined in
0032  * https://developers.google.com/kml/documentation/kmlreference.
0033  *
0034  * A GeoDataObject contains 2 properties, both corresponding directly
0035  * to tags in the KML files: the <b>id</b>, which is a unique
0036  * identifier of the object, and a <b>targetId</b> which is used to
0037  * reference other objects that have already been loaded.
0038  *
0039  * The <b>id</b> property must only be set if the <b>Update</b>
0040  * mechanism of KML is used, which is currently not supported by
0041  * Marble.
0042  */
0043 class GEODATA_EXPORT GeoDataObject : public GeoNode,
0044                       public Serializable
0045 {
0046 public:
0047     GeoDataObject();
0048     GeoDataObject( const GeoDataObject & );
0049     GeoDataObject & operator=( const GeoDataObject & );
0050     ~GeoDataObject() override;
0051 
0052     /// Provides the parent of the object in GeoDataContainers
0053     const GeoDataObject *parent() const;
0054     GeoDataObject *parent();
0055 
0056     /// Sets the parent of the object
0057     void setParent(GeoDataObject *parent);
0058 
0059     /**
0060      * @brief Get the id of the object.
0061      */
0062     QString id() const;
0063     /**
0064      * @brief Set the id of the object
0065      * @param value the new id value
0066      */
0067     void setId( const QString &value );
0068 
0069     /**
0070      * @brief Get the targetId of the object to be replaced
0071      */
0072     QString targetId() const;
0073     /**
0074      * @brief set a new targetId of this object
0075      * @param value the new targetId value
0076      */
0077     void setTargetId( const QString &value );
0078 
0079     QString resolvePath( const QString &relativePath ) const;
0080 
0081     /// Reimplemented from Serializable
0082     void pack( QDataStream& stream ) const override;
0083     /// Reimplemented from Serializable
0084     void unpack( QDataStream& steam ) override;
0085 
0086  private:
0087 
0088     GeoDataObjectPrivate * d;
0089 
0090  protected:
0091     /**
0092      * @brief Compares the value of id and targetId of the two objects
0093      * @return true if they these values are equal or false otherwise
0094      */
0095     virtual bool equals(const GeoDataObject &other) const;
0096 };
0097 
0098 
0099 /**
0100  * Returns the given node cast to type T if the node was instantiated as type T; otherwise returns 0.
0101  * If node is 0 then it will also return 0.
0102  *
0103  * @param node pointer to GeoNode object to be casted
0104  * @return the given node as type T if cast is successful, otherwise 0
0105  */
0106 template<typename T>
0107 T *geodata_cast(GeoDataObject *node)
0108 {
0109     if (node == nullptr) {
0110         return nullptr;
0111     }
0112 
0113     if (typeid(*node) == typeid(T)) {
0114         return static_cast<T *>(node);
0115     }
0116 
0117     return nullptr;
0118 }
0119 
0120 /**
0121  * Returns the given node cast to type const T if the node was instantiated as type T; otherwise returns 0.
0122  * If node is 0 then it will also return 0.
0123  *
0124  * @param node pointer to GeoNode object to be casted
0125  * @return the given node as type const T if cast is successful, otherwise 0
0126  */
0127 template<typename T>
0128 const T *geodata_cast(const GeoDataObject *node)
0129 {
0130     if (node == nullptr) {
0131         return nullptr;
0132     }
0133 
0134     if (typeid(*node) == typeid(T)) {
0135         return static_cast<const T *>(node);
0136     }
0137 
0138     return nullptr;
0139 }
0140 
0141 }
0142 
0143 Q_DECLARE_METATYPE( Marble::GeoDataObject* )
0144 
0145 #endif