diff --git a/src/lib/marble/geodata/data/GeoDataContainer.cpp b/src/lib/marble/geodata/data/GeoDataContainer.cpp index bb0b3c80a..8c2c20704 100644 --- a/src/lib/marble/geodata/data/GeoDataContainer.cpp +++ b/src/lib/marble/geodata/data/GeoDataContainer.cpp @@ -1,475 +1,512 @@ // // 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 ) { } GeoDataContainer::GeoDataContainer( const GeoDataContainer& other ) : GeoDataFeature( other ) { } GeoDataContainer::~GeoDataContainer() { } -GeoDataContainerPrivate* GeoDataContainer::p() -{ - return static_cast(d); -} - -const GeoDataContainerPrivate* GeoDataContainer::p() const -{ - return static_cast(d); -} - bool GeoDataContainer::equals( const GeoDataContainer &other ) const { if ( !GeoDataFeature::equals(other) ) { return false; } - QVector::const_iterator thisBegin = p()->m_vector.constBegin(); - QVector::const_iterator thisEnd = p()->m_vector.constEnd(); - QVector::const_iterator otherBegin = other.p()->m_vector.constBegin(); - QVector::const_iterator otherEnd = other.p()->m_vector.constEnd(); + 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; } GeoDataLatLonAltBox GeoDataContainer::latLonAltBox() const { + Q_D(const GeoDataContainer); GeoDataLatLonAltBox result; - QVector::const_iterator it = p()->m_vector.constBegin(); - QVector::const_iterator end = p()->m_vector.constEnd(); + 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 = p()->m_vector.constBegin(); - QVector::const_iterator end = p()->m_vector.constEnd(); + 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=p()->m_vector.constBegin(), end = p()->m_vector.constEnd(); it != end; ++it) { + 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 { - return p()->m_vector; + Q_D(const GeoDataContainer); + return d->m_vector; } /** * @brief returns the requested child item */ GeoDataFeature* GeoDataContainer::child( int i ) { detach(); - return p()->m_vector.at(i); + + Q_D(GeoDataContainer); + return d->m_vector.at(i); } const GeoDataFeature* GeoDataContainer::child( int i ) const { - return p()->m_vector.at(i); + 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 { - for ( int i=0; i< p()->m_vector.size(); i++ ) - { - if ( p()->m_vector.at( i ) == object ) - { + 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 ) { detach(); + + Q_D(GeoDataContainer); feature->setParent(this); - p()->m_vector.insert( index, feature ); + d->m_vector.insert( index, feature ); } void GeoDataContainer::append( GeoDataFeature *other ) { detach(); + + Q_D(GeoDataContainer); other->setParent(this); - p()->m_vector.append( other ); + d->m_vector.append( other ); } void GeoDataContainer::remove( int index ) { detach(); - p()->m_vector.remove( index ); + + Q_D(GeoDataContainer); + d->m_vector.remove( index ); } void GeoDataContainer::remove(int index, int count) { detach(); - p()->m_vector.remove( index, count ); + + Q_D(GeoDataContainer); + d->m_vector.remove( index, count ); } int GeoDataContainer::removeAll(GeoDataFeature *feature) { detach(); + + Q_D(GeoDataContainer); #if QT_VERSION >= 0x050400 - return p()->m_vector.removeAll(feature); + return d->m_vector.removeAll(feature); #else int count = 0; - QVector &vector = p()->m_vector; + 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) { detach(); - p()->m_vector.removeAt( index ); + + Q_D(GeoDataContainer); + d->m_vector.removeAt( index ); } void GeoDataContainer::removeFirst() { detach(); - p()->m_vector.removeFirst(); + + Q_D(GeoDataContainer); + d->m_vector.removeFirst(); } void GeoDataContainer::removeLast() { detach(); - p()->m_vector.removeLast(); + + Q_D(GeoDataContainer); + d->m_vector.removeLast(); } bool GeoDataContainer::removeOne( GeoDataFeature *feature ) { detach(); + + Q_D(GeoDataContainer); #if QT_VERSION >= 0x050400 - return p()->m_vector.removeOne( feature ); + return d->m_vector.removeOne( feature ); #else - QVector &vector = p()->m_vector; + 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 { - return p()->m_vector.size(); + Q_D(const GeoDataContainer); + return d->m_vector.size(); } GeoDataFeature& GeoDataContainer::at( int pos ) { detach(); - return *(p()->m_vector[ pos ]); + + Q_D(GeoDataContainer); + return *(d->m_vector[pos]); } const GeoDataFeature& GeoDataContainer::at( int pos ) const { - return *(p()->m_vector.at( pos )); + Q_D(const GeoDataContainer); + return *(d->m_vector.at(pos)); } GeoDataFeature& GeoDataContainer::last() { detach(); - return *(p()->m_vector.last()); + + Q_D(GeoDataContainer); + return *(d->m_vector.last()); } const GeoDataFeature& GeoDataContainer::last() const { - return *(p()->m_vector.last()); + Q_D(const GeoDataContainer); + return *(d->m_vector.last()); } GeoDataFeature& GeoDataContainer::first() { detach(); - return *(p()->m_vector.first()); + + Q_D(GeoDataContainer); + return *(d->m_vector.first()); } const GeoDataFeature& GeoDataContainer::first() const { - return *(p()->m_vector.first()); + Q_D(const GeoDataContainer); + return *(d->m_vector.first()); } void GeoDataContainer::clear() { GeoDataContainer::detach(); - qDeleteAll(p()->m_vector); - p()->m_vector.clear(); + + Q_D(GeoDataContainer); + qDeleteAll(d->m_vector); + d->m_vector.clear(); } QVector::Iterator GeoDataContainer::begin() { detach(); - return p()->m_vector.begin(); + + Q_D(GeoDataContainer); + return d->m_vector.begin(); } QVector::Iterator GeoDataContainer::end() { detach(); - return p()->m_vector.end(); + + Q_D(GeoDataContainer); + return d->m_vector.end(); } QVector::ConstIterator GeoDataContainer::constBegin() const { - return p()->m_vector.constBegin(); + Q_D(const GeoDataContainer); + return d->m_vector.constBegin(); } QVector::ConstIterator GeoDataContainer::constEnd() const { - return p()->m_vector.constEnd(); + Q_D(const GeoDataContainer); + return d->m_vector.constEnd(); } void GeoDataContainer::pack( QDataStream& stream ) const { + Q_D(const GeoDataContainer); GeoDataFeature::pack( stream ); - stream << p()->m_vector.count(); + stream << d->m_vector.count(); - for ( QVector ::const_iterator iterator = p()->m_vector.constBegin(); - iterator != p()->m_vector.constEnd(); + 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 ) { detach(); + + 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 ); - p()->m_vector.append( folder ); + d->m_vector.append( folder ); } break; case GeoDataPlacemarkId: { GeoDataPlacemark *placemark = new GeoDataPlacemark; placemark->unpack( stream ); - p()->m_vector.append( placemark ); + 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 81a4485ee..e03cb43cc 100644 --- a/src/lib/marble/geodata/data/GeoDataContainer.h +++ b/src/lib/marble/geodata/data/GeoDataContainer.h @@ -1,183 +1,182 @@ // // 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 virtual ~GeoDataContainer(); /** * @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 */ virtual void pack( QDataStream& stream ) const; /** * @brief Unserialize the container from a stream * @param stream the stream */ virtual void unpack( QDataStream& stream ); protected: explicit GeoDataContainer( GeoDataContainerPrivate *priv ); bool equals( const GeoDataContainer &other ) const; using GeoDataFeature::equals; private: - GeoDataContainerPrivate* p(); - const GeoDataContainerPrivate* p() const; + Q_DECLARE_PRIVATE(GeoDataContainer) }; } #endif diff --git a/src/lib/marble/geodata/data/GeoDataDocument.cpp b/src/lib/marble/geodata/data/GeoDataDocument.cpp index 09570cce4..a6f903534 100644 --- a/src/lib/marble/geodata/data/GeoDataDocument.cpp +++ b/src/lib/marble/geodata/data/GeoDataDocument.cpp @@ -1,285 +1,324 @@ /* Copyright (C) 2007 Murad Tagirov Copyright (C) 2007 Nikolas Zimmermann 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 "GeoDataDocument.h" #include "GeoDataDocument_p.h" #include "GeoDataFolder.h" #include "GeoDataPlacemark.h" #include "GeoDataStyle.h" #include "GeoDataStyleMap.h" #include "GeoDataNetworkLinkControl.h" #include "GeoDataSchema.h" #include "MarbleDebug.h" #include namespace Marble { GeoDataDocument::GeoDataDocument() : GeoDataContainer( new GeoDataDocumentPrivate ) { } GeoDataDocument::GeoDataDocument( const GeoDataDocument& other ) : GeoDocument(), GeoDataContainer( other ) { } GeoDataDocument::~GeoDataDocument() { } -GeoDataDocumentPrivate* GeoDataDocument::p() -{ - return static_cast(d); -} - -const GeoDataDocumentPrivate* GeoDataDocument::p() const -{ - return static_cast(d); -} - bool GeoDataDocument::operator==( const GeoDataDocument &other ) const { if (!GeoDataContainer::equals(other)) { return false; } - if (!(p()->m_styleHash.size() == other.p()->m_styleHash.size() && - p()->m_styleMapHash == other.p()->m_styleMapHash && - p()->m_schemaHash == other.p()->m_schemaHash && - p()->m_filename == other.p()->m_filename && - p()->m_baseUri == other.p()->m_baseUri && - p()->m_networkLinkControl == other.p()->m_networkLinkControl && - p()->m_property == other.p()->m_property && - p()->m_documentRole == other.p()->m_documentRole)) { + Q_D(const GeoDataDocument); + const GeoDataDocumentPrivate* const other_d = other.d_func(); + if (!(d->m_styleHash.size() == other_d->m_styleHash.size() && + d->m_styleMapHash == other_d->m_styleMapHash && + d->m_schemaHash == other_d->m_schemaHash && + d->m_filename == other_d->m_filename && + d->m_baseUri == other_d->m_baseUri && + d->m_networkLinkControl == other_d->m_networkLinkControl && + d->m_property == other_d->m_property && + d->m_documentRole == other_d->m_documentRole)) { return false; } - auto iter = p()->m_styleHash.constBegin(); - auto const end = p()->m_styleHash.constEnd(); + auto iter = d->m_styleHash.constBegin(); + auto const end = d->m_styleHash.constEnd(); for (; iter != end; ++iter) { - if (!other.p()->m_styleHash.contains(iter.key())) { + if (!other_d->m_styleHash.contains(iter.key())) { return false; } - if (*iter.value() != *other.p()->m_styleHash[iter.key()]) { + if (*iter.value() != *other_d->m_styleHash[iter.key()]) { return false; } } return true; } bool GeoDataDocument::operator!=( const GeoDataDocument &other ) const { return !this->operator==( other ); } DocumentRole GeoDataDocument::documentRole() const { - return p()->m_documentRole; + Q_D(const GeoDataDocument); + return d->m_documentRole; } void GeoDataDocument::setDocumentRole( DocumentRole role ) { - p()->m_documentRole = role; + detach(); + + Q_D(GeoDataDocument); + d->m_documentRole = role; } QString GeoDataDocument::property() const { - return p()->m_property; + Q_D(const GeoDataDocument); + return d->m_property; } void GeoDataDocument::setProperty( const QString& property ) { - p()->m_property = property; + detach(); + + Q_D(GeoDataDocument); + d->m_property = property; } QString GeoDataDocument::fileName() const { - return p()->m_filename; + Q_D(const GeoDataDocument); + return d->m_filename; } void GeoDataDocument::setFileName( const QString &value ) { detach(); - p()->m_filename = value; + + Q_D(GeoDataDocument); + d->m_filename = value; } QString GeoDataDocument::baseUri() const { - return p()->m_baseUri; + Q_D(const GeoDataDocument); + return d->m_baseUri; } void GeoDataDocument::setBaseUri( const QString &baseUrl ) { detach(); - p()->m_baseUri = baseUrl; + + Q_D(GeoDataDocument); + d->m_baseUri = baseUrl; } GeoDataNetworkLinkControl GeoDataDocument::networkLinkControl() const { - return p()->m_networkLinkControl; + Q_D(const GeoDataDocument); + return d->m_networkLinkControl; } void GeoDataDocument::setNetworkLinkControl( const GeoDataNetworkLinkControl &networkLinkControl ) { detach(); - p()->m_networkLinkControl = networkLinkControl; + + Q_D(GeoDataDocument); + d->m_networkLinkControl = networkLinkControl; } void GeoDataDocument::addStyle( const GeoDataStyle::Ptr &style ) { detach(); - p()->m_styleHash.insert( style->id(), style ); - p()->m_styleHash[ style->id() ]->setParent( this ); + + Q_D(GeoDataDocument); + d->m_styleHash.insert(style->id(), style); + d->m_styleHash[style->id()]->setParent(this); } void GeoDataDocument::removeStyle( const QString& styleId ) { detach(); - p()->m_styleHash.remove( styleId ); + + Q_D(GeoDataDocument); + d->m_styleHash.remove(styleId); } GeoDataStyle::Ptr GeoDataDocument::style( const QString& styleId ) { + detach(); /* * FIXME: m_styleHash always should contain at least default * GeoDataStyle element */ - return p()->m_styleHash[ styleId ]; + Q_D(GeoDataDocument); + return d->m_styleHash[styleId]; } GeoDataStyle::ConstPtr GeoDataDocument::style( const QString &styleId ) const { - return p()->m_styleHash.value( styleId ); + Q_D(const GeoDataDocument); + return d->m_styleHash.value(styleId); } QList GeoDataDocument::styles() const { + Q_D(const GeoDataDocument); QList result; - foreach(auto const & style, p()->m_styleHash.values()) { + foreach(auto const & style, d->m_styleHash.values()) { result << style; } return result; } QList GeoDataDocument::styles() { detach(); - return p()->m_styleHash.values(); + + Q_D(GeoDataDocument); + return d->m_styleHash.values(); } void GeoDataDocument::addStyleMap( const GeoDataStyleMap& map ) { detach(); - p()->m_styleMapHash.insert( map.id(), map ); - p()->m_styleMapHash[ map.id() ].setParent( this ); + + Q_D(GeoDataDocument); + d->m_styleMapHash.insert(map.id(), map); + d->m_styleMapHash[map.id()].setParent(this); } void GeoDataDocument::removeStyleMap( const QString& mapId ) { detach(); - p()->m_styleMapHash.remove( mapId ); + + Q_D(GeoDataDocument); + d->m_styleMapHash.remove(mapId); } GeoDataStyleMap& GeoDataDocument::styleMap( const QString& styleId ) { - return p()->m_styleMapHash[ styleId ]; + detach(); + + Q_D(GeoDataDocument); + return d->m_styleMapHash[styleId]; } GeoDataStyleMap GeoDataDocument::styleMap( const QString &styleId ) const { - return p()->m_styleMapHash.value( styleId ); + Q_D(const GeoDataDocument); + return d->m_styleMapHash.value(styleId); } QList GeoDataDocument::styleMaps() const { - return p()->m_styleMapHash.values(); + Q_D(const GeoDataDocument); + return d->m_styleMapHash.values(); } void GeoDataDocument::addSchema( const GeoDataSchema& schema ) { detach(); - p()->m_schemaHash.insert( schema.id(), schema ); - p()->m_schemaHash[ schema.id() ].setParent( this ); + + Q_D(GeoDataDocument); + d->m_schemaHash.insert(schema.id(), schema); + d->m_schemaHash[schema.id()].setParent(this); } void GeoDataDocument::removeSchema( const QString& schemaId ) { detach(); - GeoDataSchema schema = p()->m_schemaHash.take( schemaId ); + + Q_D(GeoDataDocument); + GeoDataSchema schema = d->m_schemaHash.take(schemaId); schema.setParent( 0 ); } GeoDataSchema GeoDataDocument::schema( const QString& schemaId ) const { - return p()->m_schemaHash.value( schemaId ); + Q_D(const GeoDataDocument); + return d->m_schemaHash.value(schemaId); } GeoDataSchema &GeoDataDocument::schema( const QString &schemaId ) { - return p()->m_schemaHash[ schemaId ]; + detach(); + + Q_D(GeoDataDocument); + return d->m_schemaHash[schemaId]; } QList GeoDataDocument::schemas() const { - return p()->m_schemaHash.values(); + Q_D(const GeoDataDocument); + return d->m_schemaHash.values(); } void GeoDataDocument::pack( QDataStream& stream ) const { + Q_D(const GeoDataDocument); GeoDataContainer::pack( stream ); - stream << p()->m_styleHash.size(); - - + stream << d->m_styleHash.size(); + for( QMap::const_iterator iterator - = p()->m_styleHash.constBegin(); - iterator != p()->m_styleHash.constEnd(); + = d->m_styleHash.constBegin(); + iterator != d->m_styleHash.constEnd(); ++iterator ) { iterator.value()->pack( stream ); } } void GeoDataDocument::unpack( QDataStream& stream ) { detach(); + + Q_D(GeoDataDocument); GeoDataContainer::unpack( stream ); int size = 0; stream >> size; for( int i = 0; i < size; i++ ) { GeoDataStyle::Ptr style; style->unpack( stream ); - p()->m_styleHash.insert( style->id(), style ); + d->m_styleHash.insert(style->id(), style); } } } diff --git a/src/lib/marble/geodata/data/GeoDataDocument.h b/src/lib/marble/geodata/data/GeoDataDocument.h index 374f9bbe1..3229496e6 100644 --- a/src/lib/marble/geodata/data/GeoDataDocument.h +++ b/src/lib/marble/geodata/data/GeoDataDocument.h @@ -1,205 +1,204 @@ /* Copyright (C) 2007, 2008 Nikolas Zimmermann Copyright (C) 2007 Murad Tagirov Copyright (C) 2009 Patrick Spendrin 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_GEODATADOCUMENT_H #define MARBLE_GEODATADOCUMENT_H #include #include "geodata_export.h" #include "GeoDataContainer.h" #include "GeoDocument.h" #include "GeoDataStyle.h" namespace Marble { enum DocumentRole { UnknownDocument, MapDocument, UserDocument, TrackingDocument, BookmarkDocument, SearchResultDocument, ConversionDocument }; class GeoDataStyleMap; class GeoDataNetworkLinkControl; class GeoDataSchema; class GeoDataDocumentPrivate; /** * @short A container for Features, Styles and in the future Schemas. * * A GeoDataDocument is a container for features, styles, and * schemas. This element is required if your KML file uses schemas or * shared styles. It is recommended that all Styles be defined in a * Document, each with an id, and then later referenced by a * styleUrl for a given Feature or StyleMap. */ class GEODATA_EXPORT GeoDataDocument : public GeoDocument, public GeoDataContainer { public: GeoDataDocument(); GeoDataDocument( const GeoDataDocument& other ); ~GeoDataDocument(); bool operator==( const GeoDataDocument &other ) const; bool operator!=( const GeoDataDocument &other ) const; /// Provides type information for downcasting a GeoData virtual bool isGeoDataDocument() const { return true; } DocumentRole documentRole() const; void setDocumentRole( DocumentRole role ); QString property() const; void setProperty( const QString& property ); /** * @brief The filename of the document * * The filename of the document is used internally to identify the files. * it should never be empty as this could lead to potential collisions. * * @return The filename of this document */ QString fileName() const; /** * @brief Set a new file name for this document * @param value the new name */ void setFileName( const QString &value ); /** * @brief The URI relative paths should be resolved against */ QString baseUri() const; /** * @brief Change the URI for resolving relative paths. * See http://tools.ietf.org/html/rfc3986#section-5 */ void setBaseUri( const QString &baseUri ); /** * @brief the NetworkLinkControl of the file */ GeoDataNetworkLinkControl networkLinkControl() const; /** * @brief set the NetworkLinkControl of the file */ void setNetworkLinkControl( const GeoDataNetworkLinkControl &networkLinkControl ); /** * @brief Add a style to the style storage * @param style the new style */ void addStyle(const GeoDataStyle::Ptr &style); /** * @brief Add a style to the style storage * @param style the new style */ void removeStyle( const QString& styleId ); /** * @brief Return a style in the style storage * @param styleId the id of the style */ GeoDataStyle::Ptr style( const QString& styleId ); GeoDataStyle::ConstPtr style( const QString& styleId ) const; /** * @brief dump a Vector of all styles */ QList styles(); QList styles() const; /** * @brief Add a stylemap to the stylemap storage * @param map the new stylemap */ void addStyleMap( const GeoDataStyleMap& map ); /** * @brief remove stylemap from storage * @param mapId the styleId of the styleMap to be removed */ void removeStyleMap( const QString& mapId ); /** * @brief Return a style in the style storage * @param styleId the id of the style */ GeoDataStyleMap& styleMap( const QString& styleId ); GeoDataStyleMap styleMap( const QString& styleId ) const; /** * @brief dump a Vector of all stylemaps */ QList styleMaps() const; /** * @brief Add a schema to simplemap storage * @param schema the new schema */ void addSchema( const GeoDataSchema& schema ); /** * @brief remove a schema from schema storage * @param schemaId the of schema to be removed */ void removeSchema( const QString& schemaId ); /** * @brief Returns a schema with id = schemaId form schema storage * @param schemaId The id of schema to be returned */ GeoDataSchema schema( const QString& schemaId ) const; GeoDataSchema &schema( const QString& schemaId ); /** * @brief dump a vector of all schemas */ QList schemas() const; // Serialize the Placemark to @p stream virtual void pack( QDataStream& stream ) const; // Unserialize the Placemark from @p stream virtual void unpack( QDataStream& stream ); private: - GeoDataDocumentPrivate *p(); - const GeoDataDocumentPrivate *p() const; + Q_DECLARE_PRIVATE(GeoDataDocument) }; } Q_DECLARE_METATYPE(Marble::GeoDataDocument*) #endif diff --git a/src/lib/marble/geodata/data/GeoDataFeature.cpp b/src/lib/marble/geodata/data/GeoDataFeature.cpp index c71da2389..955bd2df3 100644 --- a/src/lib/marble/geodata/data/GeoDataFeature.cpp +++ b/src/lib/marble/geodata/data/GeoDataFeature.cpp @@ -1,490 +1,565 @@ // // 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 "GeoDataFolder.h" #include "GeoDataPlacemark.h" #include "GeoDataRegion.h" #include "GeoDataCamera.h" namespace Marble { const QSharedPointer GeoDataFeaturePrivate::s_defaultStyle(new GeoDataStyle); GeoDataFeature::GeoDataFeature() - : d( new GeoDataFeaturePrivate() ) + : d_ptr(new GeoDataFeaturePrivate()) { - d->ref.ref(); + d_ptr->ref.ref(); } GeoDataFeature::GeoDataFeature( const GeoDataFeature& other ) : GeoDataObject(), - d( other.d ) + d_ptr( other.d_ptr ) { - d->ref.ref(); + d_ptr->ref.ref(); } GeoDataFeature::GeoDataFeature( const QString& name ) - : d( new GeoDataFeaturePrivate() ) + : d_ptr(new GeoDataFeaturePrivate()) { - d->ref.ref(); - d->m_name = name; + d_ptr->ref.ref(); + d_ptr->m_name = name; } -GeoDataFeature::GeoDataFeature( GeoDataFeaturePrivate *priv ) - : d( priv ) +GeoDataFeature::GeoDataFeature(GeoDataFeaturePrivate *dd) + : d_ptr(dd) { - d->ref.ref(); + d_ptr->ref.ref(); } GeoDataFeature::~GeoDataFeature() { - if (!d->ref.deref()) { - delete d; + if (!d_ptr->ref.deref()) { + delete d_ptr; } } -GeoDataFeaturePrivate* GeoDataFeature::p() const -{ - return static_cast(d); -} - GeoDataFeature& GeoDataFeature::operator=( const GeoDataFeature& other ) { - if (!d->ref.deref()) { - delete d; + if (!d_ptr->ref.deref()) { + delete d_ptr; } - d = other.d; - d->ref.ref(); + d_ptr = other.d_ptr; + d_ptr->ref.ref(); return *this; } bool GeoDataFeature::equals( const GeoDataFeature &other ) const { - 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() ) { + 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) ) { + 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) ) { + 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) ) { + 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) ) { + if ((d->m_featureExtendedData && other_d->m_featureExtendedData) && + (*d->m_featureExtendedData != *other_d->m_featureExtendedData)) { return false; } return true; } const char* GeoDataFeature::nodeType() const { - return p()->nodeType(); + Q_D(const GeoDataFeature); + return d->nodeType(); } 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 ) { detach(); + + 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 ) { detach(); + + 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) { - if (value.isEmpty() && !d->m_featureExtendedData) { + if (value.isEmpty() && !d_func()->m_featureExtendedData) { return; // nothing to change } detach(); + + Q_D(GeoDataFeature); 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) { - if (value.isEmpty() && !d->m_featureExtendedData) { + if (value.isEmpty() && !d_func()->m_featureExtendedData) { return; // nothing to change } detach(); + + Q_D(GeoDataFeature); 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) { - if (value.isEmpty() && !d->m_featureExtendedData) { + if (value.isEmpty() && !d_func()->m_featureExtendedData) { return; // nothing to change } detach(); + + Q_D(GeoDataFeature); 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 ) { detach(); + + 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 ) { - if (abstractView == nullptr && !d->m_featureExtendedData) { + if (abstractView == nullptr && !d_func()->m_featureExtendedData) { return; // nothing to change } detach(); + + Q_D(GeoDataFeature); d->featureExtendedData().m_abstractView = abstractView; } QString GeoDataFeature::styleUrl() const { + Q_D(const GeoDataFeature); return d->m_styleUrl; } void GeoDataFeature::setStyleUrl( const QString &value ) { detach(); + 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 ) { detach(); + + 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() { detach(); + + Q_D(GeoDataFeature); return d->featureExtendedData().m_timeSpan; } void GeoDataFeature::setTimeSpan( const GeoDataTimeSpan &timeSpan ) { detach(); + + 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() { detach(); + + Q_D(GeoDataFeature); return d->featureExtendedData().m_timeStamp; } void GeoDataFeature::setTimeStamp( const GeoDataTimeStamp &timeStamp ) { detach(); + + 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 ) { detach(); + + Q_D(GeoDataFeature); if (style) style->setParent( this ); d->m_style = style; } GeoDataExtendedData& GeoDataFeature::extendedData() { detach(); + + Q_D(GeoDataFeature); return d->m_extendedData; } void GeoDataFeature::setExtendedData( const GeoDataExtendedData& extendedData ) { detach(); + + Q_D(GeoDataFeature); d->m_extendedData = extendedData; } -GeoDataRegion& GeoDataFeature::region() const +const GeoDataRegion& GeoDataFeature::region() const +{ + Q_D(const GeoDataFeature); + return d->featureExtendedData().m_region; +} + +GeoDataRegion& GeoDataFeature::region() { - // FIXME: Should call detach(). Maybe don't return reference. + detach(); + + Q_D(GeoDataFeature); return d->featureExtendedData().m_region; } void GeoDataFeature::setRegion( const GeoDataRegion& region ) { detach(); + + 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 ) { detach(); + + 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 ) { + detach(); + + Q_D(GeoDataFeature); d->m_styleMap = styleMap; } int GeoDataFeature::zoomLevel() const { + Q_D(const GeoDataFeature); return d->m_zoomLevel; } void GeoDataFeature::setZoomLevel( int zoomLevel ) { detach(); + + Q_D(GeoDataFeature); d->m_zoomLevel = zoomLevel; } qint64 GeoDataFeature::popularity() const { + Q_D(const GeoDataFeature); return d->m_popularity; } void GeoDataFeature::setPopularity( qint64 popularity ) { detach(); + + Q_D(GeoDataFeature); d->m_popularity = popularity; } void GeoDataFeature::detach() { - if(d->ref.load() == 1) { + if (d_ptr->ref.load() == 1) { return; } - GeoDataFeaturePrivate* new_d = d->copy(); + GeoDataFeaturePrivate* new_d = d_ptr->copy(); - if (!d->ref.deref()) { - delete d; + if (!d_ptr->ref.deref()) { + delete d_ptr; } - d = new_d; + d_ptr = new_d; - d->ref.ref(); + d_ptr->ref.ref(); } 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 ) { detach(); + + 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 9ec006c03..a4a521361 100644 --- a/src/lib/marble/geodata/data/GeoDataFeature.h +++ b/src/lib/marble/geodata/data/GeoDataFeature.h @@ -1,286 +1,286 @@ // // 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 */ // FIXME: Later also add NetworkLink and Overlay 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 ); virtual ~GeoDataFeature(); GeoDataFeature& operator=( const GeoDataFeature& other ); /// Provides type information for downcasting a GeoData virtual const char* nodeType() const; 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. */ - GeoDataRegion& region() const; + 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 ); /// Serialize the contents of the feature to @p stream. virtual void pack( QDataStream& stream ) const; /// Unserialize the contents of the feature from @p stream. virtual void unpack( QDataStream& stream ); protected: // the d-pointer needs to be protected to be accessible from derived classes - GeoDataFeaturePrivate* d; - explicit GeoDataFeature( GeoDataFeaturePrivate* priv ); + GeoDataFeaturePrivate* d_ptr; + explicit GeoDataFeature(GeoDataFeaturePrivate* dd); virtual void detach(); bool equals( const GeoDataFeature &other ) const; using GeoDataObject::equals; private: - // the private d pointer accessor - use it instead of the d pointer directly - GeoDataFeaturePrivate* p() const; + Q_DECLARE_PRIVATE(GeoDataFeature) }; } #endif diff --git a/src/lib/marble/geodata/data/GeoDataFeature_p.h b/src/lib/marble/geodata/data/GeoDataFeature_p.h index 86649c618..1b5bed8f5 100644 --- a/src/lib/marble/geodata/data/GeoDataFeature_p.h +++ b/src/lib/marble/geodata/data/GeoDataFeature_p.h @@ -1,248 +1,255 @@ // // 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 2009 Patrick Spendrin // #ifndef MARBLE_GEODATAFEATUREPRIVATE_H #define MARBLE_GEODATAFEATUREPRIVATE_H #include #include #include "GeoDataExtendedData.h" #include "GeoDataAbstractView.h" #include "GeoDataFeature.h" #include "GeoDataRegion.h" #include "GeoDataTimeStamp.h" #include "GeoDataTimeSpan.h" #include "GeoDataTypes.h" #include "GeoDataStyle.h" #include "GeoDataSnippet.h" #include "GeoDataLookAt.h" #include "GeoDataCamera.h" namespace Marble { class GeoDataFeatureExtendedData { public: GeoDataSnippet m_snippet; // Snippet of the feature. QString m_description; // A longer textual description bool m_descriptionCDATA; // True if description should be considered CDATA QString m_address; // The address. Optional QString m_phoneNumber; // Phone Optional GeoDataAbstractView* m_abstractView; // AbstractView Optional GeoDataTimeSpan m_timeSpan; GeoDataTimeStamp m_timeStamp; GeoDataRegion m_region; GeoDataFeatureExtendedData() : m_snippet(), m_description(), m_descriptionCDATA(false), m_address(), m_phoneNumber(), m_abstractView( 0 ), m_timeSpan(), m_timeStamp(), m_region() { // nothing to do } GeoDataFeatureExtendedData(const GeoDataFeatureExtendedData &other) : m_snippet( other.m_snippet ), m_description( other.m_description ), m_descriptionCDATA( other.m_descriptionCDATA), m_address( other.m_address ), m_phoneNumber( other.m_phoneNumber ), m_abstractView( other.m_abstractView ), m_timeSpan( other.m_timeSpan ), m_timeStamp( other.m_timeStamp ), m_region( other.m_region ) { // nothing to do } GeoDataFeatureExtendedData& operator=(const GeoDataFeatureExtendedData &other) { m_snippet = other.m_snippet; m_description = other.m_description; m_descriptionCDATA = other.m_descriptionCDATA; m_address = other.m_address; m_phoneNumber = other.m_phoneNumber; m_abstractView = other.m_abstractView; m_timeSpan = other.m_timeSpan; m_timeStamp = other.m_timeStamp; m_region = other.m_region; return *this; } bool operator==(const GeoDataFeatureExtendedData &other) const { if (m_snippet != other.m_snippet || m_description != other.m_description || m_descriptionCDATA != other.m_descriptionCDATA || m_address != other.m_address || m_phoneNumber != other.m_phoneNumber || m_timeSpan != other.m_timeSpan || m_timeStamp != other.m_timeStamp || m_region != other.m_region) { return false; } if ( (!m_abstractView && other.m_abstractView) || (m_abstractView && !other.m_abstractView) ) { return false; } if (m_abstractView && other.m_abstractView) { if ( m_abstractView->nodeType() != other.m_abstractView->nodeType() ) { return false; } if ( m_abstractView->nodeType() == GeoDataTypes::GeoDataCameraType ) { GeoDataCamera *thisCam = dynamic_cast( m_abstractView ); GeoDataCamera *otherCam = dynamic_cast( other.m_abstractView ); Q_ASSERT(thisCam && otherCam); if ( *thisCam != *otherCam ) { return false; } } else if ( m_abstractView->nodeType() == GeoDataTypes::GeoDataLookAtType ) { GeoDataLookAt *thisLookAt = dynamic_cast( m_abstractView ); GeoDataLookAt *otherLookAt = dynamic_cast( other.m_abstractView ); Q_ASSERT(thisLookAt && otherLookAt); if ( *thisLookAt != *otherLookAt ) { return false; } } } return true; } bool operator!=(const GeoDataFeatureExtendedData &other) const { return !(*this == other); } }; class GeoDataFeaturePrivate { public: GeoDataFeaturePrivate() : m_name(), m_styleUrl(), m_popularity( 0 ), m_zoomLevel( 1 ), m_visible( true ), m_role(" "), m_style( 0 ), m_styleMap( 0 ), m_extendedData(), m_featureExtendedData(nullptr), ref( 0 ) { } GeoDataFeaturePrivate( const GeoDataFeaturePrivate& other ) : m_name( other.m_name ), m_styleUrl( other.m_styleUrl ), m_popularity( other.m_popularity ), m_zoomLevel( other.m_zoomLevel ), m_visible( other.m_visible ), m_role( other.m_role ), m_style( other.m_style ), //FIXME: both style and stylemap need to be reworked internally!!!! m_styleMap( other.m_styleMap ), m_extendedData( other.m_extendedData ), m_featureExtendedData(nullptr), ref( 0 ) { if (other.m_featureExtendedData) { m_featureExtendedData = new GeoDataFeatureExtendedData(*other.m_featureExtendedData); } } GeoDataFeaturePrivate& operator=( const GeoDataFeaturePrivate& other ) { m_name = other.m_name; m_styleUrl = other.m_styleUrl; m_popularity = other.m_popularity; m_zoomLevel = other.m_zoomLevel; m_visible = other.m_visible; m_role = other.m_role; m_style = other.m_style; m_styleMap = other.m_styleMap; m_extendedData = other.m_extendedData; delete m_featureExtendedData; m_featureExtendedData = nullptr; if (other.m_featureExtendedData) { m_featureExtendedData = new GeoDataFeatureExtendedData(*other.m_featureExtendedData); } return *this; } virtual GeoDataFeaturePrivate* copy() { GeoDataFeaturePrivate* copy = new GeoDataFeaturePrivate; *copy = *this; return copy; } virtual EnumFeatureId featureId() const { return InvalidFeatureId; } virtual ~GeoDataFeaturePrivate() { delete m_featureExtendedData; } virtual const char* nodeType() const { return GeoDataTypes::GeoDataFeatureType; } GeoDataFeatureExtendedData & featureExtendedData() { if (!m_featureExtendedData) { m_featureExtendedData = new GeoDataFeatureExtendedData; } return *m_featureExtendedData; } + const GeoDataFeatureExtendedData & featureExtendedData() const + { + if (!m_featureExtendedData) { + m_featureExtendedData = new GeoDataFeatureExtendedData; + } + return *m_featureExtendedData; + } QString m_name; // Name of the feature. Is shown on screen QString m_styleUrl; // styleUrl Url#tag to a document wide style qint64 m_popularity; // Population/Area/Altitude depending on placemark(!) int m_zoomLevel; // Zoom Level of the feature bool m_visible; // True if this feature should be shown. QString m_role; GeoDataStyle::Ptr m_style; const GeoDataStyleMap* m_styleMap; GeoDataExtendedData m_extendedData; - GeoDataFeatureExtendedData* m_featureExtendedData; + mutable GeoDataFeatureExtendedData* m_featureExtendedData; QAtomicInt ref; // Static members static const QSharedPointer s_defaultStyle; }; } // namespace Marble #endif diff --git a/src/lib/marble/geodata/data/GeoDataFolder.cpp b/src/lib/marble/geodata/data/GeoDataFolder.cpp index c7ccdc44b..e197ef855 100644 --- a/src/lib/marble/geodata/data/GeoDataFolder.cpp +++ b/src/lib/marble/geodata/data/GeoDataFolder.cpp @@ -1,82 +1,77 @@ /* Copyright (C) 2007 Murad Tagirov Copyright (C) 2007 Nikolas Zimmermann 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 "GeoDataFolder.h" #include "GeoDataTypes.h" #include "GeoDataContainer_p.h" namespace Marble { class GeoDataFolderPrivate : public GeoDataContainerPrivate { public: GeoDataFolderPrivate() { } virtual GeoDataFeaturePrivate* copy() { GeoDataFolderPrivate* copy = new GeoDataFolderPrivate; *copy = *this; return copy; } virtual const char* nodeType() const { return GeoDataTypes::GeoDataFolderType; } }; GeoDataFolder::GeoDataFolder() : GeoDataContainer( new GeoDataFolderPrivate ) { } GeoDataFolder::GeoDataFolder( const GeoDataFolder& other ) : GeoDataContainer( other ) { } GeoDataFolder::~GeoDataFolder() { } -GeoDataFolderPrivate* GeoDataFolder::p() const -{ - return static_cast(d); -} - bool GeoDataFolder::operator==( const GeoDataFolder &other ) const { return GeoDataContainer::equals( other ); } bool GeoDataFolder::operator!=( const GeoDataFolder &other ) const { return !this->operator==( other ); } } diff --git a/src/lib/marble/geodata/data/GeoDataFolder.h b/src/lib/marble/geodata/data/GeoDataFolder.h index cd0c9f2fe..6ccc55376 100644 --- a/src/lib/marble/geodata/data/GeoDataFolder.h +++ b/src/lib/marble/geodata/data/GeoDataFolder.h @@ -1,68 +1,68 @@ /* Copyright (C) 2007 Nikolas Zimmermann Copyright 2007 Murad Tagirov Copyright 2007 Inge Wallin 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_GEODATAFOLDER_H #define MARBLE_GEODATAFOLDER_H #include "GeoDataContainer.h" #include "geodata_export.h" namespace Marble { /** * @short A container that is used to arrange other GeoDataFeatures. * * A GeoDataFolder is used to arrange other GeoDataFeatures * hierarchically (Folders, Placemarks, NetworkLinks, or Overlays). A * GeoDataFeature is visible only if it and all its ancestors are * visible. * * @see GeoDataFeature * @see GeoDataContainer */ class GeoDataFolderPrivate; class GEODATA_EXPORT GeoDataFolder : public GeoDataContainer { public: GeoDataFolder(); GeoDataFolder( const GeoDataFolder& other ); ~GeoDataFolder(); bool operator==( const GeoDataFolder &other ) const; bool operator!=( const GeoDataFolder &other ) const; private: - GeoDataFolderPrivate *p() const; + Q_DECLARE_PRIVATE(GeoDataFolder) }; } Q_DECLARE_METATYPE(Marble::GeoDataFolder*) #endif diff --git a/src/lib/marble/geodata/data/GeoDataPlacemark.cpp b/src/lib/marble/geodata/data/GeoDataPlacemark.cpp index 056df6536..ad7cbe45c 100644 --- a/src/lib/marble/geodata/data/GeoDataPlacemark.cpp +++ b/src/lib/marble/geodata/data/GeoDataPlacemark.cpp @@ -1,822 +1,849 @@ // // 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 2004-2007 Torsten Rahn // Copyright 2007 Inge Wallin // Copyright 2008-2009 Patrick Spendrin // // Own #include "GeoDataPlacemark.h" // Private #include "GeoDataPlacemark_p.h" #include "GeoDataMultiGeometry.h" #include "GeoDataCoordinates.h" #include "GeoDataLatLonAltBox.h" #include "GeoDataData.h" #include "osm/OsmPlacemarkData.h" // Qt #include #include "MarbleDebug.h" #include "GeoDataTrack.h" #include "GeoDataModel.h" #include #include namespace Marble { const OsmPlacemarkData GeoDataPlacemarkPrivate::s_nullOsmPlacemarkData = OsmPlacemarkData(); const GeoDataPlacemarkExtendedData GeoDataPlacemarkPrivate::s_nullPlacemarkExtendedData = GeoDataPlacemarkExtendedData(); GeoDataPlacemark::GeoDataPlacemark() : GeoDataFeature( new GeoDataPlacemarkPrivate ) { - p()->m_geometry->setParent( this ); + Q_D(GeoDataPlacemark); + d->m_geometry->setParent(this); } GeoDataPlacemark::GeoDataPlacemark( const GeoDataPlacemark& other ) : GeoDataFeature( other ) { // FIXME: temporary (until detach() is called) violates following invariant // which could lead to crashes // Q_ASSERT( this == p()->m_geometry->parent() ); // FIXME: fails as well when "other" is a copy where detach wasn't called -// Q_ASSERT( other.p()->m_geometry == 0 || &other == other.p()->m_geometry->parent() ); +// Q_ASSERT( other_d->m_geometry == 0 || &other == other_d->m_geometry->parent() ); } GeoDataPlacemark::GeoDataPlacemark( const QString& name ) : GeoDataFeature( new GeoDataPlacemarkPrivate ) { + Q_D(GeoDataPlacemark); d->m_name = name; - p()->m_geometry->setParent( this ); + d->m_geometry->setParent(this); } GeoDataPlacemark::~GeoDataPlacemark() { // nothing to do } GeoDataPlacemark &GeoDataPlacemark::operator=( const GeoDataPlacemark &other ) { GeoDataFeature::operator=( other ); return *this; } bool GeoDataPlacemark::operator==( const GeoDataPlacemark& other ) const { + Q_D(const GeoDataPlacemark); + const GeoDataPlacemarkPrivate* const other_d = other.d_func(); if (!equals(other) || - p()->m_population != other.p()->m_population) { + d->m_population != other_d->m_population) { return false; } - if ((p()->m_placemarkExtendedData && !other.p()->m_placemarkExtendedData) || - (!p()->m_placemarkExtendedData && other.p()->m_placemarkExtendedData)) { + if ((d->m_placemarkExtendedData && !other_d->m_placemarkExtendedData) || + (!d->m_placemarkExtendedData && other_d->m_placemarkExtendedData)) { return false; } - if (p()->m_placemarkExtendedData && other.p()->m_placemarkExtendedData && - !(*p()->m_placemarkExtendedData == *other.p()->m_placemarkExtendedData)) { + if (d->m_placemarkExtendedData && other_d->m_placemarkExtendedData && + !(*d->m_placemarkExtendedData == *other_d->m_placemarkExtendedData)) { return false; } - if ( !p()->m_geometry && !other.p()->m_geometry ) { + if (!d->m_geometry && !other_d->m_geometry) { return true; - } else if ( (!p()->m_geometry && other.p()->m_geometry) || - (p()->m_geometry && !other.p()->m_geometry) ) { + } + if ((!d->m_geometry && other_d->m_geometry) || + (d->m_geometry && !other_d->m_geometry)) { return false; } - if ( p()->m_geometry->nodeType() != other.p()->m_geometry->nodeType() ) { + if (d->m_geometry->nodeType() != other_d->m_geometry->nodeType()) { return false; } - if ( p()->m_geometry->nodeType() == GeoDataTypes::GeoDataPolygonType ) { - GeoDataPolygon *thisPoly = dynamic_cast( p()->m_geometry ); - GeoDataPolygon *otherPoly = dynamic_cast( other.p()->m_geometry ); + if (d->m_geometry->nodeType() == GeoDataTypes::GeoDataPolygonType) { + GeoDataPolygon *thisPoly = dynamic_cast(d->m_geometry); + GeoDataPolygon *otherPoly = dynamic_cast(other_d->m_geometry); Q_ASSERT( thisPoly && otherPoly ); if ( *thisPoly != *otherPoly ) { return false; } - } else if ( p()->m_geometry->nodeType() == GeoDataTypes::GeoDataLineStringType ) { - GeoDataLineString *thisLine = dynamic_cast( p()->m_geometry ); - GeoDataLineString *otherLine = dynamic_cast( other.p()->m_geometry ); + } else if (d->m_geometry->nodeType() == GeoDataTypes::GeoDataLineStringType) { + GeoDataLineString *thisLine = dynamic_cast(d->m_geometry); + GeoDataLineString *otherLine = dynamic_cast(other_d->m_geometry); Q_ASSERT( thisLine && otherLine ); if ( *thisLine != *otherLine ) { return false; } - } else if ( p()->m_geometry->nodeType() == GeoDataTypes::GeoDataModelType ) { - GeoDataModel *thisModel = dynamic_cast( p()->m_geometry ); - GeoDataModel *otherModel = dynamic_cast( other.p()->m_geometry ); + } else if (d->m_geometry->nodeType() == GeoDataTypes::GeoDataModelType) { + GeoDataModel *thisModel = dynamic_cast(d->m_geometry); + GeoDataModel *otherModel = dynamic_cast(other_d->m_geometry); Q_ASSERT( thisModel && otherModel ); if ( *thisModel != *otherModel ) { return false; } - /*} else if ( p()->m_geometry->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) { - GeoDataMultiGeometry *thisMG = dynamic_cast( p()->m_geometry ); - GeoDataMultiGeometry *otherMG = dynamic_cast( other.p()->m_geometry ); + /*} else if (d->m_geometry->nodeType() == GeoDataTypes::GeoDataMultiGeometryType) { + GeoDataMultiGeometry *thisMG = dynamic_cast(d->m_geometry); + GeoDataMultiGeometry *otherMG = dynamic_cast(other_d->m_geometry); Q_ASSERT( thisMG && otherMG ); if ( *thisMG != *otherMG ) { return false; } */ // Does not have equality operators. I guess they need to be implemented soon. - } else if ( p()->m_geometry->nodeType() == GeoDataTypes::GeoDataTrackType ) { - GeoDataTrack *thisTrack = dynamic_cast( p()->m_geometry ); - GeoDataTrack *otherTrack = dynamic_cast( other.p()->m_geometry ); + } else if (d->m_geometry->nodeType() == GeoDataTypes::GeoDataTrackType) { + GeoDataTrack *thisTrack = dynamic_cast(d->m_geometry); + GeoDataTrack *otherTrack = dynamic_cast(other_d->m_geometry); Q_ASSERT( thisTrack && otherTrack ); if ( *thisTrack != *otherTrack ) { return false; } - } else if ( p()->m_geometry->nodeType() == GeoDataTypes::GeoDataMultiTrackType ) { - GeoDataMultiTrack *thisMT = dynamic_cast( p()->m_geometry ); - GeoDataMultiTrack *otherMT = dynamic_cast( other.p()->m_geometry ); + } else if (d->m_geometry->nodeType() == GeoDataTypes::GeoDataMultiTrackType) { + GeoDataMultiTrack *thisMT = dynamic_cast(d->m_geometry); + GeoDataMultiTrack *otherMT = dynamic_cast(other_d->m_geometry); Q_ASSERT( thisMT && otherMT ); if ( *thisMT != *otherMT ) { return false; } - } else if ( p()->m_geometry->nodeType() == GeoDataTypes::GeoDataPointType ) { - GeoDataPoint *thisPoint = dynamic_cast( p()->m_geometry ); - GeoDataPoint *otherPoint = dynamic_cast( other.p()->m_geometry ); + } else if (d->m_geometry->nodeType() == GeoDataTypes::GeoDataPointType) { + GeoDataPoint *thisPoint = dynamic_cast(d->m_geometry); + GeoDataPoint *otherPoint = dynamic_cast(other_d->m_geometry); Q_ASSERT( thisPoint && otherPoint ); if ( *thisPoint != *otherPoint ) { return false; } } return true; } bool GeoDataPlacemark::operator!=( const GeoDataPlacemark& other ) const { return !this->operator==( other ); } GeoDataPlacemark::GeoDataVisualCategory GeoDataPlacemark::visualCategory() const { - return p()->m_visualCategory; + Q_D(const GeoDataPlacemark); + return d->m_visualCategory; } void GeoDataPlacemark::setVisualCategory(GeoDataPlacemark::GeoDataVisualCategory index) { detach(); - p()->m_visualCategory = index; -} - -GeoDataPlacemarkPrivate* GeoDataPlacemark::p() -{ - return static_cast(d); -} -const GeoDataPlacemarkPrivate* GeoDataPlacemark::p() const -{ - return static_cast(d); + Q_D(GeoDataPlacemark); + d->m_visualCategory = index; } GeoDataGeometry* GeoDataPlacemark::geometry() { detach(); - p()->m_geometry->setParent( this ); - return p()->m_geometry; + + Q_D(GeoDataPlacemark); + d->m_geometry->setParent(this); + return d->m_geometry; } const GeoDataGeometry* GeoDataPlacemark::geometry() const { - return p()->m_geometry; + Q_D(const GeoDataPlacemark); + return d->m_geometry; } const OsmPlacemarkData& GeoDataPlacemark::osmData() const { + Q_D(const GeoDataPlacemark); QVariant &placemarkVariantData = extendedData().valueRef( OsmPlacemarkData::osmHashKey() ).valueRef(); if ( !placemarkVariantData.canConvert() ) { - return p()->s_nullOsmPlacemarkData; + return d->s_nullOsmPlacemarkData; } OsmPlacemarkData &osmData = *reinterpret_cast( placemarkVariantData.data() ); return osmData; } void GeoDataPlacemark::setOsmData( const OsmPlacemarkData &osmData ) { extendedData().addValue( GeoDataData( OsmPlacemarkData::osmHashKey(), QVariant::fromValue( osmData ) ) ); } OsmPlacemarkData& GeoDataPlacemark::osmData() { QVariant &placemarkVariantData = extendedData().valueRef( OsmPlacemarkData::osmHashKey() ).valueRef(); if ( !placemarkVariantData.canConvert() ) { extendedData().addValue( GeoDataData( OsmPlacemarkData::osmHashKey(), QVariant::fromValue( OsmPlacemarkData() ) ) ); placemarkVariantData = extendedData().valueRef( OsmPlacemarkData::osmHashKey() ).valueRef(); } OsmPlacemarkData &osmData = *reinterpret_cast( placemarkVariantData.data() ); return osmData; } bool GeoDataPlacemark::hasOsmData() const { QVariant &placemarkVariantData = extendedData().valueRef( OsmPlacemarkData::osmHashKey() ).valueRef(); return placemarkVariantData.canConvert(); } void GeoDataPlacemark::clearOsmData() { detach(); extendedData().removeKey(OsmPlacemarkData::osmHashKey()); } const GeoDataLookAt *GeoDataPlacemark::lookAt() const { return dynamic_cast( abstractView() ); } GeoDataLookAt *GeoDataPlacemark::lookAt() { return dynamic_cast( abstractView() ); } bool GeoDataPlacemark::placemarkLayoutOrderCompare(const GeoDataPlacemark *left, const GeoDataPlacemark *right) { - if (left->d->m_zoomLevel != right->d->m_zoomLevel) { - return (left->d->m_zoomLevel < right->d->m_zoomLevel); // lower zoom level comes first + const GeoDataPlacemarkPrivate * const left_d = left->d_func(); + const GeoDataPlacemarkPrivate * const right_d = right->d_func(); + + if (left_d->m_zoomLevel != right_d->m_zoomLevel) { + return (left_d->m_zoomLevel < right_d->m_zoomLevel); // lower zoom level comes first } - if (left->d->m_popularity != right->d->m_popularity) { - return left->d->m_popularity > right->d->m_popularity; // higher popularity comes first + if (left_d->m_popularity != right_d->m_popularity) { + return (left_d->m_popularity > right_d->m_popularity); // higher popularity comes first } return left < right; // lower pointer value comes first } GeoDataCoordinates GeoDataPlacemark::coordinate( const QDateTime &dateTime, bool *iconAtCoordinates ) const { + Q_D(const GeoDataPlacemark); bool hasIcon = false; GeoDataCoordinates coord; - if( p()->m_geometry ) { + if (d->m_geometry) { // Beware: comparison between pointers, not strings. - if (p()->m_geometry->nodeType() == GeoDataTypes::GeoDataPointType - || p()->m_geometry->nodeType() == GeoDataTypes::GeoDataPolygonType - || p()->m_geometry->nodeType() == GeoDataTypes::GeoDataLinearRingType) { + if (d->m_geometry->nodeType() == GeoDataTypes::GeoDataPointType + || d->m_geometry->nodeType() == GeoDataTypes::GeoDataPolygonType + || d->m_geometry->nodeType() == GeoDataTypes::GeoDataLinearRingType) { hasIcon = true; - coord = p()->m_geometry->latLonAltBox().center(); - } else if ( p()->m_geometry->nodeType() == GeoDataTypes::GeoDataMultiGeometryType ) { - const GeoDataMultiGeometry *multiGeometry = static_cast( p()->m_geometry ); + coord = d->m_geometry->latLonAltBox().center(); + } else if (d->m_geometry->nodeType() == GeoDataTypes::GeoDataMultiGeometryType) { + const GeoDataMultiGeometry *multiGeometry = static_cast(d->m_geometry); QVector::ConstIterator it = multiGeometry->constBegin(); QVector::ConstIterator end = multiGeometry->constEnd(); for ( ; it != end; ++it ) { if ((*it)->nodeType() == GeoDataTypes::GeoDataPointType || (*it)->nodeType() == GeoDataTypes::GeoDataPolygonType || (*it)->nodeType() == GeoDataTypes::GeoDataLinearRingType) { hasIcon = true; break; } } - coord = p()->m_geometry->latLonAltBox().center(); - } else if ( p()->m_geometry->nodeType() == GeoDataTypes::GeoDataTrackType ) { - const GeoDataTrack *track = static_cast( p()->m_geometry ); + coord = d->m_geometry->latLonAltBox().center(); + } else if (d->m_geometry->nodeType() == GeoDataTypes::GeoDataTrackType) { + const GeoDataTrack *track = static_cast(d->m_geometry); hasIcon = track->size() != 0 && track->firstWhen() <= dateTime; coord = track->coordinatesAt( dateTime ); } else { - coord = p()->m_geometry->latLonAltBox().center(); + coord = d->m_geometry->latLonAltBox().center(); } } if ( iconAtCoordinates != 0 ) { *iconAtCoordinates = hasIcon; } return coord; } void GeoDataPlacemark::coordinate( qreal& lon, qreal& lat, qreal& alt ) const { coordinate().geoCoordinates( lon, lat, alt ); } void GeoDataPlacemark::setCoordinate( qreal lon, qreal lat, qreal alt, GeoDataPoint::Unit _unit) { setGeometry( new GeoDataPoint(lon, lat, alt, _unit ) ); } void GeoDataPlacemark::setCoordinate( const GeoDataCoordinates &point ) { setGeometry ( new GeoDataPoint( point ) ); } void GeoDataPlacemark::setGeometry( GeoDataGeometry *entry ) { detach(); - delete p()->m_geometry; - p()->m_geometry = entry; - p()->m_geometry->setParent( this ); + + Q_D(GeoDataPlacemark); + delete d->m_geometry; + d->m_geometry = entry; + d->m_geometry->setParent(this); } QString GeoDataPlacemark::displayName() const { if (hasOsmData()) { OsmPlacemarkData const &data = osmData(); QStringList const uiLanguages = QLocale::system().uiLanguages(); foreach (const QString &uiLanguage, uiLanguages) { for (auto tagIter = data.tagsBegin(), end = data.tagsEnd(); tagIter != end; ++tagIter) { if (tagIter.key().startsWith(QLatin1String("name:"))) { QStringRef const tagLanguage = tagIter.key().midRef(5); if (tagLanguage == uiLanguage) { return tagIter.value(); } } } } } return name(); } QString GeoDataPlacemark::categoryName() const { - switch (p()->m_visualCategory) { + Q_D(const GeoDataPlacemark); + switch (d->m_visualCategory) { case Valley: return GeoDataPlacemarkPrivate::tr("Valley"); case OtherTerrain: return GeoDataPlacemarkPrivate::tr("Terrain"); case Crater: return GeoDataPlacemarkPrivate::tr("Crater"); case Mare: return GeoDataPlacemarkPrivate::tr("Sea"); case MannedLandingSite: return GeoDataPlacemarkPrivate::tr("Manned Landing Site"); case RoboticRover: return GeoDataPlacemarkPrivate::tr("Robotic Rover"); case UnmannedSoftLandingSite: return GeoDataPlacemarkPrivate::tr("Unmanned Soft Landing Site"); case UnmannedHardLandingSite: return GeoDataPlacemarkPrivate::tr("Unmanned Hard Landing Site"); case Mons: return GeoDataPlacemarkPrivate::tr("Mountain"); case SmallCity: return GeoDataPlacemarkPrivate::tr("City"); case SmallCountyCapital: return GeoDataPlacemarkPrivate::tr("County Capital"); case SmallStateCapital: return GeoDataPlacemarkPrivate::tr("State Capital"); case SmallNationCapital: return GeoDataPlacemarkPrivate::tr("Nation Capital"); case MediumCity: return GeoDataPlacemarkPrivate::tr("City"); case MediumCountyCapital: return GeoDataPlacemarkPrivate::tr("County Capital"); case MediumStateCapital: return GeoDataPlacemarkPrivate::tr("State Capital"); case MediumNationCapital: return GeoDataPlacemarkPrivate::tr("Nation Capital"); case BigCity: return GeoDataPlacemarkPrivate::tr("City"); case BigCountyCapital: return GeoDataPlacemarkPrivate::tr("County Capital"); case BigStateCapital: return GeoDataPlacemarkPrivate::tr("State Capital"); case BigNationCapital: return GeoDataPlacemarkPrivate::tr("Nation Capital"); case LargeCity: return GeoDataPlacemarkPrivate::tr("City"); case LargeCountyCapital: return GeoDataPlacemarkPrivate::tr("County Capital"); case LargeStateCapital: return GeoDataPlacemarkPrivate::tr("State Capital"); case LargeNationCapital: return GeoDataPlacemarkPrivate::tr("Nation Capital"); case Nation: return GeoDataPlacemarkPrivate::tr("Nation"); case Mountain: return GeoDataPlacemarkPrivate::tr("Mountain"); case Volcano: return GeoDataPlacemarkPrivate::tr("Volcano"); case Continent: return GeoDataPlacemarkPrivate::tr("Continent"); case Ocean: return GeoDataPlacemarkPrivate::tr("Ocean"); case GeographicPole: return GeoDataPlacemarkPrivate::tr("Geographic Pole"); case MagneticPole: return GeoDataPlacemarkPrivate::tr("Magnetic Pole"); case ShipWreck: return GeoDataPlacemarkPrivate::tr("Ship Wreck"); case AirPort: return GeoDataPlacemarkPrivate::tr("Air Port"); case Observatory: return GeoDataPlacemarkPrivate::tr("Observatory"); case MilitaryDangerArea: return GeoDataPlacemarkPrivate::tr("Military Danger Area"); case OsmSite: return GeoDataPlacemarkPrivate::tr("OSM Site"); case Coordinate: return GeoDataPlacemarkPrivate::tr("Coordinate"); case Bookmark: return GeoDataPlacemarkPrivate::tr("Bookmark"); case Satellite: return GeoDataPlacemarkPrivate::tr("Satellite"); // OpenStreetMap categories case PlaceCity: return GeoDataPlacemarkPrivate::tr("City"); case PlaceCityCapital: return GeoDataPlacemarkPrivate::tr("City Capital"); case PlaceSuburb: return GeoDataPlacemarkPrivate::tr("Suburb"); case PlaceHamlet: return GeoDataPlacemarkPrivate::tr("Hamlet"); case PlaceLocality: return GeoDataPlacemarkPrivate::tr("Locality"); case PlaceTown: return GeoDataPlacemarkPrivate::tr("Town"); case PlaceTownCapital: return GeoDataPlacemarkPrivate::tr("Town Capital"); case PlaceVillage: return GeoDataPlacemarkPrivate::tr("Village"); case PlaceVillageCapital: return GeoDataPlacemarkPrivate::tr("Village Capital"); case NaturalWater: return GeoDataPlacemarkPrivate::tr("Water"); case NaturalReef: return GeoDataPlacemarkPrivate::tr("Reef"); case NaturalWood: return GeoDataPlacemarkPrivate::tr("Wood"); case NaturalBeach: return GeoDataPlacemarkPrivate::tr("Beach"); case NaturalWetland: return GeoDataPlacemarkPrivate::tr("Wetland"); case NaturalGlacier: return GeoDataPlacemarkPrivate::tr("Glacier"); case NaturalIceShelf: return GeoDataPlacemarkPrivate::tr("Ice Shelf"); case NaturalScrub: return GeoDataPlacemarkPrivate::tr("Scrub"); case NaturalCliff: return GeoDataPlacemarkPrivate::tr("Cliff"); case NaturalHeath: return GeoDataPlacemarkPrivate::tr("Heath"); case HighwayTrafficSignals: return GeoDataPlacemarkPrivate::tr("Traffic Signals"); case HighwaySteps: return GeoDataPlacemarkPrivate::tr("Steps"); case HighwayUnknown: return GeoDataPlacemarkPrivate::tr("Unknown Road"); case HighwayPath: return GeoDataPlacemarkPrivate::tr("Path"); case HighwayFootway: return GeoDataPlacemarkPrivate::tr("Footway"); case HighwayTrack: return GeoDataPlacemarkPrivate::tr("Track"); case HighwayPedestrian: return GeoDataPlacemarkPrivate::tr("Footway"); case HighwayCycleway: return GeoDataPlacemarkPrivate::tr("Cycleway"); case HighwayService: return GeoDataPlacemarkPrivate::tr("Service Road"); case HighwayRoad: return GeoDataPlacemarkPrivate::tr("Road"); case HighwayResidential: return GeoDataPlacemarkPrivate::tr("Residential Road"); case HighwayLivingStreet: return GeoDataPlacemarkPrivate::tr("Living Street"); case HighwayUnclassified: return GeoDataPlacemarkPrivate::tr("Unclassified Road"); case HighwayTertiaryLink: return GeoDataPlacemarkPrivate::tr("Tertiary Link Road"); case HighwayTertiary: return GeoDataPlacemarkPrivate::tr("Tertiary Road"); case HighwaySecondaryLink: return GeoDataPlacemarkPrivate::tr("Secondary Link Road"); case HighwaySecondary: return GeoDataPlacemarkPrivate::tr("Secondary Road"); case HighwayPrimaryLink: return GeoDataPlacemarkPrivate::tr("Primary Link Road"); case HighwayPrimary: return GeoDataPlacemarkPrivate::tr("Primary Road"); case HighwayTrunkLink: return GeoDataPlacemarkPrivate::tr("Trunk Link Road"); case HighwayTrunk: return GeoDataPlacemarkPrivate::tr("Trunk Road"); case HighwayMotorwayLink: return GeoDataPlacemarkPrivate::tr("Motorway Link Road"); case HighwayMotorway: return GeoDataPlacemarkPrivate::tr("Motorway"); case Building: return GeoDataPlacemarkPrivate::tr("Building"); case AccomodationCamping: return GeoDataPlacemarkPrivate::tr("Camping"); case AccomodationHostel: return GeoDataPlacemarkPrivate::tr("Hostel"); case AccomodationHotel: return GeoDataPlacemarkPrivate::tr("Hotel"); case AccomodationMotel: return GeoDataPlacemarkPrivate::tr("Motel"); case AccomodationYouthHostel: return GeoDataPlacemarkPrivate::tr("Youth Hostel"); case AccomodationGuestHouse: return GeoDataPlacemarkPrivate::tr("Guest House"); case AmenityLibrary: return GeoDataPlacemarkPrivate::tr("Library"); case AmenityKindergarten: return GeoDataPlacemarkPrivate::tr("Kindergarten"); case EducationCollege: return GeoDataPlacemarkPrivate::tr("College"); case EducationSchool: return GeoDataPlacemarkPrivate::tr("School"); case EducationUniversity: return GeoDataPlacemarkPrivate::tr("University"); case FoodBar: return GeoDataPlacemarkPrivate::tr("Bar"); case FoodBiergarten: return GeoDataPlacemarkPrivate::tr("Biergarten"); case FoodCafe: return GeoDataPlacemarkPrivate::tr("Cafe"); case FoodFastFood: return GeoDataPlacemarkPrivate::tr("Fast Food"); case FoodPub: return GeoDataPlacemarkPrivate::tr("Pub"); case FoodRestaurant: return GeoDataPlacemarkPrivate::tr("Restaurant"); case HealthDentist: return GeoDataPlacemarkPrivate::tr("Dentist"); case HealthDoctors: return GeoDataPlacemarkPrivate::tr("Doctors"); case HealthHospital: return GeoDataPlacemarkPrivate::tr("Hospital"); case HealthPharmacy: return GeoDataPlacemarkPrivate::tr("Pharmacy"); case HealthVeterinary: return GeoDataPlacemarkPrivate::tr("Veterinary"); case MoneyAtm: return GeoDataPlacemarkPrivate::tr("ATM"); case MoneyBank: return GeoDataPlacemarkPrivate::tr("Bank"); case AmenityArchaeologicalSite: return GeoDataPlacemarkPrivate::tr("Archaeological Site"); case AmenityEmbassy: return GeoDataPlacemarkPrivate::tr("Embassy"); case AmenityEmergencyPhone: return GeoDataPlacemarkPrivate::tr("Emergency Phone"); case AmenityWaterPark: return GeoDataPlacemarkPrivate::tr("Water Park"); case AmenityCommunityCentre: return GeoDataPlacemarkPrivate::tr("Community Centre"); case AmenityFountain: return GeoDataPlacemarkPrivate::tr("Fountain"); case AmenityNightClub: return GeoDataPlacemarkPrivate::tr("Night Club"); case AmenityBench: return GeoDataPlacemarkPrivate::tr("Bench"); case AmenityCourtHouse: return GeoDataPlacemarkPrivate::tr("Court House"); case AmenityFireStation: return GeoDataPlacemarkPrivate::tr("Fire Station"); case AmenityHuntingStand: return GeoDataPlacemarkPrivate::tr("Hunting Stand"); case AmenityPolice: return GeoDataPlacemarkPrivate::tr("Police"); case AmenityPostBox: return GeoDataPlacemarkPrivate::tr("Post Box"); case AmenityPostOffice: return GeoDataPlacemarkPrivate::tr("Post Office"); case AmenityPrison: return GeoDataPlacemarkPrivate::tr("Prison"); case AmenityRecycling: return GeoDataPlacemarkPrivate::tr("Recycling"); case AmenityShelter: return GeoDataPlacemarkPrivate::tr("Shelter"); case AmenityTelephone: return GeoDataPlacemarkPrivate::tr("Telephone"); case AmenityToilets: return GeoDataPlacemarkPrivate::tr("Toilets"); case AmenityTownHall: return GeoDataPlacemarkPrivate::tr("Town Hall"); case AmenityWasteBasket: return GeoDataPlacemarkPrivate::tr("Waste Basket"); case AmenityDrinkingWater: return GeoDataPlacemarkPrivate::tr("Drinking Water"); case AmenityGraveyard: return GeoDataPlacemarkPrivate::tr("Graveyard"); case BarrierCityWall: return GeoDataPlacemarkPrivate::tr("City Wall"); case BarrierGate: return GeoDataPlacemarkPrivate::tr("Gate"); case BarrierLiftGate: return GeoDataPlacemarkPrivate::tr("Lift Gate"); case BarrierWall: return GeoDataPlacemarkPrivate::tr("Wall"); case NaturalPeak: return GeoDataPlacemarkPrivate::tr("Peak"); case NaturalTree: return GeoDataPlacemarkPrivate::tr("Tree"); case ShopBeverages: return GeoDataPlacemarkPrivate::tr("Beverages"); case ShopHifi: return GeoDataPlacemarkPrivate::tr("Hifi"); case ShopSupermarket: return GeoDataPlacemarkPrivate::tr("Supermarket"); case ShopAlcohol: return GeoDataPlacemarkPrivate::tr("Alcohol"); case ShopBakery: return GeoDataPlacemarkPrivate::tr("Bakery"); case ShopButcher: return GeoDataPlacemarkPrivate::tr("Butcher"); case ShopConfectionery: return GeoDataPlacemarkPrivate::tr("Confectionery"); case ShopConvenience: return GeoDataPlacemarkPrivate::tr("Convenience Shop"); case ShopGreengrocer: return GeoDataPlacemarkPrivate::tr("Greengrocer"); case ShopSeafood: return GeoDataPlacemarkPrivate::tr("Seafood"); case ShopDepartmentStore: return GeoDataPlacemarkPrivate::tr("Department Store"); case ShopKiosk: return GeoDataPlacemarkPrivate::tr("Kiosk"); case ShopBag: return GeoDataPlacemarkPrivate::tr("Bag"); case ShopClothes: return GeoDataPlacemarkPrivate::tr("Clothes"); case ShopFashion: return GeoDataPlacemarkPrivate::tr("Fashion"); case ShopJewelry: return GeoDataPlacemarkPrivate::tr("Jewelry"); case ShopShoes: return GeoDataPlacemarkPrivate::tr("Shoes"); case ShopVarietyStore: return GeoDataPlacemarkPrivate::tr("Variety Store"); case ShopBeauty: return GeoDataPlacemarkPrivate::tr("Beauty"); case ShopChemist: return GeoDataPlacemarkPrivate::tr("Chemist"); case ShopCosmetics: return GeoDataPlacemarkPrivate::tr("Cosmetics"); case ShopHairdresser: return GeoDataPlacemarkPrivate::tr("Hairdresser"); case ShopOptician: return GeoDataPlacemarkPrivate::tr("Optician"); case ShopPerfumery: return GeoDataPlacemarkPrivate::tr("Perfumery"); case ShopDoitYourself: return GeoDataPlacemarkPrivate::tr("Doit Yourself"); case ShopFlorist: return GeoDataPlacemarkPrivate::tr("Florist"); case ShopHardware: return GeoDataPlacemarkPrivate::tr("Hardware"); case ShopFurniture: return GeoDataPlacemarkPrivate::tr("Furniture"); case ShopElectronics: return GeoDataPlacemarkPrivate::tr("Electronics"); case ShopMobilePhone: return GeoDataPlacemarkPrivate::tr("Mobile Phone"); case ShopBicycle: return GeoDataPlacemarkPrivate::tr("Bicycle"); case ShopCar: return GeoDataPlacemarkPrivate::tr("Car"); case ShopCarRepair: return GeoDataPlacemarkPrivate::tr("Car Repair"); case ShopCarParts: return GeoDataPlacemarkPrivate::tr("Car Parts"); case ShopMotorcycle: return GeoDataPlacemarkPrivate::tr("Motorcycle"); case ShopOutdoor: return GeoDataPlacemarkPrivate::tr("Outdoor"); case ShopMusicalInstrument: return GeoDataPlacemarkPrivate::tr("Musical Instrument"); case ShopPhoto: return GeoDataPlacemarkPrivate::tr("Photo"); case ShopBook: return GeoDataPlacemarkPrivate::tr("Book"); case ShopGift: return GeoDataPlacemarkPrivate::tr("Gift"); case ShopStationery: return GeoDataPlacemarkPrivate::tr("Stationery"); case ShopLaundry: return GeoDataPlacemarkPrivate::tr("Laundry"); case ShopPet: return GeoDataPlacemarkPrivate::tr("Pet"); case ShopToys: return GeoDataPlacemarkPrivate::tr("Toys"); case ShopTravelAgency: return GeoDataPlacemarkPrivate::tr("Travel Agency"); case Shop: return GeoDataPlacemarkPrivate::tr("Shop"); case ManmadeBridge: return GeoDataPlacemarkPrivate::tr("Bridge"); case ManmadeLighthouse: return GeoDataPlacemarkPrivate::tr("Lighthouse"); case ManmadePier: return GeoDataPlacemarkPrivate::tr("Pier"); case ManmadeWaterTower: return GeoDataPlacemarkPrivate::tr("Water Tower"); case ManmadeWindMill: return GeoDataPlacemarkPrivate::tr("Wind Mill"); case TouristAttraction: return GeoDataPlacemarkPrivate::tr("Tourist Attraction"); case TouristCastle: return GeoDataPlacemarkPrivate::tr("Castle"); case TouristCinema: return GeoDataPlacemarkPrivate::tr("Cinema"); case TouristInformation: return GeoDataPlacemarkPrivate::tr("Information"); case TouristMonument: return GeoDataPlacemarkPrivate::tr("Monument"); case TouristMuseum: return GeoDataPlacemarkPrivate::tr("Museum"); case TouristRuin: return GeoDataPlacemarkPrivate::tr("Ruin"); case TouristTheatre: return GeoDataPlacemarkPrivate::tr("Theatre"); case TouristThemePark: return GeoDataPlacemarkPrivate::tr("Theme Park"); case TouristViewPoint: return GeoDataPlacemarkPrivate::tr("View Point"); case TouristZoo: return GeoDataPlacemarkPrivate::tr("Zoo"); case TouristAlpineHut: return GeoDataPlacemarkPrivate::tr("Alpine Hut"); case TransportAerodrome: return GeoDataPlacemarkPrivate::tr("Aerodrome"); case TransportHelipad: return GeoDataPlacemarkPrivate::tr("Helipad"); case TransportAirportGate: return GeoDataPlacemarkPrivate::tr("Airport Gate"); case TransportAirportRunway: return GeoDataPlacemarkPrivate::tr("Airport Runway"); case TransportAirportApron: return GeoDataPlacemarkPrivate::tr("Airport Apron"); case TransportAirportTaxiway: return GeoDataPlacemarkPrivate::tr("Airport Taxiway"); case TransportAirportTerminal: return GeoDataPlacemarkPrivate::tr("Airport Terminal"); case TransportBusStation: return GeoDataPlacemarkPrivate::tr("Bus Station"); case TransportBusStop: return GeoDataPlacemarkPrivate::tr("Bus Stop"); case TransportCarShare: return GeoDataPlacemarkPrivate::tr("Car Sharing"); case TransportFuel: return GeoDataPlacemarkPrivate::tr("Gas Station"); case TransportParking: return GeoDataPlacemarkPrivate::tr("Parking"); case TransportParkingSpace: return GeoDataPlacemarkPrivate::tr("Parking Space"); case TransportPlatform: return GeoDataPlacemarkPrivate::tr("Platform"); case TransportRentalBicycle: return GeoDataPlacemarkPrivate::tr("Rental Bicycle"); case TransportRentalCar: return GeoDataPlacemarkPrivate::tr("Rental Car"); case TransportTaxiRank: return GeoDataPlacemarkPrivate::tr("Taxi Rank"); case TransportTrainStation: return GeoDataPlacemarkPrivate::tr("Train Station"); case TransportTramStop: return GeoDataPlacemarkPrivate::tr("Tram Stop"); case TransportBicycleParking: return GeoDataPlacemarkPrivate::tr("Bicycle Parking"); case TransportMotorcycleParking: return GeoDataPlacemarkPrivate::tr("Motorcycle Parking"); case TransportSubwayEntrance: return GeoDataPlacemarkPrivate::tr("Subway Entrance"); case ReligionPlaceOfWorship: return GeoDataPlacemarkPrivate::tr("Place Of Worship"); case ReligionBahai: return GeoDataPlacemarkPrivate::tr("Bahai"); case ReligionBuddhist: return GeoDataPlacemarkPrivate::tr("Buddhist"); case ReligionChristian: return GeoDataPlacemarkPrivate::tr("Christian"); case ReligionMuslim: return GeoDataPlacemarkPrivate::tr("Muslim"); case ReligionHindu: return GeoDataPlacemarkPrivate::tr("Hindu"); case ReligionJain: return GeoDataPlacemarkPrivate::tr("Jain"); case ReligionJewish: return GeoDataPlacemarkPrivate::tr("Jewish"); case ReligionShinto: return GeoDataPlacemarkPrivate::tr("Shinto"); case ReligionSikh: return GeoDataPlacemarkPrivate::tr("Sikh"); case LeisureGolfCourse: return GeoDataPlacemarkPrivate::tr("Golf Course"); case LeisureMarina: return GeoDataPlacemarkPrivate::tr("Marina"); case LeisurePark: return GeoDataPlacemarkPrivate::tr("Park"); case LeisurePlayground: return GeoDataPlacemarkPrivate::tr("Playground"); case LeisurePitch: return GeoDataPlacemarkPrivate::tr("Pitch"); case LeisureSportsCentre: return GeoDataPlacemarkPrivate::tr("Sports Centre"); case LeisureStadium: return GeoDataPlacemarkPrivate::tr("Stadium"); case LeisureTrack: return GeoDataPlacemarkPrivate::tr("Track"); case LeisureSwimmingPool: return GeoDataPlacemarkPrivate::tr("Swimming Pool"); case LanduseAllotments: return GeoDataPlacemarkPrivate::tr("Allotments"); case LanduseBasin: return GeoDataPlacemarkPrivate::tr("Basin"); case LanduseCemetery: return GeoDataPlacemarkPrivate::tr("Cemetery"); case LanduseCommercial: return GeoDataPlacemarkPrivate::tr("Commercial"); case LanduseConstruction: return GeoDataPlacemarkPrivate::tr("Construction"); case LanduseFarmland: return GeoDataPlacemarkPrivate::tr("Farmland"); case LanduseFarmyard: return GeoDataPlacemarkPrivate::tr("Farmyard"); case LanduseGarages: return GeoDataPlacemarkPrivate::tr("Garages"); case LanduseGrass: return GeoDataPlacemarkPrivate::tr("Grass"); case LanduseIndustrial: return GeoDataPlacemarkPrivate::tr("Industrial"); case LanduseLandfill: return GeoDataPlacemarkPrivate::tr("Landfill"); case LanduseMeadow: return GeoDataPlacemarkPrivate::tr("Meadow"); case LanduseMilitary: return GeoDataPlacemarkPrivate::tr("Military"); case LanduseQuarry: return GeoDataPlacemarkPrivate::tr("Quarry"); case LanduseRailway: return GeoDataPlacemarkPrivate::tr("Railway"); case LanduseReservoir: return GeoDataPlacemarkPrivate::tr("Reservoir"); case LanduseResidential: return GeoDataPlacemarkPrivate::tr("Residential"); case LanduseRetail: return GeoDataPlacemarkPrivate::tr("Retail"); case LanduseOrchard: return GeoDataPlacemarkPrivate::tr("Orchard"); case LanduseVineyard: return GeoDataPlacemarkPrivate::tr("Vineyard"); case RailwayRail: return GeoDataPlacemarkPrivate::tr("Rail"); case RailwayNarrowGauge: return GeoDataPlacemarkPrivate::tr("Narrow Gauge"); case RailwayTram: return GeoDataPlacemarkPrivate::tr("Tram"); case RailwayLightRail: return GeoDataPlacemarkPrivate::tr("Light Rail"); case RailwayAbandoned: return GeoDataPlacemarkPrivate::tr("Abandoned Railway"); case RailwaySubway: return GeoDataPlacemarkPrivate::tr("Subway"); case RailwayPreserved: return GeoDataPlacemarkPrivate::tr("Preserved Railway"); case RailwayMiniature: return GeoDataPlacemarkPrivate::tr("Miniature Railway"); case RailwayConstruction: return GeoDataPlacemarkPrivate::tr("Railway Construction"); case RailwayMonorail: return GeoDataPlacemarkPrivate::tr("Monorail"); case RailwayFunicular: return GeoDataPlacemarkPrivate::tr("Funicular Railway"); case PowerTower: return GeoDataPlacemarkPrivate::tr("Power Tower"); case AdminLevel1: return GeoDataPlacemarkPrivate::tr("Admin Boundary (Level 1)"); case AdminLevel2: return GeoDataPlacemarkPrivate::tr("Admin Boundary (Level 2)"); case AdminLevel3: return GeoDataPlacemarkPrivate::tr("Admin Boundary (Level 3)"); case AdminLevel4: return GeoDataPlacemarkPrivate::tr("Admin Boundary (Level 4)"); case AdminLevel5: return GeoDataPlacemarkPrivate::tr("Admin Boundary (Level 5)"); case AdminLevel6: return GeoDataPlacemarkPrivate::tr("Admin Boundary (Level 6)"); case AdminLevel7: return GeoDataPlacemarkPrivate::tr("Admin Boundary (Level 7)"); case AdminLevel8: return GeoDataPlacemarkPrivate::tr("Admin Boundary (Level 8)"); case AdminLevel9: return GeoDataPlacemarkPrivate::tr("Admin Boundary (Level 9)"); case AdminLevel10: return GeoDataPlacemarkPrivate::tr("Admin Boundary (Level 10)"); case AdminLevel11: return GeoDataPlacemarkPrivate::tr("Admin Boundary (Level 11)"); case BoundaryMaritime: return GeoDataPlacemarkPrivate::tr("Boundary (Maritime)"); case Landmass: return GeoDataPlacemarkPrivate::tr("Land Mass"); case UrbanArea: return GeoDataPlacemarkPrivate::tr("Urban Area"); case InternationalDateLine: return GeoDataPlacemarkPrivate::tr("International Date Line"); case Bathymetry: return GeoDataPlacemarkPrivate::tr("Bathymetry"); case Default: case Unknown: case None: case LastIndex: return QString(); } return QString(); } qreal GeoDataPlacemark::area() const { - return p()->m_placemarkExtendedData ? p()->m_placemarkExtendedData->m_area : -1.0; + Q_D(const GeoDataPlacemark); + return d->m_placemarkExtendedData ? d->m_placemarkExtendedData->m_area : -1.0; } void GeoDataPlacemark::setArea( qreal area ) { - if (area == -1.0 && !p()->m_placemarkExtendedData) { + if (area == -1.0 && !d_func()->m_placemarkExtendedData) { return; // nothing to do } detach(); - p()->m_geometry->setParent( this ); - p()->placemarkExtendedData().m_area = area; + + Q_D(GeoDataPlacemark); + d->m_geometry->setParent(this); + d->placemarkExtendedData().m_area = area; } qint64 GeoDataPlacemark::population() const { - return p()->m_population; + Q_D(const GeoDataPlacemark); + return d->m_population; } void GeoDataPlacemark::setPopulation( qint64 population ) { detach(); - p()->m_geometry->setParent( this ); - p()->m_population = population; + + Q_D(GeoDataPlacemark); + d->m_geometry->setParent(this); + d->m_population = population; } const QString GeoDataPlacemark::state() const { - return p()->m_placemarkExtendedData ? p()->m_placemarkExtendedData->m_state : QString(); + Q_D(const GeoDataPlacemark); + return d->m_placemarkExtendedData ? d->m_placemarkExtendedData->m_state : QString(); } void GeoDataPlacemark::setState( const QString &state ) { - if (state.isEmpty() && !p()->m_placemarkExtendedData) { + if (state.isEmpty() && !d_func()->m_placemarkExtendedData) { return; // nothing to do } detach(); - p()->m_geometry->setParent( this ); - p()->placemarkExtendedData().m_state = state; + + Q_D(GeoDataPlacemark); + d->m_geometry->setParent(this); + d->placemarkExtendedData().m_state = state; } const QString GeoDataPlacemark::countryCode() const { - return p()->m_placemarkExtendedData ? p()->m_placemarkExtendedData->m_countrycode : QString(); + Q_D(const GeoDataPlacemark); + return d->m_placemarkExtendedData ? d->m_placemarkExtendedData->m_countrycode : QString(); } void GeoDataPlacemark::setCountryCode( const QString &countrycode ) { - if (countrycode.isEmpty() && !p()->m_placemarkExtendedData) { + if (countrycode.isEmpty() && !d_func()->m_placemarkExtendedData) { return; // nothing to do } detach(); - p()->m_geometry->setParent( this ); - p()->placemarkExtendedData().m_countrycode = countrycode; + + Q_D(GeoDataPlacemark); + d->m_geometry->setParent(this); + d->placemarkExtendedData().m_countrycode = countrycode; } bool GeoDataPlacemark::isBalloonVisible() const { - return p()->m_placemarkExtendedData ? p()->m_placemarkExtendedData->m_isBalloonVisible : false; + Q_D(const GeoDataPlacemark); + return d->m_placemarkExtendedData ? d->m_placemarkExtendedData->m_isBalloonVisible : false; } void GeoDataPlacemark::setBalloonVisible( bool visible ) { - if (!visible && !p()->m_placemarkExtendedData) { + if (!visible && !d_func()->m_placemarkExtendedData) { return; // nothing to do } detach(); - p()->m_geometry->setParent( this ); - p()->placemarkExtendedData().m_isBalloonVisible = visible; + + Q_D(GeoDataPlacemark); + d->m_geometry->setParent(this); + d->placemarkExtendedData().m_isBalloonVisible = visible; } void GeoDataPlacemark::pack( QDataStream& stream ) const { + Q_D(const GeoDataPlacemark); GeoDataFeature::pack( stream ); - stream << p()->placemarkExtendedData().m_countrycode; - stream << p()->placemarkExtendedData().m_area; - stream << p()->m_population; - if ( p()->m_geometry ) - { - stream << p()->m_geometry->geometryId(); - p()->m_geometry->pack( stream ); + stream << d->placemarkExtendedData().m_countrycode; + stream << d->placemarkExtendedData().m_area; + stream << d->m_population; + if (d->m_geometry) { + stream << d->m_geometry->geometryId(); + d->m_geometry->pack( stream ); } else { stream << InvalidGeometryId; } } QXmlStreamWriter& GeoDataPlacemark::pack( QXmlStreamWriter& stream ) const { stream.writeStartElement( "placemark" ); stream.writeEndElement(); return stream; } QXmlStreamWriter& GeoDataPlacemark::operator <<( QXmlStreamWriter& stream ) const { pack( stream ); return stream; } void GeoDataPlacemark::unpack( QDataStream& stream ) { detach(); - p()->m_geometry->setParent( this ); + + Q_D(GeoDataPlacemark); + // TODO: check if this should be done after the switch + d->m_geometry->setParent(this); GeoDataFeature::unpack( stream ); - stream >> p()->placemarkExtendedData().m_countrycode; - stream >> p()->placemarkExtendedData().m_area; - stream >> p()->m_population; + stream >> d->placemarkExtendedData().m_countrycode; + stream >> d->placemarkExtendedData().m_area; + stream >> d->m_population; int geometryId; stream >> geometryId; switch( geometryId ) { case InvalidGeometryId: break; case GeoDataPointId: { GeoDataPoint* point = new GeoDataPoint; point->unpack( stream ); - delete p()->m_geometry; - p()->m_geometry = point; + delete d->m_geometry; + d->m_geometry = point; } break; case GeoDataLineStringId: { GeoDataLineString* lineString = new GeoDataLineString; lineString->unpack( stream ); - delete p()->m_geometry; - p()->m_geometry = lineString; + delete d->m_geometry; + d->m_geometry = lineString; } break; case GeoDataLinearRingId: { GeoDataLinearRing* linearRing = new GeoDataLinearRing; linearRing->unpack( stream ); - delete p()->m_geometry; - p()->m_geometry = linearRing; + delete d->m_geometry; + d->m_geometry = linearRing; } break; case GeoDataPolygonId: { GeoDataPolygon* polygon = new GeoDataPolygon; polygon->unpack( stream ); - delete p()->m_geometry; - p()->m_geometry = polygon; + delete d->m_geometry; + d->m_geometry = polygon; } break; case GeoDataMultiGeometryId: { GeoDataMultiGeometry* multiGeometry = new GeoDataMultiGeometry; multiGeometry->unpack( stream ); - delete p()->m_geometry; - p()->m_geometry = multiGeometry; + delete d->m_geometry; + d->m_geometry = multiGeometry; } break; case GeoDataModelId: break; default: break; }; } } diff --git a/src/lib/marble/geodata/data/GeoDataPlacemark.h b/src/lib/marble/geodata/data/GeoDataPlacemark.h index 0ffdbf508..f2b3007c1 100644 --- a/src/lib/marble/geodata/data/GeoDataPlacemark.h +++ b/src/lib/marble/geodata/data/GeoDataPlacemark.h @@ -1,636 +1,635 @@ // // 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 2006-2007 Torsten Rahn // Copyright 2007 Inge Wallin // Copyright 2008-2009 Patrick Spendrin // #ifndef MARBLE_GEODATAPLACEMARK_H #define MARBLE_GEODATAPLACEMARK_H #include #include "GeoDataCoordinates.h" #include "GeoDataFeature.h" #include "geodata_export.h" class QXmlStreamWriter; namespace Marble { class GeoDataPlacemarkPrivate; class OsmPlacemarkData; class GeoDataLookAt; class GeoDataPolygon; class GeoDataGeometry; /** * @short a class representing a point of interest on the map * * This class represents a point of interest, e.g. a city or a * mountain. It is filled with data by the KML or GPX loader and the * PlacemarkModel makes use of it. * * A Placemark can have an associated geometry which will be rendered to the map * along with the placemark's point icon. If you would like to render more than * one geometry for any one placemark than use @see setGeometry() to set add a * @see MultiGeometry. * * This is more or less only a GeoDataFeature with a geographic * position and a country code attached to it. The country code is * not provided in a KML file. */ class GEODATA_EXPORT GeoDataPlacemark: public GeoDataFeature { public: /** * Create a new placemark. */ GeoDataPlacemark(); /** * Create a new placemark from existing placemark @p placemark */ GeoDataPlacemark( const GeoDataPlacemark& placemark ); /** * Create a new placemark with the given @p name. */ explicit GeoDataPlacemark( const QString &name ); /** * Delete the placemark */ ~GeoDataPlacemark(); GeoDataPlacemark &operator=( const GeoDataPlacemark &other ); /** * Equality operators. */ bool operator==( const GeoDataPlacemark& other ) const; bool operator!=( const GeoDataPlacemark& other ) const; /** * @brief A categorization of a placemark as defined by ...FIXME. * There is an additional osm tag mapping to GeoDataVisualCategory * in OsmPlacemarkData */ enum GeoDataVisualCategory { None, Default, Unknown, // The order of the cities needs to stay fixed as the // algorithms rely on that. SmallCity, SmallCountyCapital, SmallStateCapital, SmallNationCapital, MediumCity, MediumCountyCapital, MediumStateCapital, MediumNationCapital, BigCity, BigCountyCapital, BigStateCapital, BigNationCapital, LargeCity, LargeCountyCapital, LargeStateCapital, LargeNationCapital, Nation, // Terrain Mountain, Volcano, Mons, // m Valley, // v Continent, Ocean, OtherTerrain, // o // Space Terrain Crater, // c Mare, // a // Places of Interest GeographicPole, MagneticPole, ShipWreck, AirPort, Observatory, // Military MilitaryDangerArea, // Runners OsmSite, Coordinate, // Planets MannedLandingSite, // h RoboticRover, // r UnmannedSoftLandingSite, // u UnmannedHardLandingSite, // i Bookmark, Satellite, /* * Start of OpenStreetMap categories */ PlaceCity, PlaceCityCapital, PlaceSuburb, PlaceHamlet, PlaceLocality, PlaceTown, PlaceTownCapital, PlaceVillage, PlaceVillageCapital, NaturalWater, NaturalReef, NaturalWood, NaturalBeach, NaturalWetland, NaturalGlacier, NaturalIceShelf, NaturalScrub, NaturalCliff, NaturalHeath, HighwayTrafficSignals, // OpenStreetMap highways HighwaySteps, HighwayUnknown, HighwayPath, HighwayFootway, HighwayTrack, HighwayPedestrian, HighwayCycleway, HighwayService, HighwayRoad, HighwayResidential, HighwayLivingStreet, HighwayUnclassified, HighwayTertiaryLink, HighwayTertiary, HighwaySecondaryLink, HighwaySecondary, HighwayPrimaryLink, HighwayPrimary, HighwayTrunkLink, HighwayTrunk, HighwayMotorwayLink, HighwayMotorway, //OSM building Building, // OpenStreetMap category Accomodation AccomodationCamping, AccomodationHostel, AccomodationHotel, AccomodationMotel, AccomodationYouthHostel, AccomodationGuestHouse, // OpenStreetMap category Amenity AmenityLibrary, AmenityKindergarten, ///< @since 0.26.0 // OpenStreetMap category Education EducationCollege, EducationSchool, EducationUniversity, // OpenStreetMap category Food FoodBar, FoodBiergarten, FoodCafe, FoodFastFood, FoodPub, FoodRestaurant, // OpenStreetMap category Health HealthDentist, HealthDoctors, HealthHospital, HealthPharmacy, HealthVeterinary, // OpenStreetMap category Money MoneyAtm, MoneyBank, AmenityArchaeologicalSite, AmenityEmbassy, AmenityEmergencyPhone, AmenityWaterPark, AmenityCommunityCentre, AmenityFountain, AmenityNightClub, AmenityBench, AmenityCourtHouse, AmenityFireStation, AmenityHuntingStand, AmenityPolice, AmenityPostBox, AmenityPostOffice, AmenityPrison, AmenityRecycling, AmenityShelter, ///< @since 0.26.0 AmenityTelephone, AmenityToilets, AmenityTownHall, AmenityWasteBasket, AmenityDrinkingWater, AmenityGraveyard, // OpenStreetMap category Barrier BarrierCityWall, BarrierGate, BarrierLiftGate, BarrierWall, NaturalPeak, NaturalTree, // OpenStreetMap category Shopping ShopBeverages, ShopHifi, ShopSupermarket, ShopAlcohol, ShopBakery, ShopButcher, ShopConfectionery, ShopConvenience, ShopGreengrocer, ShopSeafood, ShopDepartmentStore, ShopKiosk, ShopBag, ShopClothes, ShopFashion, ShopJewelry, ShopShoes, ShopVarietyStore, ShopBeauty, ShopChemist, ShopCosmetics, ShopHairdresser, ShopOptician, ShopPerfumery, ShopDoitYourself, ShopFlorist, ShopHardware, ShopFurniture, ShopElectronics, ShopMobilePhone, ShopBicycle, ShopCar, ShopCarRepair, ShopCarParts, ShopMotorcycle, ShopOutdoor, ShopMusicalInstrument, ShopPhoto, ShopBook, ShopGift, ShopStationery, ShopLaundry, ShopPet, ShopToys, ShopTravelAgency, Shop, ManmadeBridge, ManmadeLighthouse, ManmadePier, ManmadeWaterTower, ManmadeWindMill, // OpenStreetMap category Tourist TouristAttraction, TouristCastle, TouristCinema, TouristInformation, TouristMonument, TouristMuseum, TouristRuin, TouristTheatre, TouristThemePark, TouristViewPoint, TouristZoo, TouristAlpineHut, // OpenStreetMap category Transport TransportAerodrome, TransportHelipad, TransportAirportTerminal, TransportAirportGate, ///< @since 0.26.0 TransportAirportRunway, ///< @since 0.26.0 TransportAirportTaxiway, ///< @since 0.26.0 TransportAirportApron, ///< @since 0.26.0 TransportBusStation, TransportBusStop, TransportCarShare, TransportFuel, TransportParking, TransportParkingSpace, TransportPlatform, TransportRentalBicycle, TransportRentalCar, TransportTaxiRank, TransportTrainStation, TransportTramStop, TransportBicycleParking, TransportMotorcycleParking, TransportSubwayEntrance, // OpenStreetMap category religion ReligionPlaceOfWorship, ReligionBahai, ReligionBuddhist, ReligionChristian, ReligionMuslim, ReligionHindu, ReligionJain, ReligionJewish, ReligionShinto, ReligionSikh, // OpenStreetMap category Leisure LeisureGolfCourse, LeisureMarina, ///< @since 0.26.0 LeisurePark, LeisurePlayground, LeisurePitch, LeisureSportsCentre, LeisureStadium, LeisureTrack, LeisureSwimmingPool, LanduseAllotments, LanduseBasin, LanduseCemetery, LanduseCommercial, LanduseConstruction, LanduseFarmland, LanduseFarmyard, LanduseGarages, LanduseGrass, LanduseIndustrial, LanduseLandfill, LanduseMeadow, LanduseMilitary, LanduseQuarry, LanduseRailway, LanduseReservoir, LanduseResidential, LanduseRetail, LanduseOrchard, LanduseVineyard, RailwayRail, RailwayNarrowGauge, RailwayTram, RailwayLightRail, RailwayAbandoned, RailwaySubway, RailwayPreserved, RailwayMiniature, RailwayConstruction, RailwayMonorail, RailwayFunicular, // OpenStreetMap category Power PowerTower, //Admin level tags for depicting boundary AdminLevel1, AdminLevel2, AdminLevel3, AdminLevel4, AdminLevel5, AdminLevel6, AdminLevel7, AdminLevel8, AdminLevel9, AdminLevel10, AdminLevel11, BoundaryMaritime, //Custom OSM Tags Landmass, UrbanArea, InternationalDateLine, Bathymetry, ///< @since 0.26.0 // Important: Make sure that this is always the last // item and just use it to specify the array size LastIndex }; /** * Return the symbol index of the placemark. */ GeoDataVisualCategory visualCategory() const; /** * Sets the symbol @p index of the placemark. * @param category the new category to be used. */ void setVisualCategory(GeoDataVisualCategory category); /** * Return the coordinates of the placemark at time @p dateTime as a GeoDataCoordinates * * The @p dateTime parameter should be used if the placemark geometry() is a * GeoDataTrack and thus contains several coordinates associated with a date and time. * * The @p iconAtCoordinates boolean is set to true if an icon should be drawn to * represent the placemark at these coordinates as described in * https://code.google.com/apis/kml/documentation/kmlreference.html#placemark, * it is set to false otherwise. * * @see GeoDataTrack::GeoDataTrack */ GeoDataCoordinates coordinate( const QDateTime &dateTime = QDateTime(), bool *iconAtCoordinates = 0 ) const; /** * The geometry of the GeoDataPlacemark is to be rendered to the marble map * along with the icon at the coordinate associated with this Placemark. * @return a pointer to the current Geometry object */ GeoDataGeometry* geometry(); const GeoDataGeometry* geometry() const; /** * @brief displays the name of a place in the locale language of the user */ QString displayName() const; /** * @since 0.26.0 */ QString categoryName() const; /** * Return the coordinates of the placemark as @p longitude, * @p latitude and @p altitude. */ void coordinate( qreal &longitude, qreal &latitude, qreal &altitude ) const; /** * Quick, safe accessor to the placemark's OsmPlacemarkData stored within it's * ExtendedData. If the extendedData does not contain osmData, the function * inserts a default-constructed one, and returns a reference to it. */ OsmPlacemarkData &osmData(); const OsmPlacemarkData &osmData() const; void setOsmData( const OsmPlacemarkData &osmData ); bool hasOsmData() const; /** * @since 0.26.0 */ void clearOsmData(); /** * Set the coordinate of the placemark in @p longitude and * @p latitude. */ void setCoordinate( qreal longitude, qreal latitude, qreal altitude = 0, GeoDataCoordinates::Unit _unit = GeoDataCoordinates::Radian ); /** * Set the coordinate of the placemark with an @p GeoDataPoint. */ void setCoordinate( const GeoDataCoordinates &coordinate ); /** * Sets the current Geometry of this Placemark. @see geometry() and the class * overview for description of the geometry concept. The geometry can be set * to any @see GeoDataGeometry like @see GeoDataPoint,@see GeoDataLineString, * @see GeoDataLinearRing and @see GeoDataMultiGeometry */ void setGeometry( GeoDataGeometry *entry ); /** * Return the area size of the feature in square km. * * FIXME: Once we make Marble more area-aware we need to * move this into the GeoDataArea class which will get * inherited from GeoDataPlacemark (or GeoDataFeature). */ qreal area() const; /** * Set the area size of the feature in square km. */ void setArea( qreal area ); /** * Return the population of the placemark. */ qint64 population() const; /** * Sets the @p population of the placemark. * @param population the new population value */ void setPopulation( qint64 population ); /** * Return the state of the placemark. */ const QString state() const; /** * Set the state @p state of the placemark. */ void setState( const QString &state ); /** * Return the country code of the placemark. */ const QString countryCode() const; /** * Set the country @p code of the placemark. */ void setCountryCode( const QString &code ); /** * Returns whether balloon is visible or not */ bool isBalloonVisible() const; /** * Set visibility of the balloon */ void setBalloonVisible( bool visible ); /** * Serialize the Placemark to a data stream. This is a binary serialisation * and is deserialised using @see unpack() * @param stream the QDataStream to serialise object to. */ virtual void pack( QDataStream& stream ) const; /** * Serialise this Placemark to a XML stream writer @see QXmlStreamWriter in * the Qt documentation for more info. This will output the XML * representation of this Placemark. The default XML format is KML, to have * other formats supported you need to create a subclass and override this * method. * @param stream the XML Stream Reader to output to. */ virtual QXmlStreamWriter& pack( QXmlStreamWriter& stream ) const; virtual QXmlStreamWriter& operator <<( QXmlStreamWriter& stream ) const; /** * Deserialize the Placemark from a data stream. This has the opposite effect * from @see pack() * @param stream the QDataStream to deserialise from. */ virtual void unpack( QDataStream& stream ); /** * Returns GeoDataLookAt object if lookAt is setup earlier * otherwise It will convert GeoDataCoordinates of Placemark * to GeoDataLookAt with range equals to altitude of * GeoDataCoordinate */ const GeoDataLookAt *lookAt() const; GeoDataLookAt *lookAt(); static bool placemarkLayoutOrderCompare(const GeoDataPlacemark *a, const GeoDataPlacemark* b); private: - inline GeoDataPlacemarkPrivate *p(); - inline const GeoDataPlacemarkPrivate *p() const; + Q_DECLARE_PRIVATE(GeoDataPlacemark) }; } #endif diff --git a/src/lib/marble/geodata/data/GeoDataPlacemark_p.h b/src/lib/marble/geodata/data/GeoDataPlacemark_p.h index c44937173..77db108c8 100644 --- a/src/lib/marble/geodata/data/GeoDataPlacemark_p.h +++ b/src/lib/marble/geodata/data/GeoDataPlacemark_p.h @@ -1,174 +1,175 @@ // // 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 2009 Patrick Spendrin // #ifndef MARBLE_GEODATAPLACEMARKPRIVATE_H #define MARBLE_GEODATAPLACEMARKPRIVATE_H #include "GeoDataFeature_p.h" #include "GeoDataPoint.h" #include "GeoDataLinearRing.h" #include "GeoDataPolygon.h" #include "GeoDataMultiTrack.h" #include "GeoDataTrack.h" #include "GeoDataTypes.h" #include "GeoDataMultiGeometry.h" #include "osm/OsmPlacemarkData.h" namespace Marble { class GeoDataPlacemarkExtendedData { public: GeoDataPlacemarkExtendedData() : m_area( -1.0 ), m_isBalloonVisible( false ) { // nothing to do } GeoDataPlacemarkExtendedData & operator=(const GeoDataPlacemarkExtendedData &other) { m_countrycode = other.m_countrycode; m_area = other.m_area; m_state = other.m_state; m_isBalloonVisible = other.m_isBalloonVisible; return *this; } bool operator==(const GeoDataPlacemarkExtendedData &other) const { return m_countrycode == other.m_countrycode && m_area == other.m_area && m_state == other.m_state; } QString m_countrycode; // Country code. qreal m_area; // Area in square kilometer QString m_state; // State bool m_isBalloonVisible; //Visibility of balloon }; class GeoDataPlacemarkPrivate : public GeoDataFeaturePrivate { Q_DECLARE_TR_FUNCTIONS(GeoDataPlacemark) public: GeoDataPlacemarkPrivate() : m_geometry(new GeoDataPoint), m_population( -1 ), m_placemarkExtendedData(nullptr), m_visualCategory(GeoDataPlacemark::Default) { } virtual ~GeoDataPlacemarkPrivate() { delete m_geometry; delete m_placemarkExtendedData; } GeoDataPlacemarkPrivate& operator=( const GeoDataPlacemarkPrivate& other ) { if ( this == &other ) { return *this; } GeoDataFeaturePrivate::operator=( other ); m_population = other.m_population; m_visualCategory = other.m_visualCategory; GeoDataGeometry * geometry = 0; if ( other.m_geometry ) { switch( other.m_geometry->geometryId() ) { case InvalidGeometryId: break; case GeoDataPointId: geometry = new GeoDataPoint( *static_cast( other.m_geometry ) ); break; case GeoDataLineStringId: geometry = new GeoDataLineString( *static_cast( other.m_geometry ) ); break; case GeoDataLinearRingId: geometry = new GeoDataLinearRing( *static_cast( other.m_geometry ) ); break; case GeoDataPolygonId: geometry = new GeoDataPolygon( *static_cast( other.m_geometry ) ); break; case GeoDataMultiGeometryId: geometry = new GeoDataMultiGeometry( *static_cast( other.m_geometry ) ); break; case GeoDataTrackId: geometry = new GeoDataTrack( *static_cast( other.m_geometry ) ); break; case GeoDataMultiTrackId: geometry = new GeoDataMultiTrack( *static_cast( other.m_geometry ) ); break; case GeoDataModelId: break; default: break; } } delete m_geometry; m_geometry = geometry; + // TODO: why not set parent here to geometry? delete m_placemarkExtendedData; m_placemarkExtendedData = nullptr; if (other.m_placemarkExtendedData) { m_placemarkExtendedData = new GeoDataPlacemarkExtendedData(*other.m_placemarkExtendedData); } return *this; } virtual GeoDataFeaturePrivate* copy() { GeoDataPlacemarkPrivate* copy = new GeoDataPlacemarkPrivate; *copy = *this; return copy; } virtual const char* nodeType() const { return GeoDataTypes::GeoDataPlacemarkType; } virtual EnumFeatureId featureId() const { return GeoDataPlacemarkId; } GeoDataPlacemarkExtendedData & placemarkExtendedData() { if (!m_placemarkExtendedData) { m_placemarkExtendedData = new GeoDataPlacemarkExtendedData; } return *m_placemarkExtendedData; } const GeoDataPlacemarkExtendedData & placemarkExtendedData() const { return m_placemarkExtendedData ? *m_placemarkExtendedData : s_nullPlacemarkExtendedData; } // Data for a Placemark in addition to those in GeoDataFeature. GeoDataGeometry *m_geometry; // any GeoDataGeometry entry like locations qint64 m_population; // population in number of inhabitants GeoDataPlacemarkExtendedData *m_placemarkExtendedData; GeoDataPlacemark::GeoDataVisualCategory m_visualCategory; // the visual category static const OsmPlacemarkData s_nullOsmPlacemarkData; static const GeoDataPlacemarkExtendedData s_nullPlacemarkExtendedData; }; } // namespace Marble #endif diff --git a/src/lib/marble/geodata/data/GeoDataTour.cpp b/src/lib/marble/geodata/data/GeoDataTour.cpp index 34973d09b..947ae85db 100644 --- a/src/lib/marble/geodata/data/GeoDataTour.cpp +++ b/src/lib/marble/geodata/data/GeoDataTour.cpp @@ -1,75 +1,71 @@ // // 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 Illya Kovalevskyy // #include "GeoDataTour.h" #include "GeoDataTour_p.h" namespace Marble { const GeoDataTour GeoDataTour::null; GeoDataTour::GeoDataTour() : GeoDataFeature( new GeoDataTourPrivate ) { // nothing to do } GeoDataTour::~GeoDataTour() { // nothing to do; } -GeoDataTourPrivate *GeoDataTour::p() -{ - return static_cast(d); -} - -const GeoDataTourPrivate *GeoDataTour::p() const -{ - return static_cast(d); -} - bool GeoDataTour::operator==(const GeoDataTour& other) const { + Q_D(const GeoDataTour); return equals( other ) && - *p()->m_playlist == *other.p()->m_playlist; + *d->m_playlist == *other.d_func()->m_playlist; } bool GeoDataTour::operator!=(const GeoDataTour& other) const { return !this->operator==(other); } GeoDataPlaylist* GeoDataTour::playlist() { detach(); - return p()->m_playlist; + + Q_D(GeoDataTour); + return d->m_playlist; } const GeoDataPlaylist* GeoDataTour::playlist() const { - return p()->m_playlist; + Q_D(const GeoDataTour); + return d->m_playlist; } void GeoDataTour::setPlaylist(GeoDataPlaylist *playlist) { detach(); - p()->m_playlist = playlist; - p()->m_playlist->setParent( this ); + + Q_D(GeoDataTour); + d->m_playlist = playlist; + d->m_playlist->setParent(this); } const char *GeoDataTour::nodeType() const { return GeoDataTypes::GeoDataTourType; } } // namespace Marble diff --git a/src/lib/marble/geodata/data/GeoDataTour.h b/src/lib/marble/geodata/data/GeoDataTour.h index b594b00a7..4b05e2a43 100644 --- a/src/lib/marble/geodata/data/GeoDataTour.h +++ b/src/lib/marble/geodata/data/GeoDataTour.h @@ -1,49 +1,48 @@ // // 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 Illya Kovalevskyy // #ifndef GEODATATOUR_H #define GEODATATOUR_H #include "GeoDataFeature.h" #include "geodata_export.h" namespace Marble { class GeoDataTourPrivate; class GeoDataPlaylist; class GeoDataSoundCue; class GEODATA_EXPORT GeoDataTour : public GeoDataFeature { public: GeoDataTour(); virtual ~GeoDataTour(); bool operator==(const GeoDataTour &other) const; bool operator!=(const GeoDataTour &other) const; GeoDataPlaylist* playlist(); const GeoDataPlaylist* playlist() const; void setPlaylist(GeoDataPlaylist* playlist); virtual const char* nodeType() const; static const GeoDataTour null; private: - GeoDataTourPrivate *p(); - const GeoDataTourPrivate *p() const; + Q_DECLARE_PRIVATE(GeoDataTour) }; } // namespace Marble #endif // GEODATATOUR_H