Skip to content

Commit

Permalink
Fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 15, 2017
1 parent 1422d53 commit 40e551d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/core/qgscoordinatetransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateReferenceSyst
{
d = new QgsCoordinateTransformPrivate( source, destination, QgsCoordinateTransformContext() );

if ( !d->mSourceCRS.isValid() || !d->mDestCRS.isValid() )
if ( !d->checkValidity() )
return;

if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mSourceDatumTransform, d->mDestinationDatumTransform ) )
Expand All @@ -70,7 +70,7 @@ QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateReferenceSyst
d->mHasContext = true;
#endif

if ( !d->mSourceCRS.isValid() || !d->mDestCRS.isValid() )
if ( !d->checkValidity() )
return;

if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mSourceDatumTransform, d->mDestinationDatumTransform ) )
Expand All @@ -87,7 +87,7 @@ QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateReferenceSyst
d->mHasContext = true;
#endif

if ( !d->mSourceCRS.isValid() || !d->mDestCRS.isValid() )
if ( !d->checkValidity() )
return;

if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mSourceDatumTransform, d->mDestinationDatumTransform ) )
Expand All @@ -104,7 +104,7 @@ QgsCoordinateTransform::QgsCoordinateTransform( const QgsCoordinateReferenceSyst
d->mHasContext = true; // not strictly true, but we don't need to worry if datums have been explicitly set
#endif

if ( !d->mSourceCRS.isValid() || !d->mDestCRS.isValid() )
if ( !d->checkValidity() )
return;

if ( !setFromCache( d->mSourceCRS, d->mDestCRS, d->mSourceDatumTransform, d->mDestinationDatumTransform ) )
Expand All @@ -131,7 +131,7 @@ void QgsCoordinateTransform::setSourceCrs( const QgsCoordinateReferenceSystem &c
{
d.detach();
d->mSourceCRS = crs;
if ( !d->mSourceCRS.isValid() || !d->mDestCRS.isValid() )
if ( !d->checkValidity() )
return;

d->calculateTransforms();
Expand All @@ -145,7 +145,7 @@ void QgsCoordinateTransform::setDestinationCrs( const QgsCoordinateReferenceSyst
{
d.detach();
d->mDestCRS = crs;
if ( !d->mSourceCRS.isValid() || !d->mDestCRS.isValid() )
if ( !d->checkValidity() )
return;

d->calculateTransforms();
Expand All @@ -163,7 +163,7 @@ void QgsCoordinateTransform::setContext( const QgsCoordinateTransformContext &co
#ifdef QGISDEBUG
d->mHasContext = true;
#endif
if ( !d->mSourceCRS.isValid() || !d->mDestCRS.isValid() )
if ( !d->checkValidity() )
return;

d->calculateTransforms();
Expand Down
16 changes: 15 additions & 1 deletion src/core/qgscoordinatetransform_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,25 @@ QgsCoordinateTransformPrivate::~QgsCoordinateTransformPrivate()
freeProj();
}

bool QgsCoordinateTransformPrivate::initialize()
bool QgsCoordinateTransformPrivate::checkValidity()
{
if ( !mSourceCRS.isValid() || !mDestCRS.isValid() )
{
invalidate();
return false;
}
return true;
}

void QgsCoordinateTransformPrivate::invalidate()
{
mShortCircuit = true;
mIsValid = false;
}

bool QgsCoordinateTransformPrivate::initialize()
{
invalidate();
if ( !mSourceCRS.isValid() )
{
// Pass through with no projection since we have no idea what the layer
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgscoordinatetransform_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class QgsCoordinateTransformPrivate : public QSharedData

~QgsCoordinateTransformPrivate();

bool checkValidity();

void invalidate();

bool initialize();

void calculateTransforms();
Expand Down

0 comments on commit 40e551d

Please sign in to comment.