Commit 3e280f90 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

Qt'fy access to pimpl objects: use macros Q_DECLARE_PRIVATE & Q_D

Summary:
* enforces constness some more
  (see issue spotted with GeoDataTrack::extendedData())
* delivers inline-ness of the access methods
* code should be more familiar to Qt developers

Reviewers: #marble, nienhueser

Reviewed By: #marble, nienhueser

Subscribers: nienhueser

Differential Revision: https://phabricator.kde.org/D2951
parent 92e6692c
......@@ -28,102 +28,102 @@ namespace Marble
{
GeoDataGeometry::GeoDataGeometry()
: d( new GeoDataGeometryPrivate() )
: d_ptr(new GeoDataGeometryPrivate())
{
d->ref.ref();
d_ptr->ref.ref();
}
GeoDataGeometry::GeoDataGeometry( const GeoDataGeometry& other )
: GeoDataObject(),
d( other.d )
d_ptr(other.d_ptr)
{
d->ref.ref();
d_ptr->ref.ref();
}
GeoDataGeometry::GeoDataGeometry( GeoDataGeometryPrivate* priv )
: GeoDataObject(),
d( priv )
d_ptr(priv)
{
d->ref.ref();
d_ptr->ref.ref();
}
GeoDataGeometry::~GeoDataGeometry()
{
if (!d->ref.deref())
delete d;
if (!d_ptr->ref.deref())
delete d_ptr;
}
void GeoDataGeometry::detach()
{
if(d->ref.load() == 1) {
if(d_ptr->ref.load() == 1) {
return;
}
GeoDataGeometryPrivate* new_d = d->copy();
GeoDataGeometryPrivate* new_d = d_ptr->copy();
if (!d->ref.deref())
delete d;
if (!d_ptr->ref.deref())
delete d_ptr;
d = new_d;
d->ref.ref();
d_ptr = new_d;
d_ptr->ref.ref();
}
const char* GeoDataGeometry::nodeType() const
{
return d->nodeType();
return d_ptr->nodeType();
}
EnumGeometryId GeoDataGeometry::geometryId() const
{
return d->geometryId();
return d_ptr->geometryId();
}
GeoDataGeometry& GeoDataGeometry::operator=( const GeoDataGeometry& other )
{
GeoDataObject::operator=( 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 GeoDataGeometry::extrude() const
{
return d->m_extrude;
return d_ptr->m_extrude;
}
void GeoDataGeometry::setExtrude( bool extrude )
{
detach();
d->m_extrude = extrude;
d_ptr->m_extrude = extrude;
}
AltitudeMode GeoDataGeometry::altitudeMode() const
{
return d->m_altitudeMode;
return d_ptr->m_altitudeMode;
}
void GeoDataGeometry::setAltitudeMode( const AltitudeMode altitudeMode )
{
detach();
d->m_altitudeMode = altitudeMode;
d_ptr->m_altitudeMode = altitudeMode;
}
const GeoDataLatLonAltBox& GeoDataGeometry::latLonAltBox() const
{
return d->m_latLonAltBox;
return d_ptr->m_latLonAltBox;
}
void GeoDataGeometry::pack( QDataStream& stream ) const
{
GeoDataObject::pack( stream );
stream << d->m_extrude;
stream << d->m_altitudeMode;
stream << d_ptr->m_extrude;
stream << d_ptr->m_altitudeMode;
}
void GeoDataGeometry::unpack( QDataStream& stream )
......@@ -132,16 +132,16 @@ void GeoDataGeometry::unpack( QDataStream& stream )
GeoDataObject::unpack( stream );
int am;
stream >> d->m_extrude;
stream >> d_ptr->m_extrude;
stream >> am;
d->m_altitudeMode = (AltitudeMode) am;
d_ptr->m_altitudeMode = (AltitudeMode) am;
}
bool GeoDataGeometry::equals(const GeoDataGeometry &other) const
{
return GeoDataObject::equals(other) &&
d->m_extrude == other.d->m_extrude &&
d->m_altitudeMode == other.d->m_altitudeMode;
d_ptr->m_extrude == other.d_ptr->m_extrude &&
d_ptr->m_altitudeMode == other.d_ptr->m_altitudeMode;
}
}
......@@ -76,7 +76,7 @@ class GEODATA_EXPORT GeoDataGeometry : public GeoDataObject
using GeoDataObject::equals;
protected:
GeoDataGeometryPrivate *d;
GeoDataGeometryPrivate *d_ptr;
};
}
......
......@@ -48,16 +48,6 @@ GeoDataLineString::~GeoDataLineString()
#endif
}
GeoDataLineStringPrivate* GeoDataLineString::p()
{
return static_cast<GeoDataLineStringPrivate*>(d);
}
const GeoDataLineStringPrivate* GeoDataLineString::p() const
{
return static_cast<GeoDataLineStringPrivate*>(d);
}
void GeoDataLineStringPrivate::interpolateDateLine( const GeoDataCoordinates & previousCoords,
const GeoDataCoordinates & currentCoords,
GeoDataCoordinates & previousAtDateLine,
......@@ -279,100 +269,123 @@ void GeoDataLineStringPrivate::optimize (GeoDataLineString& lineString) const
bool GeoDataLineString::isEmpty() const
{
return p()->m_vector.isEmpty();
Q_D(const GeoDataLineString);
return d->m_vector.isEmpty();
}
int GeoDataLineString::size() const
{
return p()->m_vector.size();
Q_D(const GeoDataLineString);
return d->m_vector.size();
}
GeoDataCoordinates& GeoDataLineString::at( int pos )
{
GeoDataGeometry::detach();
p()->m_dirtyRange = true;
p()->m_dirtyBox = true;
return p()->m_vector[ pos ];
Q_D(GeoDataLineString);
d->m_dirtyRange = true;
d->m_dirtyBox = true;
return d->m_vector[pos];
}
const GeoDataCoordinates& GeoDataLineString::at( int pos ) const
{
return p()->m_vector.at( pos );
Q_D(const GeoDataLineString);
return d->m_vector.at(pos);
}
GeoDataCoordinates& GeoDataLineString::operator[]( int pos )
{
GeoDataGeometry::detach();
p()->m_dirtyRange = true;
p()->m_dirtyBox = true;
return p()->m_vector[ pos ];
Q_D(GeoDataLineString);
d->m_dirtyRange = true;
d->m_dirtyBox = true;
return d->m_vector[pos];
}
const GeoDataCoordinates& GeoDataLineString::operator[]( int pos ) const
{
return static_cast<GeoDataLineStringPrivate*>(d)->m_vector[ pos ];
Q_D(const GeoDataLineString);
return d->m_vector[pos];
}
GeoDataCoordinates& GeoDataLineString::last()
{
GeoDataGeometry::detach();
p()->m_dirtyRange = true;
p()->m_dirtyBox = true;
return p()->m_vector.last();
Q_D(GeoDataLineString);
d->m_dirtyRange = true;
d->m_dirtyBox = true;
return d->m_vector.last();
}
GeoDataCoordinates& GeoDataLineString::first()
{
GeoDataGeometry::detach();
return p()->m_vector.first();
Q_D(GeoDataLineString);
return d->m_vector.first();
}
const GeoDataCoordinates& GeoDataLineString::last() const
{
return p()->m_vector.last();
Q_D(const GeoDataLineString);
return d->m_vector.last();
}
const GeoDataCoordinates& GeoDataLineString::first() const
{
return p()->m_vector.first();
Q_D(const GeoDataLineString);
return d->m_vector.first();
}
QVector<GeoDataCoordinates>::Iterator GeoDataLineString::begin()
{
GeoDataGeometry::detach();
return p()->m_vector.begin();
Q_D(GeoDataLineString);
return d->m_vector.begin();
}
QVector<GeoDataCoordinates>::ConstIterator GeoDataLineString::begin() const
{
return p()->m_vector.constBegin();
Q_D(const GeoDataLineString);
return d->m_vector.constBegin();
}
QVector<GeoDataCoordinates>::Iterator GeoDataLineString::end()
{
GeoDataGeometry::detach();
return p()->m_vector.end();
Q_D(GeoDataLineString);
return d->m_vector.end();
}
QVector<GeoDataCoordinates>::ConstIterator GeoDataLineString::end() const
{
return p()->m_vector.constEnd();
Q_D(const GeoDataLineString);
return d->m_vector.constEnd();
}
QVector<GeoDataCoordinates>::ConstIterator GeoDataLineString::constBegin() const
{
return p()->m_vector.constBegin();
Q_D(const GeoDataLineString);
return d->m_vector.constBegin();
}
QVector<GeoDataCoordinates>::ConstIterator GeoDataLineString::constEnd() const
{
return p()->m_vector.constEnd();
Q_D(const GeoDataLineString);
return d->m_vector.constEnd();
}
void GeoDataLineString::insert( int index, const GeoDataCoordinates& value )
{
GeoDataGeometry::detach();
GeoDataLineStringPrivate* d = p();
Q_D(GeoDataLineString);
delete d->m_rangeCorrected;
d->m_rangeCorrected = 0;
d->m_dirtyRange = true;
......@@ -383,7 +396,8 @@ void GeoDataLineString::insert( int index, const GeoDataCoordinates& value )
void GeoDataLineString::append ( const GeoDataCoordinates& value )
{
GeoDataGeometry::detach();
GeoDataLineStringPrivate* d = p();
Q_D(GeoDataLineString);
delete d->m_rangeCorrected;
d->m_rangeCorrected = 0;
d->m_dirtyRange = true;
......@@ -394,7 +408,8 @@ void GeoDataLineString::append ( const GeoDataCoordinates& value )
void GeoDataLineString::append(const QVector<GeoDataCoordinates>& values)
{
GeoDataGeometry::detach();
GeoDataLineStringPrivate* d = p();
Q_D(GeoDataLineString);
delete d->m_rangeCorrected;
d->m_rangeCorrected = 0;
d->m_dirtyRange = true;
......@@ -413,7 +428,8 @@ void GeoDataLineString::append(const QVector<GeoDataCoordinates>& values)
GeoDataLineString& GeoDataLineString::operator << ( const GeoDataCoordinates& value )
{
GeoDataGeometry::detach();
GeoDataLineStringPrivate* d = p();
Q_D(GeoDataLineString);
delete d->m_rangeCorrected;
d->m_rangeCorrected = 0;
d->m_dirtyRange = true;
......@@ -425,7 +441,8 @@ GeoDataLineString& GeoDataLineString::operator << ( const GeoDataCoordinates& va
GeoDataLineString& GeoDataLineString::operator << ( const GeoDataLineString& value )
{
GeoDataGeometry::detach();
GeoDataLineStringPrivate* d = p();
Q_D(GeoDataLineString);
delete d->m_rangeCorrected;
d->m_rangeCorrected = 0;
d->m_dirtyRange = true;
......@@ -450,8 +467,8 @@ bool GeoDataLineString::operator==( const GeoDataLineString &other ) const
return false;
}
const GeoDataLineStringPrivate* d = p();
const GeoDataLineStringPrivate* other_d = other.p();
Q_D(const GeoDataLineString);
const GeoDataLineStringPrivate* other_d = other.d_func();
QVector<GeoDataCoordinates>::const_iterator itCoords = d->m_vector.constBegin();
QVector<GeoDataCoordinates>::const_iterator otherItCoords = other_d->m_vector.constBegin();
......@@ -476,7 +493,8 @@ bool GeoDataLineString::operator!=( const GeoDataLineString &other ) const
void GeoDataLineString::clear()
{
GeoDataGeometry::detach();
GeoDataLineStringPrivate* d = p();
Q_D(GeoDataLineString);
delete d->m_rangeCorrected;
d->m_rangeCorrected = 0;
d->m_dirtyRange = true;
......@@ -492,40 +510,48 @@ bool GeoDataLineString::isClosed() const
bool GeoDataLineString::tessellate() const
{
return p()->m_tessellationFlags.testFlag(Tessellate);
Q_D(const GeoDataLineString);
return d->m_tessellationFlags.testFlag(Tessellate);
}
void GeoDataLineString::setTessellate( bool tessellate )
{
GeoDataGeometry::detach();
Q_D(GeoDataLineString);
// According to the KML reference the tesselation of line strings in Google Earth
// is generally done along great circles. However for subsequent points that share
// the same latitude the latitude circles are followed. Our Tesselate and RespectLatitude
// Flags provide this behaviour. For true polygons the latitude circles don't get considered.
if ( tessellate ) {
p()->m_tessellationFlags |= Tessellate;
p()->m_tessellationFlags |= RespectLatitudeCircle;
d->m_tessellationFlags |= Tessellate;
d->m_tessellationFlags |= RespectLatitudeCircle;
} else {
p()->m_tessellationFlags ^= Tessellate;
p()->m_tessellationFlags ^= RespectLatitudeCircle;
d->m_tessellationFlags ^= Tessellate;
d->m_tessellationFlags ^= RespectLatitudeCircle;
}
}
TessellationFlags GeoDataLineString::tessellationFlags() const
{
return p()->m_tessellationFlags;
Q_D(const GeoDataLineString);
return d->m_tessellationFlags;
}
void GeoDataLineString::setTessellationFlags( TessellationFlags f )
{
p()->m_tessellationFlags = f;
GeoDataGeometry::detach();
Q_D(GeoDataLineString);
d->m_tessellationFlags = f;
}
void GeoDataLineString::reverse()
{
GeoDataGeometry::detach();
GeoDataLineStringPrivate* d = p();
Q_D(GeoDataLineString);
delete d->m_rangeCorrected;
d->m_rangeCorrected = 0;
d->m_dirtyRange = true;
......@@ -535,6 +561,8 @@ void GeoDataLineString::reverse()
GeoDataLineString GeoDataLineString::toNormalized() const
{
Q_D(const GeoDataLineString);
GeoDataLineString normalizedLineString;
normalizedLineString.setTessellationFlags( tessellationFlags() );
......@@ -544,9 +572,9 @@ GeoDataLineString GeoDataLineString::toNormalized() const
// FIXME: Think about how we can avoid unnecessary copies
// if the linestring stays the same.
QVector<GeoDataCoordinates>::const_iterator end = p()->m_vector.constEnd();
QVector<GeoDataCoordinates>::const_iterator end = d->m_vector.constEnd();
for( QVector<GeoDataCoordinates>::const_iterator itCoords
= p()->m_vector.constBegin();
= d->m_vector.constBegin();
itCoords != end;
++itCoords ) {
......@@ -564,39 +592,45 @@ GeoDataLineString GeoDataLineString::toNormalized() const
GeoDataLineString GeoDataLineString::toRangeCorrected() const
{
if ( p()->m_dirtyRange ) {
Q_D(const GeoDataLineString);
if (d->m_dirtyRange) {
delete p()->m_rangeCorrected;
delete d->m_rangeCorrected;
if( isClosed() ) {
p()->m_rangeCorrected = new GeoDataLinearRing( toPoleCorrected() );
d->m_rangeCorrected = new GeoDataLinearRing(toPoleCorrected());
} else {
p()->m_rangeCorrected = new GeoDataLineString( toPoleCorrected() );
d->m_rangeCorrected = new GeoDataLineString(toPoleCorrected());
}
p()->m_dirtyRange = false;
d->m_dirtyRange = false;
}
return *p()->m_rangeCorrected;
return *d->m_rangeCorrected;
}
QVector<GeoDataLineString*> GeoDataLineString::toDateLineCorrected() const
{
Q_D(const GeoDataLineString);
QVector<GeoDataLineString*> lineStrings;
p()->toDateLineCorrected( *this, lineStrings );
d->toDateLineCorrected(*this, lineStrings);
return lineStrings;
}
GeoDataLineString GeoDataLineString::toPoleCorrected() const
{
Q_D(const GeoDataLineString);
if( isClosed() ) {
GeoDataLinearRing poleCorrected;
p()->toPoleCorrected( *this, poleCorrected );
d->toPoleCorrected(*this, poleCorrected);
return poleCorrected;
} else {
GeoDataLineString poleCorrected;
p()->toPoleCorrected( *this, poleCorrected );
d->toPoleCorrected(*this, poleCorrected);
return poleCorrected;
}
}
......@@ -768,16 +802,18 @@ void GeoDataLineStringPrivate::toDateLineCorrected(
const GeoDataLatLonAltBox& GeoDataLineString::latLonAltBox() const
{
Q_D(const GeoDataLineString);
// GeoDataLatLonAltBox::fromLineString is very expensive
// that's why we recreate it only if the m_dirtyBox
// is TRUE.
// DO NOT REMOVE THIS CONSTRUCT OR MARBLE WILL BE SLOW.
if ( p()->m_dirtyBox ) {
p()->m_latLonAltBox = GeoDataLatLonAltBox::fromLineString( *this );
if (d->m_dirtyBox) {
d->m_latLonAltBox = GeoDataLatLonAltBox::fromLineString(*this);
d->m_dirtyBox = false;
}
p()->m_dirtyBox = false;
return p()->m_latLonAltBox;
return d->m_latLonAltBox;
}
qreal GeoDataLineString::length( qreal planetRadius, int offset ) const
......@@ -786,10 +822,11 @@ qreal GeoDataLineString::length( qreal planetRadius, int offset ) const
return 0;
}
Q_D(const GeoDataLineString);
qreal length = 0.0;
QVector<GeoDataCoordinates> const & vector = p()->m_vector;
QVector<GeoDataCoordinates> const & vector = d->m_vector;
int const start = qMax(offset+1, 1);
int const end = p()->m_vector.size();
int const end = d->m_vector.size();
for( int i=start; i<end; ++i )
{
length += distanceSphere( vector[i-1], vector[i] );
......@@ -801,7 +838,8 @@ qreal GeoDataLineString::length( qreal planetRadius, int offset ) const
QVector<GeoDataCoordinates>::Iterator GeoDataLineString::erase ( QVector<GeoDataCoordinates>::Iterator pos )
{
GeoDataGeometry::detach();
GeoDataLineStringPrivate* d = p();
Q_D(GeoDataLineString);
delete d->m_rangeCorrected;
d->m_rangeCorrected = 0;
d->m_dirtyRange = true;
......@@ -813,7 +851,8 @@ QVector<GeoDataCoordinates>::Iterator GeoDataLineString::erase ( QVector<GeoData
QVector<GeoDataCoordinates>::Iterator end )
{
GeoDataGeometry::detach();
GeoDataLineStringPrivate* d = p();
Q_D(GeoDataLineString);
delete d->m_rangeCorrected;
d->m_rangeCorrected = 0;
d->m_dirtyRange = true;
......@@ -824,7 +863,8 @@ QVector<GeoDataCoordinates>::Iterator GeoDataLineString::erase ( QVector<GeoData
void GeoDataLineString::remove ( int i )
{
GeoDataGeometry::detach();
GeoDataLineStringPrivate* d = p();
Q_D(GeoDataLineString);
d->m_dirtyRange = true;
d->m_dirtyBox = true;
d->m_vector.remove( i );
......@@ -832,29 +872,33 @@ void GeoDataLineString::remove ( int i )
GeoDataLineString GeoDataLineString::optimized () const
{
Q_D(const GeoDataLineString);
if( isClosed() ) {
GeoDataLinearRing linearRing(*this);
p()->optimize(linearRing);
d->optimize(linearRing);
return linearRing;
} else {
GeoDataLineString lineString(*this);
p()->optimize(lineString);
d->optimize(lineString);
return lineString;
}
}
void GeoDataLineString::pack( QDataStream& stream ) const
{
Q_D(const GeoDataLineString);
GeoDataGeometry::pack( stream );
stream <