Skip to content

Commit 9a9b53b

Browse files
committed
unset QgsMapRenderer mCachedTrForLayer on setDestinationCrs and always check layer->crs against mCachedTr destCRS
1 parent a6df30c commit 9a9b53b

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

python/core/qgscoordinatereferencesystem.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ class QgsCoordinateReferenceSystem
159159
/*! Overloaded == operator used to compare to CRS's.
160160
* Internally it will delegate to the equals method described below
161161
*/
162-
bool operator==(const QgsCoordinateReferenceSystem &theSrs);
162+
bool operator==(const QgsCoordinateReferenceSystem &theSrs) const;
163163
/*! Overloaded != operator used to compare to CRS's.
164164
* Returns opposite bool value to operator ==
165165
*/
166-
bool operator!=(const QgsCoordinateReferenceSystem &theSrs);
166+
bool operator!=(const QgsCoordinateReferenceSystem &theSrs) const;
167167
/*! Overloaded == operator used to compare to CRS's.
168168
* Internally it will use OGR isSameCRS() or isSameGeoCRS() methods as appropriate.
169169
* Additionally logic may also be applied if the result from the OGR methods

src/core/qgscoordinatereferencesystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,12 +979,12 @@ long QgsCoordinateReferenceSystem::findMatchingProj()
979979
return 0;
980980
}
981981

982-
bool QgsCoordinateReferenceSystem::operator==( const QgsCoordinateReferenceSystem &theSrs )
982+
bool QgsCoordinateReferenceSystem::operator==( const QgsCoordinateReferenceSystem &theSrs ) const
983983
{
984984
return mIsValidFlag && theSrs.mIsValidFlag && toWkt() == theSrs.toWkt();
985985
}
986986

987-
bool QgsCoordinateReferenceSystem::operator!=( const QgsCoordinateReferenceSystem &theSrs )
987+
bool QgsCoordinateReferenceSystem::operator!=( const QgsCoordinateReferenceSystem &theSrs ) const
988988
{
989989
return !( *this == theSrs );
990990
}

src/core/qgscoordinatereferencesystem.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
201201
/*! Overloaded == operator used to compare to CRS's.
202202
* Internally it will delegate to the equals method described below
203203
*/
204-
bool operator==( const QgsCoordinateReferenceSystem &theSrs );
204+
bool operator==( const QgsCoordinateReferenceSystem &theSrs ) const;
205205
/*! Overloaded != operator used to compare to CRS's.
206206
* Returns opposite bool value to operator ==
207207
*/
208-
bool operator!=( const QgsCoordinateReferenceSystem &theSrs );
208+
bool operator!=( const QgsCoordinateReferenceSystem &theSrs ) const;
209209
/*! Overloaded == operator used to compare to CRS's.
210210
* Internally it will use OGR isSameCRS() or isSameGeoCRS() methods as appropriate.
211211
* Additionally logic may also be applied if the result from the OGR methods

src/core/qgsmaprenderer.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ void QgsMapRenderer::setDestinationCrs( const QgsCoordinateReferenceSystem& crs
680680
QgsDebugMsg( "* DestCRS.srsid() = " + QString::number( crs.srsid() ) );
681681
if ( *mDestCRS != crs )
682682
{
683+
mCachedTrForLayer = 0;
683684
QgsDebugMsg( "Setting DistArea CRS to " + QString::number( crs.srsid() ) );
684685
mDistArea->setSourceCrs( crs.srsid() );
685686
*mDestCRS = crs;
@@ -754,6 +755,9 @@ bool QgsMapRenderer::splitLayersExtent( QgsMapLayer* layer, QgsRectangle& extent
754755

755756
QgsRectangle QgsMapRenderer::layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent )
756757
{
758+
QgsDebugMsg( QString( "sourceCrs = " + tr( theLayer )->sourceCrs().authid() ) );
759+
QgsDebugMsg( QString( "destCRS = " + tr( theLayer )->destCRS().authid() ) );
760+
QgsDebugMsg( QString( "extent = " + extent.toString() ) );
757761
if ( hasCrsTransformEnabled() )
758762
{
759763
try
@@ -770,6 +774,7 @@ QgsRectangle QgsMapRenderer::layerExtentToOutputExtent( QgsMapLayer* theLayer, Q
770774
{
771775
// leave extent unchanged
772776
}
777+
QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
773778

774779
return extent;
775780
}
@@ -1102,7 +1107,8 @@ void QgsMapRenderer::setLabelingEngine( QgsLabelingEngineInterface* iface )
11021107

11031108
QgsCoordinateTransform *QgsMapRenderer::tr( QgsMapLayer *layer )
11041109
{
1105-
if ( mCachedTrForLayer != layer )
1110+
// mCachedTrForLayer is unset by setDestinationCrs(), but layer->crs may also be changed after CRS was cached -> check it - the question is, how efficient now the caching is, because crs == operator is not cheap
1111+
if ( mCachedTrForLayer != layer || layer->crs() != mCachedTr->sourceCrs() )
11061112
{
11071113
delete mCachedTr;
11081114
mCachedTr = new QgsCoordinateTransform( layer->crs(), *mDestCRS );

0 commit comments

Comments
 (0)