diff --git a/src/lib/marble/geodata/data/GeoDataContainer.cpp b/src/lib/marble/geodata/data/GeoDataContainer.cpp index de2838211..29ed58f5f 100644 --- a/src/lib/marble/geodata/data/GeoDataContainer.cpp +++ b/src/lib/marble/geodata/data/GeoDataContainer.cpp @@ -1,510 +1,499 @@ // // 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 2009 Patrick Spendrin // // Own #include "GeoDataContainer.h" #include "GeoDataContainer_p.h" // Marble #include "MarbleDebug.h" #include "GeoDataFeature.h" #include "GeoDataFolder.h" #include "GeoDataPlacemark.h" #include "GeoDataDocument.h" #include "GeoDataLatLonAltBox.h" #include "GeoDataGeometry.h" #include "GeoDataNetworkLinkControl.h" #include "GeoDataNetworkLink.h" #include "GeoDataGroundOverlay.h" #include "GeoDataPhotoOverlay.h" #include "GeoDataScreenOverlay.h" #include "GeoDataTour.h" #include namespace Marble { GeoDataContainer::GeoDataContainer() : GeoDataFeature( new GeoDataContainerPrivate ) { } GeoDataContainer::GeoDataContainer(GeoDataContainerPrivate *priv) : GeoDataFeature(priv) { Q_D(GeoDataContainer); d->setParent(this); } GeoDataContainer::GeoDataContainer(const GeoDataContainer& other, GeoDataContainerPrivate *priv) : GeoDataFeature(other, priv) { Q_D(GeoDataContainer); d->setParent(this); } GeoDataContainer::GeoDataContainer( const GeoDataContainer& other ) : GeoDataFeature(other, new GeoDataContainerPrivate(*other.d_func())) { Q_D(GeoDataContainer); d->setParent(this); } GeoDataContainer::~GeoDataContainer() { } GeoDataContainer& GeoDataContainer::operator=(const GeoDataContainer& other) { if (this != &other) { Q_D(GeoDataContainer); *d = *other.d_func(); } return *this; } bool GeoDataContainer::equals( const GeoDataContainer &other ) const { if ( !GeoDataFeature::equals(other) ) { return false; } Q_D(const GeoDataContainer); const GeoDataContainerPrivate* const other_d = other.d_func(); QVector::const_iterator thisBegin = d->m_vector.constBegin(); QVector::const_iterator thisEnd = d->m_vector.constEnd(); QVector::const_iterator otherBegin = other_d->m_vector.constBegin(); QVector::const_iterator otherEnd = other_d->m_vector.constEnd(); for (; thisBegin != thisEnd && otherBegin != otherEnd; ++thisBegin, ++otherBegin) { if ( (*thisBegin)->nodeType() != (*otherBegin)->nodeType() ) { return false; } if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataDocumentType ) { GeoDataDocument *thisDoc = static_cast( *thisBegin ); GeoDataDocument *otherDoc = static_cast( *otherBegin ); Q_ASSERT( thisDoc && otherDoc ); if ( *thisDoc != *otherDoc ) { return false; } } else if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataFolderType ) { GeoDataFolder *thisFolder = static_cast( *thisBegin ); GeoDataFolder *otherFolder = static_cast( *otherBegin ); Q_ASSERT( thisFolder && otherFolder ); if ( *thisFolder != *otherFolder ) { return false; } } else if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataNetworkLinkControlType ) { GeoDataNetworkLinkControl *thisNLC = static_cast( *thisBegin ); GeoDataNetworkLinkControl *otherNLC = static_cast( *otherBegin ); Q_ASSERT( thisNLC && otherNLC ); if ( *thisNLC != *otherNLC ) { return false; } } else if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataNetworkLinkType ) { GeoDataNetworkLink *thisNetLink = static_cast( *thisBegin ); GeoDataNetworkLink *otherNetLink = static_cast( *otherBegin ); Q_ASSERT( thisNetLink && otherNetLink ); if ( *thisNetLink != *otherNetLink ) { return false; } } else if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataGroundOverlayType ) { GeoDataGroundOverlay *thisGO = static_cast( *thisBegin ); GeoDataGroundOverlay *otherGO = static_cast( *otherBegin ); Q_ASSERT( thisGO && otherGO ); if ( *thisGO != *otherGO ) { return false; } } else if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataPhotoOverlayType ) { GeoDataPhotoOverlay *thisPO = static_cast( *thisBegin ); GeoDataPhotoOverlay *otherPO = static_cast( *otherBegin ); Q_ASSERT( thisPO && otherPO ); if ( *thisPO != *otherPO ) { return false; } } else if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataScreenOverlayType ) { GeoDataScreenOverlay *thisSO = static_cast( *thisBegin ); GeoDataScreenOverlay *otherSO = static_cast( *otherBegin ); Q_ASSERT( thisSO && otherSO ); if ( *thisSO != *otherSO ) { return false; } } else if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataTourType ) { GeoDataTour *thisTour = static_cast( *thisBegin ); GeoDataTour *otherTour = static_cast( *otherBegin ); Q_ASSERT( thisTour && otherTour ); if ( *thisTour != *otherTour ) { return false; } } else if ( (*thisBegin)->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) { GeoDataPlacemark *thisPM = static_cast( *thisBegin ); GeoDataPlacemark *otherPM = static_cast( *otherBegin ); Q_ASSERT( thisPM && otherPM ); if ( *thisPM != *otherPM ) { return false; } } } return thisBegin == thisEnd && otherBegin == otherEnd; } -const char* GeoDataContainer::nodeType() const -{ - return GeoDataTypes::GeoDataContainerType; -} - - -GeoDataFeature * GeoDataContainer::clone() const -{ - return new GeoDataContainer(*this); -} - GeoDataLatLonAltBox GeoDataContainer::latLonAltBox() const { Q_D(const GeoDataContainer); GeoDataLatLonAltBox result; QVector::const_iterator it = d->m_vector.constBegin(); QVector::const_iterator end = d->m_vector.constEnd(); for (; it != end; ++it) { // Get all the placemarks from GeoDataContainer if ( (*it)->nodeType() == GeoDataTypes::GeoDataPlacemarkType ) { GeoDataPlacemark *placemark = static_cast(*it); // Only use visible placemarks for extracting their latLonAltBox and // making an union with the global latLonAltBox Marble will fit its // zoom to if (placemark->isVisible()) { if (result.isEmpty()) { result = placemark->geometry()->latLonAltBox(); } else { result |= placemark->geometry()->latLonAltBox(); } } } else if ( (*it)->nodeType() == GeoDataTypes::GeoDataFolderType || (*it)->nodeType() == GeoDataTypes::GeoDataDocumentType ) { GeoDataContainer *container = static_cast(*it); if (result.isEmpty()) { result = container->latLonAltBox(); } else { result |= container->latLonAltBox(); } } } return result; } QVector GeoDataContainer::folderList() const { Q_D(const GeoDataContainer); QVector results; QVector::const_iterator it = d->m_vector.constBegin(); QVector::const_iterator end = d->m_vector.constEnd(); for (; it != end; ++it) { GeoDataFolder *folder = dynamic_cast(*it); if ( folder ) { results.append( folder ); } } return results; } QVector GeoDataContainer::placemarkList() const { Q_D(const GeoDataContainer); QVector results; for (auto it = d->m_vector.constBegin(), end = d->m_vector.constEnd(); it != end; ++it) { if ((*it)->nodeType() == GeoDataTypes::GeoDataPlacemarkType) { results.append(static_cast(*it)); } } return results; } QVector GeoDataContainer::featureList() const { Q_D(const GeoDataContainer); return d->m_vector; } /** * @brief returns the requested child item */ GeoDataFeature* GeoDataContainer::child( int i ) { Q_D(GeoDataContainer); return d->m_vector.at(i); } const GeoDataFeature* GeoDataContainer::child( int i ) const { Q_D(const GeoDataContainer); return d->m_vector.at(i); } /** * @brief returns the position of an item in the list */ int GeoDataContainer::childPosition( const GeoDataFeature* object ) const { Q_D(const GeoDataContainer); for (int i = 0; i < d->m_vector.size(); ++i) { if (d->m_vector.at(i) == object) { return i; } } return -1; } void GeoDataContainer::insert( GeoDataFeature *other, int index ) { insert( index, other ); } void GeoDataContainer::insert( int index, GeoDataFeature *feature ) { Q_D(GeoDataContainer); feature->setParent(this); d->m_vector.insert( index, feature ); } void GeoDataContainer::append( GeoDataFeature *other ) { Q_D(GeoDataContainer); other->setParent(this); d->m_vector.append( other ); } void GeoDataContainer::remove( int index ) { Q_D(GeoDataContainer); d->m_vector.remove( index ); } void GeoDataContainer::remove(int index, int count) { Q_D(GeoDataContainer); d->m_vector.remove( index, count ); } int GeoDataContainer::removeAll(GeoDataFeature *feature) { Q_D(GeoDataContainer); #if QT_VERSION >= 0x050400 return d->m_vector.removeAll(feature); #else int count = 0; QVector &vector = d->m_vector; QVector::iterator it = vector.begin(); while(it != vector.end()) { if (*it == feature) { it = vector.erase(it); ++count; } else { ++it; } } return count; #endif } void GeoDataContainer::removeAt(int index) { Q_D(GeoDataContainer); d->m_vector.removeAt( index ); } void GeoDataContainer::removeFirst() { Q_D(GeoDataContainer); d->m_vector.removeFirst(); } void GeoDataContainer::removeLast() { Q_D(GeoDataContainer); d->m_vector.removeLast(); } bool GeoDataContainer::removeOne( GeoDataFeature *feature ) { Q_D(GeoDataContainer); #if QT_VERSION >= 0x050400 return d->m_vector.removeOne( feature ); #else QVector &vector = d->m_vector; const int i = vector.indexOf(feature); if (i < 0) { return false; } vector.remove(i); return true; #endif } int GeoDataContainer::size() const { Q_D(const GeoDataContainer); return d->m_vector.size(); } GeoDataFeature& GeoDataContainer::at( int pos ) { Q_D(GeoDataContainer); return *(d->m_vector[pos]); } const GeoDataFeature& GeoDataContainer::at( int pos ) const { Q_D(const GeoDataContainer); return *(d->m_vector.at(pos)); } GeoDataFeature& GeoDataContainer::last() { Q_D(GeoDataContainer); return *(d->m_vector.last()); } const GeoDataFeature& GeoDataContainer::last() const { Q_D(const GeoDataContainer); return *(d->m_vector.last()); } GeoDataFeature& GeoDataContainer::first() { Q_D(GeoDataContainer); return *(d->m_vector.first()); } const GeoDataFeature& GeoDataContainer::first() const { Q_D(const GeoDataContainer); return *(d->m_vector.first()); } void GeoDataContainer::clear() { Q_D(GeoDataContainer); qDeleteAll(d->m_vector); d->m_vector.clear(); } QVector::Iterator GeoDataContainer::begin() { Q_D(GeoDataContainer); return d->m_vector.begin(); } QVector::Iterator GeoDataContainer::end() { Q_D(GeoDataContainer); return d->m_vector.end(); } QVector::ConstIterator GeoDataContainer::constBegin() const { Q_D(const GeoDataContainer); return d->m_vector.constBegin(); } QVector::ConstIterator GeoDataContainer::constEnd() const { Q_D(const GeoDataContainer); return d->m_vector.constEnd(); } void GeoDataContainer::pack( QDataStream& stream ) const { Q_D(const GeoDataContainer); GeoDataFeature::pack( stream ); stream << d->m_vector.count(); for (QVector::const_iterator iterator = d->m_vector.constBegin(); iterator != d->m_vector.constEnd(); ++iterator ) { const GeoDataFeature *feature = *iterator; stream << feature->featureId(); feature->pack( stream ); } } void GeoDataContainer::unpack( QDataStream& stream ) { Q_D(GeoDataContainer); GeoDataFeature::unpack( stream ); int count; stream >> count; for ( int i = 0; i < count; ++i ) { int featureId; stream >> featureId; switch( featureId ) { case GeoDataDocumentId: /* not usable!!!! */ break; case GeoDataFolderId: { GeoDataFolder *folder = new GeoDataFolder; folder->unpack( stream ); d->m_vector.append( folder ); } break; case GeoDataPlacemarkId: { GeoDataPlacemark *placemark = new GeoDataPlacemark; placemark->unpack( stream ); d->m_vector.append( placemark ); } break; case GeoDataNetworkLinkId: break; case GeoDataScreenOverlayId: break; case GeoDataGroundOverlayId: break; default: break; }; } } } diff --git a/src/lib/marble/geodata/data/GeoDataContainer.h b/src/lib/marble/geodata/data/GeoDataContainer.h index 01806572b..b991e419f 100644 --- a/src/lib/marble/geodata/data/GeoDataContainer.h +++ b/src/lib/marble/geodata/data/GeoDataContainer.h @@ -1,188 +1,184 @@ // // 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 2007 Inge Wallin // Copyright 2009 Patrick Spendrin // #ifndef MARBLE_GEODATACONTAINER_H #define MARBLE_GEODATACONTAINER_H #include #include "geodata_export.h" #include "GeoDataFeature.h" namespace Marble { class GeoDataContainerPrivate; class GeoDataFolder; class GeoDataPlacemark; class GeoDataLatLonAltBox; /** * @short A base class that can hold GeoDataFeatures * * GeoDataContainer is the base class for the GeoData container * classes GeoDataFolder and GeoDataDocument. It is never * instantiated by itself, but is always used as part of a derived * class. * * It is based on GeoDataFeature, and it only adds a * QVector to it, making it a Feature that can hold * other Features. * * @see GeoDataFolder * @see GeoDataDocument */ class GEODATA_EXPORT GeoDataContainer : public GeoDataFeature { public: /// Default constructor GeoDataContainer(); GeoDataContainer( const GeoDataContainer& other ); /// Destruct the GeoDataContainer ~GeoDataContainer() override; GeoDataContainer& operator=(const GeoDataContainer& other); - const char* nodeType() const override; - - GeoDataFeature * clone() const override; - /** * @brief A convenience function that returns the LatLonAltBox of all * placemarks in this container. * @return The GeoDataLatLonAltBox * * @see GeoDataLatLonAltBox */ GeoDataLatLonAltBox latLonAltBox() const; /** * @brief A convenience function that returns all folders in this container. * @return A QVector of GeoDataFolder * * @see GeoDataFolder */ QVector folderList() const; /** * @brief A convenience function that returns all features in this container. * @return A QVector of GeoDataFeature * * @see GeoDataFeature */ QVector featureList() const; /** * @brief A convenience function that returns all placemarks in this container. * @return A QVector of GeoDataPlacemark * * @see GeoDataPlacemark */ QVector placemarkList() const; /** * @brief returns the requested child item */ GeoDataFeature* child( int ); /** * @brief returns the requested child item */ const GeoDataFeature* child( int ) const; /** * @brief returns the position of an item in the list */ int childPosition( const GeoDataFeature *child) const; /** * @brief inserts @p feature at position @p index in the container */ void insert( int index, GeoDataFeature *feature ); GEODATA_DEPRECATED void insert(GeoDataFeature *other, int index); /** * @brief add an element */ void append( GeoDataFeature *other ); void remove( int index ); void remove(int index, int count); int removeAll(GeoDataFeature* feature); void removeAt(int index); void removeFirst(); void removeLast(); bool removeOne( GeoDataFeature *feature ); /** * @brief size of the container */ int size() const; /** * @brief return the reference of the element at a specific position */ GeoDataFeature& at( int pos ); const GeoDataFeature& at( int pos ) const; /** * @brief return the reference of the last element for convenience */ GeoDataFeature& last(); const GeoDataFeature& last() const; /** * @brief return the reference of the last element for convenience */ GeoDataFeature& first(); const GeoDataFeature& first() const; QVector::Iterator begin(); QVector::Iterator end(); QVector::ConstIterator constBegin() const; QVector::ConstIterator constEnd() const; void clear(); /** * @brief Serialize the container to a stream. * @param stream the stream */ void pack( QDataStream& stream ) const override; /** * @brief Unserialize the container from a stream * @param stream the stream */ void unpack( QDataStream& stream ) override; protected: explicit GeoDataContainer(GeoDataContainerPrivate *priv); GeoDataContainer(const GeoDataContainer& other, GeoDataContainerPrivate *priv); bool equals( const GeoDataContainer &other ) const; using GeoDataFeature::equals; private: Q_DECLARE_PRIVATE(GeoDataContainer) }; } #endif diff --git a/src/lib/marble/geodata/data/GeoDataFeature.cpp b/src/lib/marble/geodata/data/GeoDataFeature.cpp index e52a25cfb..a5fa7b9a2 100644 --- a/src/lib/marble/geodata/data/GeoDataFeature.cpp +++ b/src/lib/marble/geodata/data/GeoDataFeature.cpp @@ -1,504 +1,494 @@ // // 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 2009 Patrick Spendrin // #include "GeoDataFeature.h" #include "GeoDataFeature_p.h" #include #include #include "MarbleDirs.h" #include "MarbleDebug.h" #include "GeoDataStyle.h" #include "GeoDataStyleMap.h" #include "GeoDataContainer.h" #include "GeoDataDocument.h" #include "GeoDataRegion.h" #include "GeoDataCamera.h" namespace Marble { const QSharedPointer GeoDataFeaturePrivate::s_defaultStyle(new GeoDataStyle); GeoDataFeature::GeoDataFeature() : d_ptr(new GeoDataFeaturePrivate()) { } GeoDataFeature::GeoDataFeature( const GeoDataFeature& other ) : GeoDataObject(), d_ptr(new GeoDataFeaturePrivate(*other.d_ptr)) { } GeoDataFeature::GeoDataFeature( const QString& name ) : d_ptr(new GeoDataFeaturePrivate()) { d_ptr->m_name = name; } GeoDataFeature::GeoDataFeature(GeoDataFeaturePrivate *dd) : GeoDataObject(), d_ptr(dd) { } GeoDataFeature::GeoDataFeature(const GeoDataFeature& other, GeoDataFeaturePrivate *dd) : GeoDataObject(), d_ptr(dd) { Q_UNUSED(other); // TODO: some classes pass "other" on and thus get duplicated id, also in operator=. Align behaviour } GeoDataFeature::~GeoDataFeature() { delete d_ptr; } GeoDataFeature& GeoDataFeature::operator=( const GeoDataFeature& other ) { if (this != &other) { *d_ptr = *other.d_ptr; } return *this; } bool GeoDataFeature::equals( const GeoDataFeature &other ) const { Q_D(const GeoDataFeature); const GeoDataFeaturePrivate* const other_d = other.d_func(); if (!GeoDataObject::equals(other) || d->m_name != other_d->m_name || d->m_styleUrl != other_d->m_styleUrl || d->m_popularity != other_d->m_popularity || d->m_zoomLevel != other_d->m_zoomLevel || d->m_visible != other_d->m_visible || d->m_role != other_d->m_role || d->m_extendedData != other_d->m_extendedData || *style() != *other.style()) { return false; } if ((!d->m_styleMap && other_d->m_styleMap) || (d->m_styleMap && !other_d->m_styleMap)) { return false; } if ((d->m_styleMap && other_d->m_styleMap) && (*d->m_styleMap != *other_d->m_styleMap)) { return false; } if ((!d->m_featureExtendedData && other_d->m_featureExtendedData && other_d->m_featureExtendedData->m_abstractView) || (d->m_featureExtendedData && d->m_featureExtendedData->m_abstractView && !other_d->m_featureExtendedData)) { return false; } if ((d->m_featureExtendedData && other_d->m_featureExtendedData) && (*d->m_featureExtendedData != *other_d->m_featureExtendedData)) { return false; } return true; } -GeoDataFeature * GeoDataFeature::clone() const -{ - return new GeoDataFeature(*this); -} - -const char* GeoDataFeature::nodeType() const -{ - return GeoDataTypes::GeoDataFeatureType; -} - EnumFeatureId GeoDataFeature::featureId() const { Q_D(const GeoDataFeature); return d->featureId(); } QString GeoDataFeature::name() const { Q_D(const GeoDataFeature); return d->m_name; } void GeoDataFeature::setName( const QString &value ) { Q_D(GeoDataFeature); d->m_name = value; } GeoDataSnippet GeoDataFeature::snippet() const { Q_D(const GeoDataFeature); return d->featureExtendedData().m_snippet; } void GeoDataFeature::setSnippet( const GeoDataSnippet &snippet ) { Q_D(GeoDataFeature); d->featureExtendedData().m_snippet = snippet; } QString GeoDataFeature::address() const { Q_D(const GeoDataFeature); if (!d->m_featureExtendedData) { return QString(); } return d->featureExtendedData().m_address; } void GeoDataFeature::setAddress( const QString &value) { Q_D(GeoDataFeature); if (value.isEmpty() && !d->m_featureExtendedData) { return; // nothing to change } d->featureExtendedData().m_address = value; } QString GeoDataFeature::phoneNumber() const { Q_D(const GeoDataFeature); if (!d->m_featureExtendedData) { return QString(); } return d->featureExtendedData().m_phoneNumber; } void GeoDataFeature::setPhoneNumber( const QString &value) { Q_D(GeoDataFeature); if (value.isEmpty() && !d->m_featureExtendedData) { return; // nothing to change } d->featureExtendedData().m_phoneNumber = value; } QString GeoDataFeature::description() const { Q_D(const GeoDataFeature); if (!d->m_featureExtendedData) { return QString(); } return d->featureExtendedData().m_description; } void GeoDataFeature::setDescription( const QString &value) { Q_D(GeoDataFeature); if (value.isEmpty() && !d->m_featureExtendedData) { return; // nothing to change } d->featureExtendedData().m_description = value; } bool GeoDataFeature::descriptionIsCDATA() const { Q_D(const GeoDataFeature); if (!d->m_featureExtendedData) { return false; } return d->featureExtendedData().m_descriptionCDATA; } void GeoDataFeature::setDescriptionCDATA( bool cdata ) { Q_D(GeoDataFeature); d->featureExtendedData().m_descriptionCDATA = cdata; } const GeoDataAbstractView* GeoDataFeature::abstractView() const { Q_D(const GeoDataFeature); if (!d->m_featureExtendedData) { return nullptr; } return d->featureExtendedData().m_abstractView; } GeoDataAbstractView *GeoDataFeature::abstractView() { // FIXME: Calling detach() doesn't help at all because the m_abstractView // object isn't actually copied in the Private class as well. // detach(); Q_D(GeoDataFeature); return d->featureExtendedData().m_abstractView; } void GeoDataFeature::setAbstractView( GeoDataAbstractView *abstractView ) { Q_D(GeoDataFeature); if (abstractView == nullptr && !d->m_featureExtendedData) { return; // nothing to change } d->featureExtendedData().m_abstractView = abstractView; } QString GeoDataFeature::styleUrl() const { Q_D(const GeoDataFeature); return d->m_styleUrl; } void GeoDataFeature::setStyleUrl( const QString &value ) { Q_D(GeoDataFeature); d->m_styleUrl = value; if ( value.isEmpty() ) { d->m_style = GeoDataStyle::Ptr(); return; } QString styleUrl = value; styleUrl.remove(QLatin1Char('#')); GeoDataObject *object = parent(); bool found = false; while ( object && !found ) { if( object->nodeType() == GeoDataTypes::GeoDataDocumentType ) { GeoDataDocument *doc = static_cast ( object ); GeoDataStyleMap &styleMap = doc->styleMap( styleUrl ); const QString normalStyleUrl = styleMap.value(QStringLiteral("normal")); if (!normalStyleUrl.isEmpty()) { styleUrl = normalStyleUrl; styleUrl.remove(QLatin1Char('#')); } // Not calling setStyle here because we don't want // re-parenting of the style d->m_style = doc->style( styleUrl ); found = true; } object = object->parent(); } } bool GeoDataFeature::isVisible() const { Q_D(const GeoDataFeature); return d->m_visible; } void GeoDataFeature::setVisible( bool value ) { Q_D(GeoDataFeature); d->m_visible = value; } bool GeoDataFeature::isGloballyVisible() const { Q_D(const GeoDataFeature); if ( parent() == 0 ) { return d->m_visible; } GeoDataContainer *container = static_cast( parent() ); return d->m_visible && container->isGloballyVisible(); } const GeoDataTimeSpan &GeoDataFeature::timeSpan() const { Q_D(const GeoDataFeature); return d->featureExtendedData().m_timeSpan; } GeoDataTimeSpan &GeoDataFeature::timeSpan() { Q_D(GeoDataFeature); return d->featureExtendedData().m_timeSpan; } void GeoDataFeature::setTimeSpan( const GeoDataTimeSpan &timeSpan ) { Q_D(GeoDataFeature); d->featureExtendedData().m_timeSpan = timeSpan; } const GeoDataTimeStamp &GeoDataFeature::timeStamp() const { Q_D(const GeoDataFeature); return d->featureExtendedData().m_timeStamp; } GeoDataTimeStamp &GeoDataFeature::timeStamp() { Q_D(GeoDataFeature); return d->featureExtendedData().m_timeStamp; } void GeoDataFeature::setTimeStamp( const GeoDataTimeStamp &timeStamp ) { Q_D(GeoDataFeature); d->featureExtendedData().m_timeStamp = timeStamp; } const GeoDataExtendedData &GeoDataFeature::extendedData() const { Q_D(const GeoDataFeature); return d->m_extendedData; } GeoDataStyle::ConstPtr GeoDataFeature::style() const { Q_D(const GeoDataFeature); if (d->m_style) { return d->m_style; } return GeoDataFeaturePrivate::s_defaultStyle; } GeoDataStyle::ConstPtr GeoDataFeature::customStyle() const { Q_D(const GeoDataFeature); return d->m_style; } void GeoDataFeature::setStyle( const GeoDataStyle::Ptr &style ) { Q_D(GeoDataFeature); if (style) style->setParent( this ); d->m_style = style; } GeoDataExtendedData& GeoDataFeature::extendedData() { Q_D(GeoDataFeature); return d->m_extendedData; } void GeoDataFeature::setExtendedData( const GeoDataExtendedData& extendedData ) { Q_D(GeoDataFeature); d->m_extendedData = extendedData; } const GeoDataRegion& GeoDataFeature::region() const { Q_D(const GeoDataFeature); return d->featureExtendedData().m_region; } GeoDataRegion& GeoDataFeature::region() { Q_D(GeoDataFeature); return d->featureExtendedData().m_region; } void GeoDataFeature::setRegion( const GeoDataRegion& region ) { Q_D(GeoDataFeature); d->featureExtendedData().m_region = region; } const QString GeoDataFeature::role() const { Q_D(const GeoDataFeature); return d->m_role; } void GeoDataFeature::setRole( const QString &role ) { Q_D(GeoDataFeature); d->m_role = role; } const GeoDataStyleMap* GeoDataFeature::styleMap() const { Q_D(const GeoDataFeature); return d->m_styleMap; } void GeoDataFeature::setStyleMap( const GeoDataStyleMap* styleMap ) { Q_D(GeoDataFeature); d->m_styleMap = styleMap; } int GeoDataFeature::zoomLevel() const { Q_D(const GeoDataFeature); return d->m_zoomLevel; } void GeoDataFeature::setZoomLevel( int zoomLevel ) { Q_D(GeoDataFeature); d->m_zoomLevel = zoomLevel; } qint64 GeoDataFeature::popularity() const { Q_D(const GeoDataFeature); return d->m_popularity; } void GeoDataFeature::setPopularity( qint64 popularity ) { Q_D(GeoDataFeature); d->m_popularity = popularity; } void GeoDataFeature::pack( QDataStream& stream ) const { Q_D(const GeoDataFeature); GeoDataObject::pack( stream ); stream << d->m_name; stream << d->featureExtendedData().m_address; stream << d->featureExtendedData().m_phoneNumber; stream << d->featureExtendedData().m_description; stream << d->m_visible; // stream << d->m_visualCategory; stream << d->m_role; stream << d->m_popularity; stream << d->m_zoomLevel; } void GeoDataFeature::unpack( QDataStream& stream ) { Q_D(GeoDataFeature); GeoDataObject::unpack( stream ); stream >> d->m_name; stream >> d->featureExtendedData().m_address; stream >> d->featureExtendedData().m_phoneNumber; stream >> d->featureExtendedData().m_description; stream >> d->m_visible; // stream >> (int)d->m_visualCategory; stream >> d->m_role; stream >> d->m_popularity; stream >> d->m_zoomLevel; } } diff --git a/src/lib/marble/geodata/data/GeoDataFeature.h b/src/lib/marble/geodata/data/GeoDataFeature.h index 4373a26a7..e30414d68 100644 --- a/src/lib/marble/geodata/data/GeoDataFeature.h +++ b/src/lib/marble/geodata/data/GeoDataFeature.h @@ -1,286 +1,283 @@ // // 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 2009 Patrick Spendrin // #ifndef MARBLE_GEODATAFEATURE_H #define MARBLE_GEODATAFEATURE_H #include "GeoDataObject.h" #include "geodata_export.h" namespace Marble { // forward define all features we can find. class GeoDataRegion; class GeoDataAbstractView; class GeoDataStyle; class GeoDataStyleMap; class GeoDataExtendedData; class GeoDataTimeSpan; class GeoDataTimeStamp; class GeoDataFeaturePrivate; class GeoDataSnippet; /** * @short A base class for all geodata features * * GeoDataFeature is the base class for most geodata classes that * correspond to places on a map. It is never instantiated by itself, * but is always used as part of a derived class. * * @see GeoDataPlacemark * @see GeoDataContainer */ class GEODATA_EXPORT GeoDataFeature : public GeoDataObject { public: GeoDataFeature(); /// Create a new GeoDataFeature with @p name as its name. explicit GeoDataFeature( const QString& name ); GeoDataFeature( const GeoDataFeature& other ); ~GeoDataFeature() override; GeoDataFeature& operator=( const GeoDataFeature& other ); - /// Provides type information for downcasting a GeoData - const char* nodeType() const override; - EnumFeatureId featureId() const; /** * @brief The name of the feature * * The name of the feature should be a short string. It is often * shown directly on the map and need therefore not take up much * space. * * @return The name of this feature */ QString name() const; /** * @brief Set a new name for this feature * @param value the new name */ void setName( const QString &value ); /** * @brief A short description of the feature. * * HTML markup is not supported. * @TODO When the Snippet is not supplied, the first lines of description should be used. * @return The name of this feature */ GeoDataSnippet snippet() const; /** * @brief Set a new name for this feature * @param value the new name */ void setSnippet( const GeoDataSnippet &value ); /// Return the address of the feature QString address() const; /// Set the address of this feature to @p value. void setAddress( const QString &value); /// Return the phone number of the feature QString phoneNumber() const; /// Set the phone number of this feature to @p value. void setPhoneNumber( const QString &value ); /// Return the text description of the feature. QString description() const; /// Set the description of this feature to @p value. void setDescription( const QString &value ); /** * @brief test if the description is CDATA or not * CDATA allows for special characters to be included in XML and also allows * for other XML formats to be embedded in the XML without interfering with * parser namespace. * @return @true if the description should be treated as CDATA * @false if the description is a plain string */ bool descriptionIsCDATA() const; /// Set the description to be CDATA See: @see descriptionIsCDATA() void setDescriptionCDATA( bool cdata ); /// Get the Abstract view of the feature const GeoDataAbstractView *abstractView() const; GeoDataAbstractView *abstractView(); /// Set the abstract view of the feature void setAbstractView( GeoDataAbstractView *abstractView ); /// Return the styleUrl of the feature. QString styleUrl() const; /// Set the styleUrl of this feature to @p value. void setStyleUrl( const QString &value ); /// Return whether this feature is visible or not bool isVisible() const; /// Return whether this feature is visible or not in the context of its parenting bool isGloballyVisible() const; /** * @brief Set a new value for visibility * @param value new value for the visibility * * This function sets the visibility, i.e. whether this feature * should be shown or not. This can be changed either from a GUI * or through some action of the program. */ void setVisible( bool value ); /** * Return the timespan of the feature. */ const GeoDataTimeSpan& timeSpan() const; GeoDataTimeSpan& timeSpan(); /** * Set the timespan of the feature. * @param timeSpan new of timespan. */ void setTimeSpan( const GeoDataTimeSpan &timeSpan ); /** * Return the timestamp of the feature. */ const GeoDataTimeStamp& timeStamp() const; GeoDataTimeStamp& timeStamp(); /** * Set the timestamp of the feature. * @param timeStamp new of the timestamp. */ void setTimeStamp( const GeoDataTimeStamp &timeStamp ); /** * Return the style assigned to the placemark, or a default style if none has been set */ QSharedPointer style() const; /** * Return the style assigned to the placemark with setStyle (can be 0) */ QSharedPointer customStyle() const; /** * Sets the style of the placemark. * @param style the new style to be used. */ void setStyle( const QSharedPointer &style ); /** * Return the ExtendedData assigned to the feature. */ GeoDataExtendedData& extendedData(); const GeoDataExtendedData& extendedData() const; /** * Sets the ExtendedData of the feature. * @param extendedData the new ExtendedData to be used. */ void setExtendedData( const GeoDataExtendedData& extendedData ); /** * Return the region assigned to the placemark. */ const GeoDataRegion& region() const; GeoDataRegion& region(); /** * @brief Sets the region of the placemark. * @param region new value for the region * * The feature is only shown when the region if active. */ void setRegion( const GeoDataRegion& region ); /** * Return the role of the placemark. * * FIXME: describe roles here! */ const QString role() const; /** * Sets the role of the placemark. * @param role the new role to be used. */ void setRole( const QString &role ); /** * @brief Return the popularity index of the placemark. * * The popularity index is a value which describes at which zoom * level the placemark will be shown. */ int zoomLevel() const; /** * Sets the popularity @p index of the placemark. * @param index the new index to be used. */ void setZoomLevel( int index ); /** * Return the popularity of the feature. */ qint64 popularity() const; /** * Sets the @p popularity of the feature. * @param popularity the new popularity value */ void setPopularity( qint64 popularity ); /** * Return a pointer to a GeoDataStyleMap object which represents the styleMap * of this feature. A styleMap is simply a QMap which can connect * two styles with a keyword. This can be used to have a highlighted and a * normal style. * @see GeoDataStyleMap */ const GeoDataStyleMap* styleMap() const; /** * Sets the styleMap of the feature */ void setStyleMap( const GeoDataStyleMap* map ); /// Duplicate into another equal instance - virtual GeoDataFeature * clone() const; + virtual GeoDataFeature * clone() const = 0; /// Serialize the contents of the feature to @p stream. void pack( QDataStream& stream ) const override; /// Unserialize the contents of the feature from @p stream. void unpack( QDataStream& stream ) override; protected: // the d-pointer needs to be protected to be accessible from derived classes GeoDataFeaturePrivate* const d_ptr; explicit GeoDataFeature(GeoDataFeaturePrivate* dd); GeoDataFeature(const GeoDataFeature& other, GeoDataFeaturePrivate* dd); bool equals( const GeoDataFeature &other ) const; using GeoDataObject::equals; private: Q_DECLARE_PRIVATE(GeoDataFeature) }; } #endif diff --git a/src/lib/marble/geodata/data/GeoDataOverlay.cpp b/src/lib/marble/geodata/data/GeoDataOverlay.cpp index bdd80ec72..0f89cfcf8 100644 --- a/src/lib/marble/geodata/data/GeoDataOverlay.cpp +++ b/src/lib/marble/geodata/data/GeoDataOverlay.cpp @@ -1,127 +1,122 @@ // // 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 Dennis Nienhüser // #include "GeoDataOverlay.h" #include "GeoDataOverlay_p.h" namespace Marble { GeoDataOverlay::GeoDataOverlay() : GeoDataFeature(new GeoDataOverlayPrivate) { // nothing to do } GeoDataOverlay::GeoDataOverlay(const GeoDataOverlay &other) : GeoDataFeature(other, new GeoDataOverlayPrivate(*other.d_func())) { // nothing to do } GeoDataOverlay::GeoDataOverlay(GeoDataOverlayPrivate *priv) : GeoDataFeature(priv) { } GeoDataOverlay::GeoDataOverlay(const GeoDataOverlay& other, GeoDataOverlayPrivate *priv) : GeoDataFeature(other, priv) { } GeoDataOverlay::~GeoDataOverlay() { } GeoDataOverlay &GeoDataOverlay::operator=( const GeoDataOverlay &other ) { if (this != &other) { Q_D(GeoDataOverlay); *d = *other.d_func(); } return *this; } -GeoDataFeature * GeoDataOverlay::clone() const -{ - return new GeoDataOverlay(*this); -} - QColor GeoDataOverlay::color() const { Q_D(const GeoDataOverlay); return d->m_color; } void GeoDataOverlay::setColor( const QColor &color ) { Q_D(GeoDataOverlay); d->m_color = color; } int GeoDataOverlay::drawOrder() const { Q_D(const GeoDataOverlay); return d->m_drawOrder; } void GeoDataOverlay::setDrawOrder( int order ) { Q_D(GeoDataOverlay); d->m_drawOrder = order; } QImage GeoDataOverlay::icon() const { Q_D(const GeoDataOverlay); if ( d->m_image.isNull() && !d->m_iconPath.isEmpty() ) { d->m_image = QImage( absoluteIconFile() ); } return d->m_image; } void GeoDataOverlay::setIcon( const QImage &icon ) { Q_D(GeoDataOverlay); d->m_image = icon; } void GeoDataOverlay::setIconFile( const QString &path ) { Q_D(GeoDataOverlay); d->m_iconPath = path; d->m_image = QImage( path ); } QString GeoDataOverlay::iconFile() const { Q_D(const GeoDataOverlay); return d->m_iconPath; } QString GeoDataOverlay::absoluteIconFile() const { Q_D(const GeoDataOverlay); return resolvePath( d->m_iconPath ); } bool GeoDataOverlay::equals(const GeoDataOverlay& other) const { Q_D(const GeoDataOverlay); const GeoDataOverlayPrivate* const other_d = other.d_func(); return GeoDataFeature::equals(other) && d->m_drawOrder == other_d->m_drawOrder && d->m_color == other_d->m_color && d->m_iconPath == other_d->m_iconPath && d->m_image == other_d->m_image; } } diff --git a/src/lib/marble/geodata/data/GeoDataOverlay.h b/src/lib/marble/geodata/data/GeoDataOverlay.h index 353dc9bbe..a415552cd 100644 --- a/src/lib/marble/geodata/data/GeoDataOverlay.h +++ b/src/lib/marble/geodata/data/GeoDataOverlay.h @@ -1,78 +1,76 @@ // // 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 Dennis Nienhüser // #ifndef MARBLE_GEODATAOVERLAY_H #define MARBLE_GEODATAOVERLAY_H #include "geodata_export.h" #include "GeoDataFeature.h" class QColor; class QImage; namespace Marble { class GeoDataOverlayPrivate; /** */ class GEODATA_EXPORT GeoDataOverlay: public GeoDataFeature { public: /** Constructor */ GeoDataOverlay(); ~GeoDataOverlay() override; GeoDataOverlay( const GeoDataOverlay &other ); GeoDataOverlay& operator=( const GeoDataOverlay &other ); - GeoDataFeature * clone() const override; - QColor color() const; void setColor( const QColor &color ); int drawOrder() const; void setDrawOrder( int order ); QImage icon() const; void setIcon( const QImage &icon ); void setIconFile( const QString &path ); QString iconFile() const; /** * Returns the #iconFile as an absolute filename. Relative files are * resolved relative to the directory of the GeoDataDocument this overlay * is part of (see #fileName of #GeoDataDocument) */ QString absoluteIconFile() const; protected: explicit GeoDataOverlay(GeoDataOverlayPrivate *priv); GeoDataOverlay(const GeoDataOverlay& other, GeoDataOverlayPrivate *priv); bool equals(const GeoDataOverlay &other) const; using GeoDataFeature::equals; private: Q_DECLARE_PRIVATE(GeoDataOverlay) }; } #endif diff --git a/src/lib/marble/geodata/parser/GeoDataTypes.cpp b/src/lib/marble/geodata/parser/GeoDataTypes.cpp index b5574810b..7e3f3c9b9 100644 --- a/src/lib/marble/geodata/parser/GeoDataTypes.cpp +++ b/src/lib/marble/geodata/parser/GeoDataTypes.cpp @@ -1,100 +1,98 @@ /* Copyright (C) 2008 Jens-Michael Hoffmann This file is part of the KDE project This library is free software you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License aint with this library see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "GeoDataTypes.h" namespace Marble { namespace GeoDataTypes { const char GeoDataAnimatedUpdateType[] = "GeoDataAnimatedUpdate"; const char GeoDataAliasType[] = "GeoDataAlias"; const char GeoDataCameraType[] = "GeoDataCamera"; const char GeoDataChangeType[] = "GeoDataChange"; const char GeoDataColorStyleType[] = "GeoDataColorStyle"; -const char GeoDataContainerType[] = "GeoDataContainer"; const char GeoDataCreateType[] = "GeoDataCreate"; const char GeoDataDataType[] = "GeoDataData"; const char GeoDataDeleteType[] = "GeoDataDelete"; const char GeoDataDocumentType[] = "GeoDataDocument"; const char GeoDataExtendedDataType[] = "GeoDataExtendedData"; -const char GeoDataFeatureType[] = "GeoDataFeature"; const char GeoDataFlyToType[] = "GeoDataFlyTo"; const char GeoDataFolderType[] = "GeoDataFolder"; const char GeoDataGeometryType[] = "GeoDataGeometry"; const char GeoDataGroundOverlayType[] = "GeoDataGroundOverlay"; const char GeoDataHotspotType[] = "GeoDataHotspot"; const char GeoDataIconStyleType[] = "GeoDataIconStyle"; const char GeoDataInnerBoundaryType[] = "GeoDataInnerBoundary"; const char GeoDataLabelStyleType[] = "GeoDataLabelStyle"; const char GeoDataLatLonAltBoxType[] = "GeoDataLatLonAlt"; const char GeoDataLatLonBoxType[] = "GeoDataLatLonBox"; const char GeoDataLatLonQuadType[] = "GeoDataLatLonQuad"; const char GeoDataLinearRingType[] = "GeoDataLinearRing"; const char GeoDataLineStringType[] = "GeoDataLineString"; const char GeoDataLineStyleType[] = "GeoDataLineStyle"; const char GeoDataLinkType[] = "GeoDataLink"; const char GeoDataLocationType[] = "GeoDataLocation"; const char GeoDataLodType[] = "GeoDataLod"; const char GeoDataLookAtType[] = "GeoDataLookAt"; const char GeoDataModelType[] = "GeoDataModel"; const char GeoDataMultiGeometryType[] = "GeoDataMultiGeometry"; const char GeoDataMultiTrackType[] = "GeoDataMultiTrack"; const char GeoDataNetworkLinkType[] = "GeoDataNetworkLink"; const char GeoDataOrientationType[] = "GeoDataOrientation"; const char GeoDataOuterBoundaryType[] = "GeoDataOuterBoundary"; const char GeoDataPhotoOverlayType[] = "GeoDataPhotoOverlay"; const char GeoDataPlacemarkType[] = "GeoDataPlacemark"; const char GeoDataPlaylistType[] = "GeoDataPlaylist"; const char GeoDataPointType[] = "GeoDataPoint"; const char GeoDataPolygonType[] = "GeoDataPolygon"; const char GeoDataPolyStyleType[] = "GeoDataPolyStyle"; const char GeoDataRegionType[] = "GeoDataRegion"; const char GeoDataRelationType[] = "GeoDataRelationType"; const char GeoDataResourceMapType[] = "GeoDataResourceMap"; const char GeoDataSchemaType[] = "GeoDataSchema"; const char GeoDataSchemaDataType[] = "GeoDataSchemaData"; const char GeoDataSimpleDataType[] = "GeoDataSimpleData"; const char GeoDataSimpleFieldType[] = "GeoDataSimpleField"; const char GeoDataSimpleArrayDataType[] = "GeoDataSimpleArrayData"; const char GeoDataStyleType[] = "GeoDataStyle"; const char GeoDataStyleMapType[] = "GeoDataStyleMap"; const char GeoDataSoundCueType[] = "GeoDataSoundCue"; const char GeoDataTimePrimitiveType[] = "GeoDataTimePrimitive"; const char GeoDataTimeSpanType[] = "GeoDataTimeSpan"; const char GeoDataTimeStampType[] = "GeoDataTimeStamp"; const char GeoDataTourType[] = "GeoDataTour"; const char GeoDataTourControlType[] = "GeoDataTourControl"; const char GeoDataWaitType[] = "GeoDataWait"; const char GeoDataTrackType[] = "GeoDataTrack"; const char GeoDataScaleType[] = "GeoDataScale"; const char GeoDataScreenOverlayType[] = "GeoDataScreenOverlay"; const char GeoDataBalloonStyleType[] = "GeoDataBalloonStyle"; const char GeoDataListStyleType[] = "GeoDataListStyle"; const char GeoDataItemIconType[] = "GeoDataItemIcon"; const char GeoDataImagePyramidType[] = "GeoDataImagePyramid"; const char GeoDataViewVolumeType[] = "GeoDataViewVolume"; const char GeoDataNetworkLinkControlType[] = "GeoDataNetworkLinkControl"; const char GeoDataUpdateType[] = "GeoDataUpdate"; } } diff --git a/src/lib/marble/geodata/parser/GeoDataTypes.h b/src/lib/marble/geodata/parser/GeoDataTypes.h index ef26a9a0c..568e139b9 100644 --- a/src/lib/marble/geodata/parser/GeoDataTypes.h +++ b/src/lib/marble/geodata/parser/GeoDataTypes.h @@ -1,111 +1,109 @@ /* Copyright (C) 2008 Nikolas Zimmermann Copyright (C) 2008 Jens-Michael Hoffmann This file is part of the KDE project This library is free software you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License aint with this library see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef MARBLE_GEODATATYPES_H #define MARBLE_GEODATATYPES_H #include "geodata_export.h" namespace Marble { namespace GeoDataTypes { /** * the following const char* XXType are used to provide RTTI to the GeoData for * downcasting to the good object * please keep alphabetic order to prevent mess */ GEODATA_EXPORT extern const char GeoDataAliasType[]; GEODATA_EXPORT extern const char GeoDataAnimatedUpdateType[]; GEODATA_EXPORT extern const char GeoDataCameraType[]; GEODATA_EXPORT extern const char GeoDataChangeType[]; GEODATA_EXPORT extern const char GeoDataColorStyleType[]; -GEODATA_EXPORT extern const char GeoDataContainerType[]; GEODATA_EXPORT extern const char GeoDataCreateType[]; GEODATA_EXPORT extern const char GeoDataDataType[]; GEODATA_EXPORT extern const char GeoDataDeleteType[]; GEODATA_EXPORT extern const char GeoDataDocumentType[]; GEODATA_EXPORT extern const char GeoDataExtendedDataType[]; -GEODATA_EXPORT extern const char GeoDataFeatureType[]; GEODATA_EXPORT extern const char GeoDataFlyToType[]; GEODATA_EXPORT extern const char GeoDataFolderType[]; GEODATA_EXPORT extern const char GeoDataGeometryType[]; GEODATA_EXPORT extern const char GeoDataGroundOverlayType[]; GEODATA_EXPORT extern const char GeoDataHotspotType[]; GEODATA_EXPORT extern const char GeoDataIconStyleType[]; GEODATA_EXPORT extern const char GeoDataInnerBoundaryType[]; GEODATA_EXPORT extern const char GeoDataLabelStyleType[]; GEODATA_EXPORT extern const char GeoDataLatLonAltBoxType[]; GEODATA_EXPORT extern const char GeoDataLatLonBoxType[]; GEODATA_EXPORT extern const char GeoDataLatLonQuadType[]; GEODATA_EXPORT extern const char GeoDataLinearRingType[]; GEODATA_EXPORT extern const char GeoDataLineStringType[]; GEODATA_EXPORT extern const char GeoDataLineStyleType[]; GEODATA_EXPORT extern const char GeoDataLinkType[]; GEODATA_EXPORT extern const char GeoDataLocationType[]; GEODATA_EXPORT extern const char GeoDataLodType[]; GEODATA_EXPORT extern const char GeoDataLookAtType[]; GEODATA_EXPORT extern const char GeoDataModelType[]; GEODATA_EXPORT extern const char GeoDataMultiGeometryType[]; GEODATA_EXPORT extern const char GeoDataMultiTrackType[]; GEODATA_EXPORT extern const char GeoDataNetworkLinkType[]; GEODATA_EXPORT extern const char GeoDataOrientationType[]; GEODATA_EXPORT extern const char GeoDataOuterBoundaryType[]; GEODATA_EXPORT extern const char GeoDataPhotoOverlayType[]; GEODATA_EXPORT extern const char GeoDataPlacemarkType[]; GEODATA_EXPORT extern const char GeoDataPlaylistType[]; GEODATA_EXPORT extern const char GeoDataPointType[]; GEODATA_EXPORT extern const char GeoDataPolygonType[]; GEODATA_EXPORT extern const char GeoDataPolyStyleType[]; GEODATA_EXPORT extern const char GeoDataRegionType[]; GEODATA_EXPORT extern const char GeoDataRelationType[]; GEODATA_EXPORT extern const char GeoDataResourceMapType[]; GEODATA_EXPORT extern const char GeoDataSchemaType[]; GEODATA_EXPORT extern const char GeoDataSchemaDataType[]; GEODATA_EXPORT extern const char GeoDataSimpleDataType[]; GEODATA_EXPORT extern const char GeoDataSimpleFieldType[]; GEODATA_EXPORT extern const char GeoDataSimpleArrayDataType[]; GEODATA_EXPORT extern const char GeoDataStyleType[]; GEODATA_EXPORT extern const char GeoDataStyleMapType[]; GEODATA_EXPORT extern const char GeoDataSoundCueType[]; GEODATA_EXPORT extern const char GeoDataTimePrimitiveType[]; GEODATA_EXPORT extern const char GeoDataTimeStampType[]; GEODATA_EXPORT extern const char GeoDataTimeSpanType[]; GEODATA_EXPORT extern const char GeoDataTourType[]; GEODATA_EXPORT extern const char GeoDataTourControlType[]; GEODATA_EXPORT extern const char GeoDataWaitType[]; GEODATA_EXPORT extern const char GeoDataTrackType[]; GEODATA_EXPORT extern const char GeoDataScaleType[]; GEODATA_EXPORT extern const char GeoDataScreenOverlayType[]; GEODATA_EXPORT extern const char GeoDataBalloonStyleType[]; GEODATA_EXPORT extern const char GeoDataListStyleType[]; GEODATA_EXPORT extern const char GeoDataItemIconType[]; GEODATA_EXPORT extern const char GeoDataImagePyramidType[]; GEODATA_EXPORT extern const char GeoDataViewVolumeType[]; GEODATA_EXPORT extern const char GeoDataNetworkLinkControlType[]; GEODATA_EXPORT extern const char GeoDataUpdateType[]; } } #endif diff --git a/tests/TestFeatureDetach.cpp b/tests/TestFeatureDetach.cpp index 8ba2870fc..ba0d44989 100644 --- a/tests/TestFeatureDetach.cpp +++ b/tests/TestFeatureDetach.cpp @@ -1,154 +1,155 @@ // // 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 Calin Cruceru // #include #include "GeoDataContainer.h" #include "GeoDataPoint.h" #include "GeoDataPlacemark.h" +#include "GeoDataRelation.h" #include "GeoDataCamera.h" #include "MarbleGlobal.h" #include "GeoDataPlaylist.h" #include "GeoDataTour.h" #include "TestUtils.h" namespace Marble { class TestFeatureDetach : public QObject { Q_OBJECT private Q_SLOTS: /** * FIXME: Doesn't work for the moment because calling detach() in * GeoDataFeature::set/abstractView() doesn't help because the object * isn't deep-copied in the private class. * - * @brief testFeature shows that getting the abstractView() of a copied + * @brief testRelation shows that getting the abstractView() of a copied * feature and modifying it doesn't modify the original one. */ - void testFeature(); + void testRelation(); /** - * @brief testContainer shows that getting some child and modifying it, + * @brief testDocument shows that getting some child and modifying it, * doesn't modify the child at the same position in the original container. */ - void testContainer(); + void testDocument(); /** * @brief testPlacemark shows that getting the geometry() and modifying it * doesn't modify the geometry of the original placemark. */ void testPlacemark(); /** * @brief testTour shows that modifying the playlist of a copied tour doesn't * modify the playlist of the original one. */ void testTour(); /** * @brief testGeometryParentInPlacemark shows that copying a placemark correctly * keeps the geometries of both the copied one and the original one pointing to its * parent. Before the changes made in GeoDataPlacemark (calling setParent() after * each detach() call and not calling anymore in the * GeoDataPlacemark( const GeoDataGeometry &other ) constructor), after the operation * highlighted in this test, the geometry of the first one (the original one) ended * pointing (its parent) to the second placemark and the second one had its geometry's * parent a null pointer. */ void testGeometryParentInPlacemark(); }; -void TestFeatureDetach::testFeature() +void TestFeatureDetach::testRelation() { - GeoDataFeature feat1; + GeoDataRelation feat1; GeoDataCamera *view1 = new GeoDataCamera(); view1->setAltitudeMode(Absolute); feat1.setAbstractView(view1); - GeoDataFeature feat2 = feat1; + GeoDataRelation feat2 = feat1; feat2.abstractView()->setAltitudeMode(ClampToSeaFloor); // FIXME: See above (method description). // QVERIFY(feat1.abstractView()->altitudeMode() == Absolute); } -void TestFeatureDetach::testContainer() +void TestFeatureDetach::testDocument() { - GeoDataContainer cont1; - GeoDataFeature *feat1 = new GeoDataFeature(); + GeoDataDocument cont1; + GeoDataFeature *feat1 = new GeoDataPlacemark(); feat1->setName("Feat1"); cont1.insert(0, feat1); - GeoDataContainer cont2 = cont1; + GeoDataDocument cont2 = cont1; cont2.child(0)->setName("Feat2"); QCOMPARE(cont1.child(0)->name(), QLatin1String("Feat1")); - const GeoDataContainer cont3 = cont1; + const GeoDataDocument cont3 = cont1; QCOMPARE(cont3.child(0)->name(), QLatin1String("Feat1")); } void TestFeatureDetach::testPlacemark() { GeoDataCoordinates coords1(30, 30, 0, GeoDataCoordinates::Degree); GeoDataPlacemark place1; place1.setCoordinate(coords1); GeoDataPlacemark place2 = place1; GeoDataCoordinates coords2(60, 60, 0, GeoDataCoordinates::Degree); GeoDataPoint *point = static_cast( place2.geometry() ); point->setCoordinates(coords2); QVERIFY(place1.coordinate() == coords1); const GeoDataPlacemark place3 = place1; QVERIFY(place3.coordinate() == coords1); } void TestFeatureDetach::testTour() { GeoDataPlaylist *newPlaylist = new GeoDataPlaylist; newPlaylist->setId("Playlist1"); GeoDataTour tour1; tour1.setPlaylist(newPlaylist); GeoDataTour tour2 = tour1; tour2.playlist()->setId("Playlist2"); QCOMPARE(tour1.playlist()->id(), QLatin1String("Playlist1")); const GeoDataTour tour3 = tour1; QCOMPARE(tour3.playlist()->id(), QLatin1String("Playlist1")); } void TestFeatureDetach::testGeometryParentInPlacemark() { GeoDataPlacemark place1; QVERIFY(place1.geometry()->parent() == &place1); GeoDataPlacemark place2 = place1; // With the changes (regarding setParent() multiple calls after each // detach() call) the only moment when some invariant is broken is right now, // after the copy constructor has been called and no other method (which calls // detach()) hasn't. This is because the geometry is not immediately copied, // so the geometry of place2 has as parent place1. This is immediately solved // when calling geometry() below. QVERIFY(place2.geometry()->parent() == &place2); QVERIFY(place1.geometry()->parent() == &place1); } } QTEST_MAIN( Marble::TestFeatureDetach ) #include "TestFeatureDetach.moc"