summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Nienhüser <nienhueser@kde.org>2016-07-23 13:15:02 (GMT)
committerDennis Nienhüser <nienhueser@kde.org>2016-07-23 14:10:40 (GMT)
commit47b59f9f029eabb60342a166f6621b8c040abda0 (patch)
tree5b932effd78a76a4483703073cd9cac5c7082bdd
parent0a8a426f05e364501ff3feb1580a4d31b138da75 (diff)
Const correct osm placemark data access.
-rw-r--r--src/lib/marble/geodata/data/GeoDataExtendedData.cpp5
-rw-r--r--src/lib/marble/geodata/data/GeoDataExtendedData.h2
-rw-r--r--src/lib/marble/geodata/data/GeoDataFeature.cpp9
-rw-r--r--src/lib/marble/geodata/data/GeoDataFeature.h3
-rw-r--r--src/lib/marble/geodata/data/GeoDataPlacemark.cpp21
-rw-r--r--src/lib/marble/geodata/data/GeoDataPlacemark.h1
-rw-r--r--src/lib/marble/geodata/data/GeoDataPlacemark_p.h3
7 files changed, 38 insertions, 6 deletions
diff --git a/src/lib/marble/geodata/data/GeoDataExtendedData.cpp b/src/lib/marble/geodata/data/GeoDataExtendedData.cpp
index 83299f4..cab72c1 100644
--- a/src/lib/marble/geodata/data/GeoDataExtendedData.cpp
+++ b/src/lib/marble/geodata/data/GeoDataExtendedData.cpp
@@ -73,6 +73,11 @@ void GeoDataExtendedData::addValue( const GeoDataData& data )
d->hash.insert( data.name(), data );
}
+void GeoDataExtendedData::removeKey(const QString &key)
+{
+ d->hash.remove(key);
+}
+
QHash< QString, GeoDataData >::const_iterator GeoDataExtendedData::constBegin( ) const
{
return d->hash.constBegin();
diff --git a/src/lib/marble/geodata/data/GeoDataExtendedData.h b/src/lib/marble/geodata/data/GeoDataExtendedData.h
index 1315add..2fc520e 100644
--- a/src/lib/marble/geodata/data/GeoDataExtendedData.h
+++ b/src/lib/marble/geodata/data/GeoDataExtendedData.h
@@ -58,6 +58,8 @@ class GEODATA_EXPORT GeoDataExtendedData : public GeoDataObject
* @brief add a data object to the GeoDataExtendedData with the @p key
*/
void addValue( const GeoDataData& data );
+
+ void removeKey(const QString &key);
/**
* @brief return const Begin iterator for QHash
diff --git a/src/lib/marble/geodata/data/GeoDataFeature.cpp b/src/lib/marble/geodata/data/GeoDataFeature.cpp
index 433ba3a..6283158 100644
--- a/src/lib/marble/geodata/data/GeoDataFeature.cpp
+++ b/src/lib/marble/geodata/data/GeoDataFeature.cpp
@@ -335,6 +335,11 @@ void GeoDataFeature::setTimeStamp( const GeoDataTimeStamp &timeStamp )
d->m_timeStamp = timeStamp;
}
+const GeoDataExtendedData &GeoDataFeature::extendedData() const
+{
+ return d->m_extendedData;
+}
+
GeoDataStyle::ConstPtr GeoDataFeature::style() const
{
if (d->m_style) {
@@ -357,9 +362,9 @@ void GeoDataFeature::setStyle( const GeoDataStyle::Ptr &style )
d->m_style = style;
}
-GeoDataExtendedData& GeoDataFeature::extendedData() const
+GeoDataExtendedData& GeoDataFeature::extendedData()
{
- // FIXME: Should call detach(). Maybe don't return reference.
+ detach();
return d->m_extendedData;
}
diff --git a/src/lib/marble/geodata/data/GeoDataFeature.h b/src/lib/marble/geodata/data/GeoDataFeature.h
index e36f751..6433d2a 100644
--- a/src/lib/marble/geodata/data/GeoDataFeature.h
+++ b/src/lib/marble/geodata/data/GeoDataFeature.h
@@ -549,7 +549,8 @@ class GEODATA_EXPORT GeoDataFeature : public GeoDataObject
/**
* Return the ExtendedData assigned to the feature.
*/
- GeoDataExtendedData& extendedData() const;
+ GeoDataExtendedData& extendedData();
+ const GeoDataExtendedData& extendedData() const;
/**
* Sets the ExtendedData of the feature.
diff --git a/src/lib/marble/geodata/data/GeoDataPlacemark.cpp b/src/lib/marble/geodata/data/GeoDataPlacemark.cpp
index 93e5efb..f5a087f 100644
--- a/src/lib/marble/geodata/data/GeoDataPlacemark.cpp
+++ b/src/lib/marble/geodata/data/GeoDataPlacemark.cpp
@@ -31,6 +31,9 @@
namespace Marble
{
+
+const OsmPlacemarkData GeoDataPlacemarkPrivate::s_nullOsmPlacemarkData = OsmPlacemarkData();
+
GeoDataPlacemark::GeoDataPlacemark()
: GeoDataFeature( new GeoDataPlacemarkPrivate )
{
@@ -180,8 +183,7 @@ const OsmPlacemarkData& GeoDataPlacemark::osmData() const
{
QVariant &placemarkVariantData = extendedData().valueRef( OsmPlacemarkData::osmHashKey() ).valueRef();
if ( !placemarkVariantData.canConvert<OsmPlacemarkData>() ) {
- extendedData().addValue( GeoDataData( OsmPlacemarkData::osmHashKey(), QVariant::fromValue( OsmPlacemarkData() ) ) );
- placemarkVariantData = extendedData().valueRef( OsmPlacemarkData::osmHashKey() ).valueRef();
+ return p()->s_nullOsmPlacemarkData;
}
OsmPlacemarkData &osmData = *reinterpret_cast<OsmPlacemarkData*>( placemarkVariantData.data() );
@@ -195,7 +197,14 @@ void GeoDataPlacemark::setOsmData( const OsmPlacemarkData &osmData )
OsmPlacemarkData& GeoDataPlacemark::osmData()
{
- return const_cast<OsmPlacemarkData&>( (static_cast<const GeoDataPlacemark*>(this) )->osmData() );
+ QVariant &placemarkVariantData = extendedData().valueRef( OsmPlacemarkData::osmHashKey() ).valueRef();
+ if ( !placemarkVariantData.canConvert<OsmPlacemarkData>() ) {
+ extendedData().addValue( GeoDataData( OsmPlacemarkData::osmHashKey(), QVariant::fromValue( OsmPlacemarkData() ) ) );
+ placemarkVariantData = extendedData().valueRef( OsmPlacemarkData::osmHashKey() ).valueRef();
+ }
+
+ OsmPlacemarkData &osmData = *reinterpret_cast<OsmPlacemarkData*>( placemarkVariantData.data() );
+ return osmData;
}
bool GeoDataPlacemark::hasOsmData() const
@@ -204,6 +213,12 @@ bool GeoDataPlacemark::hasOsmData() const
return placemarkVariantData.canConvert<OsmPlacemarkData>();
}
+void GeoDataPlacemark::clearOsmData()
+{
+ detach();
+ extendedData().removeKey(OsmPlacemarkData::osmHashKey());
+}
+
const GeoDataLookAt *GeoDataPlacemark::lookAt() const
{
return dynamic_cast<const GeoDataLookAt*>( abstractView() );
diff --git a/src/lib/marble/geodata/data/GeoDataPlacemark.h b/src/lib/marble/geodata/data/GeoDataPlacemark.h
index 62a1aa1..9a49c99 100644
--- a/src/lib/marble/geodata/data/GeoDataPlacemark.h
+++ b/src/lib/marble/geodata/data/GeoDataPlacemark.h
@@ -127,6 +127,7 @@ class GEODATA_EXPORT GeoDataPlacemark: public GeoDataFeature
void setOsmData( const OsmPlacemarkData &osmData );
bool hasOsmData() const;
+ void clearOsmData();
/**
* Set the coordinate of the placemark in @p longitude and
diff --git a/src/lib/marble/geodata/data/GeoDataPlacemark_p.h b/src/lib/marble/geodata/data/GeoDataPlacemark_p.h
index b4c1ee1..c52bd85 100644
--- a/src/lib/marble/geodata/data/GeoDataPlacemark_p.h
+++ b/src/lib/marble/geodata/data/GeoDataPlacemark_p.h
@@ -16,6 +16,7 @@
#include "GeoDataMultiTrack.h"
#include "GeoDataTrack.h"
#include "GeoDataTypes.h"
+#include "osm/OsmPlacemarkData.h"
namespace Marble
{
@@ -110,6 +111,8 @@ class GeoDataPlacemarkPrivate : public GeoDataFeaturePrivate
qint64 m_population; // population in number of inhabitants
QString m_state; // State
bool m_isBalloonVisible; //Visibility of balloon
+
+ static const OsmPlacemarkData s_nullOsmPlacemarkData;
};
} // namespace Marble