summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Nienhüser <nienhueser@kde.org>2016-09-11 16:08:52 (GMT)
committerDennis Nienhüser <nienhueser@kde.org>2016-09-11 16:08:52 (GMT)
commitdf9b850576a0d4b72b533ca4d6c454ca500a0758 (patch)
tree976174058c6707bbad3a10bfcc12ed2f8c46657c
parent6bf6d8881cfeed5f3d6152433bc9e1fcf821d94d (diff)
Reduce memory footprint of GeoDataPlacemark in the style of d7f36cb
-rw-r--r--src/lib/marble/geodata/data/GeoDataPlacemark.cpp57
-rw-r--r--src/lib/marble/geodata/data/GeoDataPlacemark_p.h65
2 files changed, 95 insertions, 27 deletions
diff --git a/src/lib/marble/geodata/data/GeoDataPlacemark.cpp b/src/lib/marble/geodata/data/GeoDataPlacemark.cpp
index 5087070..8083d91 100644
--- a/src/lib/marble/geodata/data/GeoDataPlacemark.cpp
+++ b/src/lib/marble/geodata/data/GeoDataPlacemark.cpp
@@ -33,6 +33,7 @@ namespace Marble
{
const OsmPlacemarkData GeoDataPlacemarkPrivate::s_nullOsmPlacemarkData = OsmPlacemarkData();
+const GeoDataPlacemarkExtendedData GeoDataPlacemarkPrivate::s_nullPlacemarkExtendedData = GeoDataPlacemarkExtendedData();
GeoDataPlacemark::GeoDataPlacemark()
: GeoDataFeature( new GeoDataPlacemarkPrivate )
@@ -72,11 +73,17 @@ GeoDataPlacemark &GeoDataPlacemark::operator=( const GeoDataPlacemark &other )
bool GeoDataPlacemark::operator==( const GeoDataPlacemark& other ) const
{
- if ( !equals(other) ||
- p()->m_countrycode != other.p()->m_countrycode ||
- p()->m_area != other.p()->m_area ||
- p()->m_population != other.p()->m_population ||
- p()->m_state != other.p()->m_state ) {
+ if (!equals(other) ||
+ p()->m_population != other.p()->m_population) {
+ return false;
+ }
+
+ if ((p()->m_placemarkExtendedData && !other.p()->m_placemarkExtendedData) ||
+ (!p()->m_placemarkExtendedData && other.p()->m_placemarkExtendedData)) {
+ return false;
+ }
+ if (p()->m_placemarkExtendedData && other.p()->m_placemarkExtendedData &&
+ !(*p()->m_placemarkExtendedData == *other.p()->m_placemarkExtendedData)) {
return false;
}
@@ -328,14 +335,18 @@ QString GeoDataPlacemark::displayName() const
qreal GeoDataPlacemark::area() const
{
- return p()->m_area;
+ return p()->m_placemarkExtendedData ? p()->m_placemarkExtendedData->m_area : -1.0;
}
void GeoDataPlacemark::setArea( qreal area )
{
+ if (area == -1.0 && !p()->m_placemarkExtendedData) {
+ return; // nothing to do
+ }
+
detach();
p()->m_geometry->setParent( this );
- p()->m_area = area;
+ p()->placemarkExtendedData().m_area = area;
}
qint64 GeoDataPlacemark::population() const
@@ -352,46 +363,58 @@ void GeoDataPlacemark::setPopulation( qint64 population )
const QString GeoDataPlacemark::state() const
{
- return p()->m_state;
+ return p()->m_placemarkExtendedData ? p()->m_placemarkExtendedData->m_state : QString();
}
void GeoDataPlacemark::setState( const QString &state )
{
+ if (state.isEmpty() && !p()->m_placemarkExtendedData) {
+ return; // nothing to do
+ }
+
detach();
p()->m_geometry->setParent( this );
- p()->m_state = state;
+ p()->placemarkExtendedData().m_state = state;
}
const QString GeoDataPlacemark::countryCode() const
{
- return p()->m_countrycode;
+ return p()->m_placemarkExtendedData ? p()->m_placemarkExtendedData->m_countrycode : QString();
}
void GeoDataPlacemark::setCountryCode( const QString &countrycode )
{
+ if (countrycode.isEmpty() && !p()->m_placemarkExtendedData) {
+ return; // nothing to do
+ }
+
detach();
p()->m_geometry->setParent( this );
- p()->m_countrycode = countrycode;
+ p()->placemarkExtendedData().m_countrycode = countrycode;
}
bool GeoDataPlacemark::isBalloonVisible() const
{
- return p()->m_isBalloonVisible;
+ return p()->m_placemarkExtendedData ? p()->m_placemarkExtendedData->m_isBalloonVisible : false;
}
void GeoDataPlacemark::setBalloonVisible( bool visible )
{
+ if (!visible && !p()->m_placemarkExtendedData) {
+ return; // nothing to do
+ }
+
detach();
p()->m_geometry->setParent( this );
- p()->m_isBalloonVisible = visible;
+ p()->placemarkExtendedData().m_isBalloonVisible = visible;
}
void GeoDataPlacemark::pack( QDataStream& stream ) const
{
GeoDataFeature::pack( stream );
- stream << p()->m_countrycode;
- stream << p()->m_area;
+ stream << p()->placemarkExtendedData().m_countrycode;
+ stream << p()->placemarkExtendedData().m_area;
stream << p()->m_population;
if ( p()->m_geometry )
{
@@ -424,8 +447,8 @@ void GeoDataPlacemark::unpack( QDataStream& stream )
p()->m_geometry->setParent( this );
GeoDataFeature::unpack( stream );
- stream >> p()->m_countrycode;
- stream >> p()->m_area;
+ stream >> p()->placemarkExtendedData().m_countrycode;
+ stream >> p()->placemarkExtendedData().m_area;
stream >> p()->m_population;
int geometryId;
stream >> geometryId;
diff --git a/src/lib/marble/geodata/data/GeoDataPlacemark_p.h b/src/lib/marble/geodata/data/GeoDataPlacemark_p.h
index c52bd85..3be8dfe 100644
--- a/src/lib/marble/geodata/data/GeoDataPlacemark_p.h
+++ b/src/lib/marble/geodata/data/GeoDataPlacemark_p.h
@@ -21,20 +21,51 @@
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
{
public:
GeoDataPlacemarkPrivate()
: m_geometry( new GeoDataPoint ),
- m_area( -1.0 ),
m_population( -1 ),
- m_isBalloonVisible( false )
+ m_placemarkExtendedData(nullptr)
{
}
virtual ~GeoDataPlacemarkPrivate()
{
delete m_geometry;
+ delete m_placemarkExtendedData;
}
GeoDataPlacemarkPrivate& operator=( const GeoDataPlacemarkPrivate& other )
@@ -44,6 +75,7 @@ class GeoDataPlacemarkPrivate : public GeoDataFeaturePrivate
}
GeoDataFeaturePrivate::operator=( other );
+ m_population = other.m_population;
GeoDataGeometry * geometry = 0;
if ( other.m_geometry ) {
@@ -79,10 +111,11 @@ class GeoDataPlacemarkPrivate : public GeoDataFeaturePrivate
delete m_geometry;
m_geometry = geometry;
- m_countrycode = other.m_countrycode;
- m_area = other.m_area;
- m_population = other.m_population;
- m_state = other.m_state;
+ delete m_placemarkExtendedData;
+ m_placemarkExtendedData = nullptr;
+ if (other.m_placemarkExtendedData) {
+ m_placemarkExtendedData = new GeoDataPlacemarkExtendedData(*other.m_placemarkExtendedData);
+ }
return *this;
}
@@ -104,15 +137,27 @@ class GeoDataPlacemarkPrivate : public GeoDataFeaturePrivate
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
- QString m_countrycode; // Country code.
- qreal m_area; // Area in square kilometer
qint64 m_population; // population in number of inhabitants
- QString m_state; // State
- bool m_isBalloonVisible; //Visibility of balloon
+ GeoDataPlacemarkExtendedData *m_placemarkExtendedData;
static const OsmPlacemarkData s_nullOsmPlacemarkData;
+ static const GeoDataPlacemarkExtendedData s_nullPlacemarkExtendedData;
};
} // namespace Marble