Skip to content

Commit e0d9796

Browse files
committed
Use coordinate transform cache in maprenderer
1 parent 496355b commit e0d9796

File tree

6 files changed

+15
-56
lines changed

6 files changed

+15
-56
lines changed

python/core/qgsmaprenderer.sip

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,6 @@ class QgsMapRenderer : QObject
228228
//! called by signal from layer current being drawn
229229
void onDrawingProgress( int current, int total );
230230

231-
//! invalidate cached layer CRS
232-
void invalidateCachedLayerCrs();
233-
234-
//! cached layer was destroyed
235-
void cachedLayerDestroyed();
236-
237231
protected:
238232

239233
//! adjust extent to fit the pixmap size

python/core/qgsrendercontext.sip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class QgsRenderContext
3838

3939
//setters
4040

41-
/**Sets coordinate transformation. QgsRenderContext takes ownership and deletes if necessary*/
42-
void setCoordinateTransform( QgsCoordinateTransform* t /Transfer/ );
41+
/**Sets coordinate transformation. QgsRenderContext does not take ownership*/
42+
void setCoordinateTransform( const QgsCoordinateTransform* t );
4343
void setMapToPixel( const QgsMapToPixel& mtp );
4444
void setExtent( const QgsRectangle& extent );
4545
void setDrawEditingInformation( bool b );

src/core/qgsmaprenderer.cpp

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <cfloat>
1818

1919
#include "qgscoordinatetransform.h"
20+
#include "qgscrscache.h"
2021
#include "qgslogger.h"
2122
#include "qgsmessagelog.h"
2223
#include "qgsmaprenderer.h"
@@ -46,8 +47,6 @@ QgsMapRenderer::QgsMapRenderer()
4647
mScale = 1.0;
4748
mScaleCalculator = new QgsScaleCalculator;
4849
mDistArea = new QgsDistanceArea;
49-
mCachedTrForLayer = 0;
50-
mCachedTr = 0;
5150

5251
mDrawing = false;
5352
mOverview = false;
@@ -71,7 +70,6 @@ QgsMapRenderer::~QgsMapRenderer()
7170
delete mDistArea;
7271
delete mDestCRS;
7372
delete mLabelingEngine;
74-
delete mCachedTr;
7573
}
7674

7775
QgsRectangle QgsMapRenderer::extent() const
@@ -266,7 +264,7 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
266264

267265
mDrawing = true;
268266

269-
QgsCoordinateTransform* ct;
267+
const QgsCoordinateTransform* ct;
270268

271269
#ifdef QGISDEBUG
272270
QgsDebugMsg( "Starting to render layer stack." );
@@ -402,7 +400,7 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
402400
{
403401
r1 = mExtent;
404402
split = splitLayersExtent( ml, r1, r2 );
405-
ct = new QgsCoordinateTransform( ml->crs(), *mDestCRS );
403+
ct = QgsCoordinateTransformCache::instance()->transform( ml->crs().authid(), mDestCRS->authid() );
406404
mRenderContext.setExtent( r1 );
407405
QgsDebugMsg( " extent 1: " + r1.toString() );
408406
QgsDebugMsg( " extent 2: " + r2.toString() );
@@ -692,7 +690,6 @@ void QgsMapRenderer::setDestinationCrs( const QgsCoordinateReferenceSystem& crs
692690
rect = transform.transformBoundingBox( mExtent );
693691
}
694692

695-
invalidateCachedLayerCrs();
696693
QgsDebugMsg( "Setting DistArea CRS to " + QString::number( crs.srsid() ) );
697694
mDistArea->setSourceCrs( crs.srsid() );
698695
*mDestCRS = crs;
@@ -734,7 +731,7 @@ bool QgsMapRenderer::splitLayersExtent( QgsMapLayer* layer, QgsRectangle& extent
734731
// extent separately.
735732
static const double splitCoord = 180.0;
736733

737-
if ( mCachedTr->sourceCrs().geographicFlag() )
734+
if ( layer->crs().geographicFlag() )
738735
{
739736
// Note: ll = lower left point
740737
// and ur = upper right point
@@ -1138,35 +1135,13 @@ void QgsMapRenderer::setLabelingEngine( QgsLabelingEngineInterface* iface )
11381135
mLabelingEngine = iface;
11391136
}
11401137

1141-
QgsCoordinateTransform *QgsMapRenderer::tr( QgsMapLayer *layer )
1138+
const QgsCoordinateTransform* QgsMapRenderer::tr( QgsMapLayer *layer )
11421139
{
1143-
if ( mCachedTrForLayer != layer )
1140+
if ( !layer || !mDestCRS )
11441141
{
1145-
invalidateCachedLayerCrs();
1146-
1147-
delete mCachedTr;
1148-
mCachedTr = new QgsCoordinateTransform( layer->crs(), *mDestCRS );
1149-
mCachedTrForLayer = layer;
1150-
1151-
connect( layer, SIGNAL( layerCrsChanged() ), this, SLOT( invalidateCachedLayerCrs() ) );
1152-
connect( layer, SIGNAL( destroyed() ), this, SLOT( cachedLayerDestroyed() ) );
1142+
return 0;
11531143
}
1154-
1155-
return mCachedTr;
1156-
}
1157-
1158-
void QgsMapRenderer::cachedLayerDestroyed()
1159-
{
1160-
if ( mCachedTrForLayer == sender() )
1161-
mCachedTrForLayer = 0;
1162-
}
1163-
1164-
void QgsMapRenderer::invalidateCachedLayerCrs()
1165-
{
1166-
if ( mCachedTrForLayer )
1167-
disconnect( mCachedTrForLayer, SIGNAL( layerCrsChanged() ), this, SLOT( invalidateCachedLayerCrs() ) );
1168-
1169-
mCachedTrForLayer = 0;
1144+
return QgsCoordinateTransformCache::instance()->transform( layer->crs().authid(), mDestCRS->authid() );
11701145
}
11711146

11721147
bool QgsMapRenderer::mDrawing = false;

src/core/qgsmaprenderer.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,6 @@ class CORE_EXPORT QgsMapRenderer : public QObject
265265
//! called by signal from layer current being drawn
266266
void onDrawingProgress( int current, int total );
267267

268-
//! invalidate cached layer CRS
269-
void invalidateCachedLayerCrs();
270-
271-
//! cached layer was destroyed
272-
void cachedLayerDestroyed();
273-
274268
protected:
275269

276270
//! adjust extent to fit the pixmap size
@@ -343,9 +337,7 @@ class CORE_EXPORT QgsMapRenderer : public QObject
343337
QMutex mRenderMutex;
344338

345339
private:
346-
QgsCoordinateTransform *tr( QgsMapLayer *layer );
347-
QgsCoordinateTransform *mCachedTr;
348-
QgsMapLayer *mCachedTrForLayer;
340+
const QgsCoordinateTransform* tr( QgsMapLayer *layer );
349341
};
350342

351343
#endif

src/core/qgsrendercontext.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ QgsRenderContext::QgsRenderContext()
3434

3535
QgsRenderContext::~QgsRenderContext()
3636
{
37-
delete mCoordTransform;
3837
}
3938

40-
void QgsRenderContext::setCoordinateTransform( QgsCoordinateTransform* t )
39+
void QgsRenderContext::setCoordinateTransform( const QgsCoordinateTransform* t )
4140
{
42-
delete mCoordTransform;
4341
mCoordTransform = t;
4442
}
4543

src/core/qgsrendercontext.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ class CORE_EXPORT QgsRenderContext
6666

6767
//setters
6868

69-
/**Sets coordinate transformation. QgsRenderContext takes ownership and deletes if necessary*/
70-
void setCoordinateTransform( QgsCoordinateTransform* t );
69+
/**Sets coordinate transformation. QgsRenderContext does not take ownership*/
70+
void setCoordinateTransform( const QgsCoordinateTransform* t );
7171
void setMapToPixel( const QgsMapToPixel& mtp ) {mMapToPixel = mtp;}
7272
void setExtent( const QgsRectangle& extent ) {mExtent = extent;}
7373
void setDrawEditingInformation( bool b ) {mDrawEditingInformation = b;}
@@ -87,7 +87,7 @@ class CORE_EXPORT QgsRenderContext
8787
QPainter* mPainter;
8888

8989
/**For transformation between coordinate systems. Can be 0 if on-the-fly reprojection is not used*/
90-
QgsCoordinateTransform* mCoordTransform;
90+
const QgsCoordinateTransform* mCoordTransform;
9191

9292
/**True if vertex markers for editing should be drawn*/
9393
bool mDrawEditingInformation;

0 commit comments

Comments
 (0)