diff --git a/src/lib/marble/geodata/data/GeoDataObject.h b/src/lib/marble/geodata/data/GeoDataObject.h index 77b8eb35e..ee1526be4 100644 --- a/src/lib/marble/geodata/data/GeoDataObject.h +++ b/src/lib/marble/geodata/data/GeoDataObject.h @@ -1,150 +1,150 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2007 Murad Tagirov // Copyright 2008 Jens-Michael Hoffmann // #ifndef MARBLE_GEODATAOBJECT_H #define MARBLE_GEODATAOBJECT_H #include "geodata_export.h" #include "GeoDocument.h" #include "Serializable.h" #include namespace Marble { class GeoDataObjectPrivate; /** * @short A base class for all geodata objects * * GeoDataObject is the base class for all geodata classes. It is * never instantiated by itself, but is always used as part of a * derived object. * * The Geodata objects are all modeled after the Google KML files as * defined in * http://code.google.com/apis/kml/documentation/kml_tags_21.html. * * A GeoDataObject contains 2 properties, both corresponding directly * to tags in the KML files: the id, which is a unique * identifier of the object, and a targetId which is used to * reference other objects that have already been loaded. * * The id property must only be set if the Update * mechanism of KML is used, which is currently not supported by * Marble. */ class GEODATA_EXPORT GeoDataObject : public GeoNode, public Serializable { public: GeoDataObject(); GeoDataObject( const GeoDataObject & ); GeoDataObject & operator=( const GeoDataObject & ); ~GeoDataObject() override; /// Provides the parent of the object in GeoDataContainers const GeoDataObject *parent() const; GeoDataObject *parent(); /// Sets the parent of the object void setParent(GeoDataObject *parent); /** * @brief Get the id of the object. */ QString id() const; /** * @brief Set the id of the object * @param value the new id value */ void setId( const QString &value ); /** * @brief Get the targetId of the object to be replaced */ QString targetId() const; /** * @brief set a new targetId of this object * @param value the new targetId value */ void setTargetId( const QString &value ); QString resolvePath( const QString &relativePath ) const; /// Reimplemented from Serializable void pack( QDataStream& stream ) const override; /// Reimplemented from Serializable void unpack( QDataStream& steam ) override; private: GeoDataObjectPrivate * d; protected: /** * @brief Compares the value of id and targetId of the two objects * @return true if they these values are equal or false otherwise */ virtual bool equals(const GeoDataObject &other) const; }; /** * Returns the given node cast to type T if the node was instantiated as type T; otherwise returns 0. * If node is 0 then it will also return 0. * * @param node pointer to GeoNode object to be casted * @return the given node as type T if cast is successful, otherwise 0 */ template -T *geodata_cast(GeoNode *node) +T *geodata_cast(GeoDataObject *node) { if (node == nullptr) { return nullptr; } if (node->nodeType() == T().nodeType()) { return static_cast(node); } return nullptr; } /** * Returns the given node cast to type const T if the node was instantiated as type T; otherwise returns 0. * If node is 0 then it will also return 0. * * @param node pointer to GeoNode object to be casted * @return the given node as type const T if cast is successful, otherwise 0 */ template -const T *geodata_cast(const GeoNode *node) +const T *geodata_cast(const GeoDataObject *node) { if (node == nullptr) { return nullptr; } if (node->nodeType() == T().nodeType()) { return static_cast(node); } return nullptr; } } Q_DECLARE_METATYPE( Marble::GeoDataObject* ) #endif diff --git a/src/lib/marble/geodata/writers/kml/KmlAnimatedUpdateTagWriter.cpp b/src/lib/marble/geodata/writers/kml/KmlAnimatedUpdateTagWriter.cpp index e1e015e5b..70af709cd 100644 --- a/src/lib/marble/geodata/writers/kml/KmlAnimatedUpdateTagWriter.cpp +++ b/src/lib/marble/geodata/writers/kml/KmlAnimatedUpdateTagWriter.cpp @@ -1,45 +1,45 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2014 Sanjiban Bairagya // #include "KmlAnimatedUpdateTagWriter.h" #include "GeoDataAnimatedUpdate.h" #include "GeoDataTypes.h" #include "GeoDataUpdate.h" #include "GeoWriter.h" #include "KmlElementDictionary.h" #include "KmlObjectTagWriter.h" namespace Marble { static GeoTagWriterRegistrar s_writerAnimatedUpdate( GeoTagWriter::QualifiedName( GeoDataTypes::GeoDataAnimatedUpdateType, kml::kmlTag_nameSpaceOgc22 ), new KmlAnimatedUpdateTagWriter ); bool KmlAnimatedUpdateTagWriter::write( const GeoNode *node, GeoWriter& writer ) const { - Q_ASSERT(geodata_cast(node)); + Q_ASSERT(dynamic_cast(node)); const GeoDataAnimatedUpdate *animUpdate = static_cast( node ); writer.writeStartElement( kml::kmlTag_nameSpaceGx22, kml::kmlTag_AnimatedUpdate ); KmlObjectTagWriter::writeIdentifiers( writer, animUpdate ); writer.writeOptionalElement( "gx:duration", animUpdate->duration(), 0.0 ); if ( animUpdate->update() ){ GeoDataUpdate const *update = dynamic_cast( animUpdate->update() ); if( update ){ writeElement( update, writer ); } } writer.writeOptionalElement( "gx:delayedStart", animUpdate->delayedStart(), 0.0 ); writer.writeEndElement(); return true; } } diff --git a/src/lib/marble/geodata/writers/kml/KmlFeatureTagWriter.cpp b/src/lib/marble/geodata/writers/kml/KmlFeatureTagWriter.cpp index 281566690..20d44a016 100644 --- a/src/lib/marble/geodata/writers/kml/KmlFeatureTagWriter.cpp +++ b/src/lib/marble/geodata/writers/kml/KmlFeatureTagWriter.cpp @@ -1,113 +1,114 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2013 Dennis Nienhüser // #include "KmlFeatureTagWriter.h" #include "GeoDataOverlay.h" #include "GeoDataTimeStamp.h" #include "GeoDataTimeSpan.h" #include "GeoDataDocument.h" #include "GeoDataStyle.h" #include "GeoDataStyleMap.h" #include "GeoDataExtendedData.h" #include "GeoDataLookAt.h" #include "GeoDataPlacemark.h" #include "GeoDataCamera.h" #include "GeoWriter.h" #include "GeoDataRegion.h" #include "GeoDataLatLonAltBox.h" #include "KmlElementDictionary.h" #include "KmlObjectTagWriter.h" #include "KmlOsmPlacemarkDataTagWriter.h" #include "OsmPlacemarkData.h" #include namespace Marble { KmlFeatureTagWriter::KmlFeatureTagWriter(const QString &elementName) : m_elementName( elementName ) { // nothing to do } bool KmlFeatureTagWriter::write( const Marble::GeoNode *node, GeoWriter &writer ) const { - if (const GeoDataDocument *document = geodata_cast(node)) { + const GeoDataFeature *feature = static_cast(node); + + if (const GeoDataDocument *document = geodata_cast(feature)) { // when a document has only one feature and no styling // the document tag is excused if( (document->id().isEmpty()) && (document->name().isEmpty()) && (document->targetId().isEmpty()) && (document->styles().count() == 0) && (document->styleMaps().count() == 0) && (document->extendedData().isEmpty()) && (document->featureList().count() == 1) ) { writeElement( document->featureList()[0], writer ); return true; } } writer.writeStartElement( m_elementName ); - GeoDataFeature const *feature = static_cast(node); KmlObjectTagWriter::writeIdentifiers( writer, feature ); writer.writeOptionalElement( kml::kmlTag_name, feature->name() ); writer.writeOptionalElement( kml::kmlTag_visibility, QString::number( feature->isVisible() ), "1" ); writer.writeOptionalElement( "address", feature->address() ); if( !feature->description().isEmpty() ) { writer.writeStartElement( "description" ); if( feature->descriptionIsCDATA() ) { writer.writeCDATA( feature->description() ); } else { writer.writeCharacters( feature->description() ); } writer.writeEndElement(); } GeoDataLookAt const * lookAt = dynamic_cast( feature->abstractView() ); if ( lookAt ) { writeElement( lookAt, writer ); } GeoDataCamera const * camera = dynamic_cast( feature->abstractView() ); if ( camera ) { writeElement( camera, writer ); } if( feature->timeStamp().when().isValid() ) { writeElement( &feature->timeStamp(), writer ); } if( feature->timeSpan().isValid() ) { writeElement( &feature->timeSpan(), writer ); } if ( !feature->region().latLonAltBox().isNull() ) { writeElement( &feature->region(), writer ); } bool const result = writeMid( node, writer ); if (geodata_cast(feature)) { KmlOsmPlacemarkDataTagWriter::write(feature, writer); } if( !feature->extendedData().isEmpty() ) { writeElement( &feature->extendedData(), writer ); } writer.writeEndElement(); return result; } } diff --git a/src/lib/marble/geodata/writers/kml/KmlTimeSpanWriter.cpp b/src/lib/marble/geodata/writers/kml/KmlTimeSpanWriter.cpp index 8f2723982..a5b55dd71 100644 --- a/src/lib/marble/geodata/writers/kml/KmlTimeSpanWriter.cpp +++ b/src/lib/marble/geodata/writers/kml/KmlTimeSpanWriter.cpp @@ -1,46 +1,46 @@ // // This file is part of the Marble Virtual Globe. // // This program is free software licensed under the GNU LGPL. You can // find a copy of this license in LICENSE.txt in the top directory of // the source code. // // Copyright 2012 Shou Ya // #include "KmlTimeSpanWriter.h" #include "GeoDataTimeSpan.h" #include "GeoDataTypes.h" #include "GeoWriter.h" #include "KmlElementDictionary.h" #include "KmlTimeStampTagWriter.h" #include "KmlObjectTagWriter.h" namespace Marble { static GeoTagWriterRegistrar s_writerLookAt( GeoTagWriter::QualifiedName( GeoDataTypes::GeoDataTimeSpanType, kml::kmlTag_nameSpaceOgc22 ), new KmlTimeSpanWriter ); bool KmlTimeSpanWriter::write( const GeoNode *node, GeoWriter& writer ) const { - const GeoDataTimeSpan *timespan = geodata_cast(node); - Q_ASSERT(timespan); + Q_ASSERT(dynamic_cast(node)); + const GeoDataTimeSpan *timespan = static_cast(node); writer.writeStartElement( kml::kmlTag_TimeSpan ); KmlObjectTagWriter::writeIdentifiers( writer, timespan ); writer.writeTextElement( "begin", KmlTimeStampTagWriter::toString( timespan->begin() ) ); writer.writeTextElement( "end", KmlTimeStampTagWriter::toString( timespan->end() ) ); writer.writeEndElement(); return true; } }