Skip to content

Commit

Permalink
Use coordinate transform cache in maprenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Dec 17, 2012
1 parent 496355b commit e0d9796
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 56 deletions.
6 changes: 0 additions & 6 deletions python/core/qgsmaprenderer.sip
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,6 @@ class QgsMapRenderer : QObject
//! called by signal from layer current being drawn
void onDrawingProgress( int current, int total );

//! invalidate cached layer CRS
void invalidateCachedLayerCrs();

//! cached layer was destroyed
void cachedLayerDestroyed();

protected:

//! adjust extent to fit the pixmap size
Expand Down
4 changes: 2 additions & 2 deletions python/core/qgsrendercontext.sip
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class QgsRenderContext

//setters

/**Sets coordinate transformation. QgsRenderContext takes ownership and deletes if necessary*/
void setCoordinateTransform( QgsCoordinateTransform* t /Transfer/ );
/**Sets coordinate transformation. QgsRenderContext does not take ownership*/
void setCoordinateTransform( const QgsCoordinateTransform* t );
void setMapToPixel( const QgsMapToPixel& mtp );
void setExtent( const QgsRectangle& extent );
void setDrawEditingInformation( bool b );
Expand Down
41 changes: 8 additions & 33 deletions src/core/qgsmaprenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <cfloat>

#include "qgscoordinatetransform.h"
#include "qgscrscache.h"
#include "qgslogger.h"
#include "qgsmessagelog.h"
#include "qgsmaprenderer.h"
Expand Down Expand Up @@ -46,8 +47,6 @@ QgsMapRenderer::QgsMapRenderer()
mScale = 1.0;
mScaleCalculator = new QgsScaleCalculator;
mDistArea = new QgsDistanceArea;
mCachedTrForLayer = 0;
mCachedTr = 0;

mDrawing = false;
mOverview = false;
Expand All @@ -71,7 +70,6 @@ QgsMapRenderer::~QgsMapRenderer()
delete mDistArea;
delete mDestCRS;
delete mLabelingEngine;
delete mCachedTr;
}

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

mDrawing = true;

QgsCoordinateTransform* ct;
const QgsCoordinateTransform* ct;

#ifdef QGISDEBUG
QgsDebugMsg( "Starting to render layer stack." );
Expand Down Expand Up @@ -402,7 +400,7 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
{
r1 = mExtent;
split = splitLayersExtent( ml, r1, r2 );
ct = new QgsCoordinateTransform( ml->crs(), *mDestCRS );
ct = QgsCoordinateTransformCache::instance()->transform( ml->crs().authid(), mDestCRS->authid() );
mRenderContext.setExtent( r1 );
QgsDebugMsg( " extent 1: " + r1.toString() );
QgsDebugMsg( " extent 2: " + r2.toString() );
Expand Down Expand Up @@ -692,7 +690,6 @@ void QgsMapRenderer::setDestinationCrs( const QgsCoordinateReferenceSystem& crs
rect = transform.transformBoundingBox( mExtent );
}

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

if ( mCachedTr->sourceCrs().geographicFlag() )
if ( layer->crs().geographicFlag() )
{
// Note: ll = lower left point
// and ur = upper right point
Expand Down Expand Up @@ -1138,35 +1135,13 @@ void QgsMapRenderer::setLabelingEngine( QgsLabelingEngineInterface* iface )
mLabelingEngine = iface;
}

QgsCoordinateTransform *QgsMapRenderer::tr( QgsMapLayer *layer )
const QgsCoordinateTransform* QgsMapRenderer::tr( QgsMapLayer *layer )
{
if ( mCachedTrForLayer != layer )
if ( !layer || !mDestCRS )
{
invalidateCachedLayerCrs();

delete mCachedTr;
mCachedTr = new QgsCoordinateTransform( layer->crs(), *mDestCRS );
mCachedTrForLayer = layer;

connect( layer, SIGNAL( layerCrsChanged() ), this, SLOT( invalidateCachedLayerCrs() ) );
connect( layer, SIGNAL( destroyed() ), this, SLOT( cachedLayerDestroyed() ) );
return 0;
}

return mCachedTr;
}

void QgsMapRenderer::cachedLayerDestroyed()
{
if ( mCachedTrForLayer == sender() )
mCachedTrForLayer = 0;
}

void QgsMapRenderer::invalidateCachedLayerCrs()
{
if ( mCachedTrForLayer )
disconnect( mCachedTrForLayer, SIGNAL( layerCrsChanged() ), this, SLOT( invalidateCachedLayerCrs() ) );

mCachedTrForLayer = 0;
return QgsCoordinateTransformCache::instance()->transform( layer->crs().authid(), mDestCRS->authid() );
}

bool QgsMapRenderer::mDrawing = false;
10 changes: 1 addition & 9 deletions src/core/qgsmaprenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,6 @@ class CORE_EXPORT QgsMapRenderer : public QObject
//! called by signal from layer current being drawn
void onDrawingProgress( int current, int total );

//! invalidate cached layer CRS
void invalidateCachedLayerCrs();

//! cached layer was destroyed
void cachedLayerDestroyed();

protected:

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

private:
QgsCoordinateTransform *tr( QgsMapLayer *layer );
QgsCoordinateTransform *mCachedTr;
QgsMapLayer *mCachedTrForLayer;
const QgsCoordinateTransform* tr( QgsMapLayer *layer );
};

#endif
Expand Down
4 changes: 1 addition & 3 deletions src/core/qgsrendercontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ QgsRenderContext::QgsRenderContext()

QgsRenderContext::~QgsRenderContext()
{
delete mCoordTransform;
}

void QgsRenderContext::setCoordinateTransform( QgsCoordinateTransform* t )
void QgsRenderContext::setCoordinateTransform( const QgsCoordinateTransform* t )
{
delete mCoordTransform;
mCoordTransform = t;
}

6 changes: 3 additions & 3 deletions src/core/qgsrendercontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class CORE_EXPORT QgsRenderContext

//setters

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

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

/**True if vertex markers for editing should be drawn*/
bool mDrawEditingInformation;
Expand Down

0 comments on commit e0d9796

Please sign in to comment.