Skip to content

Commit

Permalink
Don't cache context along with QgsCoordinateTransforms
Browse files Browse the repository at this point in the history
This information should not be restored from the cache, since
it's project specific yet the cache is not
  • Loading branch information
nyalldawson committed Dec 18, 2017
1 parent 25c3e13 commit 9ba1d28
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
44 changes: 33 additions & 11 deletions src/core/qgscoordinatetransform.cpp
Expand Up @@ -65,9 +65,10 @@ QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateReferenceSyst

QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination, const QgsCoordinateTransformContext &context )
{
d = new QgsCoordinateTransformPrivate( source, destination, context );
mContext = context;
d = new QgsCoordinateTransformPrivate( source, destination, mContext );
#ifdef QGISDEBUG
d->mHasContext = true;
mHasContext = true;
#endif

if ( !d->checkValidity() )
Expand All @@ -82,9 +83,11 @@ QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateReferenceSyst

QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination, const QgsProject *project )
{
d = new QgsCoordinateTransformPrivate( source, destination, project ? project->transformContext() : QgsCoordinateTransformContext() );
mContext = project ? project->transformContext() : QgsCoordinateTransformContext();
d = new QgsCoordinateTransformPrivate( source, destination, mContext );
#ifdef QGISDEBUG
d->mHasContext = true;
if ( project )
mHasContext = true;
#endif

if ( !d->checkValidity() )
Expand All @@ -101,7 +104,7 @@ QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateReferenceSyst
{
d = new QgsCoordinateTransformPrivate( source, destination, sourceDatumTransform, destinationDatumTransform );
#ifdef QGISDEBUG
d->mHasContext = true; // not strictly true, but we don't need to worry if datums have been explicitly set
mHasContext = true; // not strictly true, but we don't need to worry if datums have been explicitly set
#endif

if ( !d->checkValidity() )
Expand All @@ -115,13 +118,21 @@ QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateReferenceSyst
}

QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateTransform &o )
: mContext( o.mContext )
#ifdef QGISDEBUG
, mHasContext( o.mHasContext )
#endif
{
d = o.d;
}

QgsCoordinateTransform &QgsCoordinateTransform::operator=( const QgsCoordinateTransform &o ) //NOLINT
{
d = o.d;
#ifdef QGISDEBUG
mHasContext = o.mHasContext;
#endif
mContext = o.mContext;
return *this;
}

Expand All @@ -134,7 +145,7 @@ void QgsCoordinateTransform::setSourceCrs( const QgsCoordinateReferenceSystem &c
if ( !d->checkValidity() )
return;

d->calculateTransforms();
d->calculateTransforms( mContext );
if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mSourceDatumTransform, d->mDestinationDatumTransform ) )
{
d->initialize();
Expand All @@ -148,7 +159,7 @@ void QgsCoordinateTransform::setDestinationCrs( const QgsCoordinateReferenceSyst
if ( !d->checkValidity() )
return;

d->calculateTransforms();
d->calculateTransforms( mContext );
if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mSourceDatumTransform, d->mDestinationDatumTransform ) )
{
d->initialize();
Expand All @@ -159,14 +170,14 @@ void QgsCoordinateTransform::setDestinationCrs( const QgsCoordinateReferenceSyst
void QgsCoordinateTransform::setContext( const QgsCoordinateTransformContext &context )
{
d.detach();
d->mContext = context;
mContext = context;
#ifdef QGISDEBUG
d->mHasContext = true;
mHasContext = true;
#endif
if ( !d->checkValidity() )
return;

d->calculateTransforms();
d->calculateTransforms( mContext );
if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mSourceDatumTransform, d->mDestinationDatumTransform ) )
{
d->initialize();
Expand Down Expand Up @@ -575,7 +586,7 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
#endif

#ifdef QGISDEBUG
if ( !d->mHasContext )
if ( !mHasContext )
qWarning( "No QgsCoordinateTransformContext context set for transform" );
#endif

Expand Down Expand Up @@ -792,8 +803,19 @@ bool QgsCoordinateTransform::setFromCache( const QgsCoordinateReferenceSystem &s
if ( ( *valIt ).sourceDatumTransformId() == srcDatumTransform &&
( *valIt ).destinationDatumTransformId() == destDatumTransform )
{
// need to save, and then restore the context... we don't want this to be cached or to use the values from the cache
QgsCoordinateTransformContext context = mContext;
#ifdef QGISDEBUG
bool hasContext = mHasContext;
#endif
*this = *valIt;
sCacheLock.unlock();

mContext = context;
#ifdef QGISDEBUG
mHasContext = hasContext;
#endif

return true;
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/core/qgscoordinatetransform.h
Expand Up @@ -22,12 +22,12 @@
#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgscoordinatereferencesystem.h"
#include "qgscoordinatetransformcontext.h"

class QgsCoordinateTransformPrivate;
class QgsPointXY;
class QgsRectangle;
class QPolygonF;
class QgsCoordinateTransformContext;
class QgsProject;

/**
Expand Down Expand Up @@ -410,6 +410,13 @@ class CORE_EXPORT QgsCoordinateTransform

mutable QExplicitlySharedDataPointer<QgsCoordinateTransformPrivate> d;

//! Transform context
QgsCoordinateTransformContext mContext;

#ifdef QGISDEBUG
bool mHasContext = false;
#endif

bool setFromCache( const QgsCoordinateReferenceSystem &src,
const QgsCoordinateReferenceSystem &dest,
int srcDatumTransform,
Expand Down
7 changes: 1 addition & 6 deletions src/core/qgscoordinatetransform_p.cpp
Expand Up @@ -55,10 +55,9 @@ QgsCoordinateTransformPrivate::QgsCoordinateTransformPrivate( const QgsCoordinat
const QgsCoordinateTransformContext &context )
: mSourceCRS( source )
, mDestCRS( destination )
, mContext( context )
{
setFinder();
calculateTransforms();
calculateTransforms( context );
}

QgsCoordinateTransformPrivate::QgsCoordinateTransformPrivate( const QgsCoordinateReferenceSystem &source, const QgsCoordinateReferenceSystem &destination, int sourceDatumTransform, int destDatumTransform )
Expand All @@ -76,10 +75,6 @@ QgsCoordinateTransformPrivate::QgsCoordinateTransformPrivate( const QgsCoordinat
, mShortCircuit( other.mShortCircuit )
, mSourceCRS( other.mSourceCRS )
, mDestCRS( other.mDestCRS )
, mContext( other.mContext )
#ifdef QGISDEBUG
, mHasContext( other.mHasContext )
#endif
, mSourceDatumTransform( other.mSourceDatumTransform )
, mDestinationDatumTransform( other.mDestinationDatumTransform )
{
Expand Down
9 changes: 1 addition & 8 deletions src/core/qgscoordinatetransform_p.h
Expand Up @@ -87,7 +87,7 @@ class QgsCoordinateTransformPrivate : public QSharedData

bool initialize();

void calculateTransforms();
void calculateTransforms( const QgsCoordinateTransformContext &context );

QPair< projPJ, projPJ > threadLocalProjData();

Expand All @@ -109,13 +109,6 @@ class QgsCoordinateTransformPrivate : public QSharedData
//! QgsCoordinateReferenceSystem of the destination (map canvas) coordinate system
QgsCoordinateReferenceSystem mDestCRS;

//! Transform context
QgsCoordinateTransformContext mContext;

#ifdef QGISDEBUG
bool mHasContext = false;
#endif

QString mSourceProjString;
QString mDestProjString;

Expand Down
1 change: 1 addition & 0 deletions src/core/qgscoordinatetransformcontext.cpp
Expand Up @@ -17,6 +17,7 @@

#include "qgscoordinatetransformcontext.h"
#include "qgscoordinatetransformcontext_p.h"
#include "qgscoordinatetransform.h"
#include "qgssettings.h"

QgsCoordinateTransformContext::QgsCoordinateTransformContext()
Expand Down

0 comments on commit 9ba1d28

Please sign in to comment.