diff --git a/python/core/qgsmaprenderer.sip b/python/core/qgsmaprenderer.sip index 838dca38780..a79ccb51615 100644 --- a/python/core/qgsmaprenderer.sip +++ b/python/core/qgsmaprenderer.sip @@ -14,6 +14,8 @@ public: //! called when we're going to start with rendering virtual void init() = 0; + //! called to find out whether the layer is used for labeling + virtual bool willUseLayer( QgsVectorLayer* layer ) = 0; //! called when starting rendering of a layer virtual int prepareLayer(QgsVectorLayer* layer, int& attrIndex) = 0; //! called for every feature diff --git a/src/core/qgsmaprenderer.cpp b/src/core/qgsmaprenderer.cpp index 18fbe4451f2..98b3f34d087 100644 --- a/src/core/qgsmaprenderer.cpp +++ b/src/core/qgsmaprenderer.cpp @@ -180,9 +180,9 @@ void QgsMapRenderer::adjustExtentToSize() dymax = mExtent.yMaximum() + whitespace; } - QgsDebugMsg( QString("Map units per pixel (x,y) : %1, %2\n" ).arg( mapUnitsPerPixelX ).arg( mapUnitsPerPixelY ) ); - QgsDebugMsg( QString("Pixmap dimensions (x,y) : %1, %2\n" ).arg( myWidth ).arg( myHeight ) ); - QgsDebugMsg( QString("Extent dimensions (x,y) : %1, %2\n" ).arg( mExtent.width() ).arg( mExtent.height() ) ); + QgsDebugMsg( QString( "Map units per pixel (x,y) : %1, %2\n" ).arg( mapUnitsPerPixelX ).arg( mapUnitsPerPixelY ) ); + QgsDebugMsg( QString( "Pixmap dimensions (x,y) : %1, %2\n" ).arg( myWidth ).arg( myHeight ) ); + QgsDebugMsg( QString( "Extent dimensions (x,y) : %1, %2\n" ).arg( mExtent.width() ).arg( mExtent.height() ) ); QgsDebugMsg( mExtent.toString() ); // update extent @@ -194,7 +194,7 @@ void QgsMapRenderer::adjustExtentToSize() // update the scale updateScale(); - QgsDebugMsg( QString("Scale (assuming meters as map units) = 1:%1").arg( mScale ) ); + QgsDebugMsg( QString( "Scale (assuming meters as map units) = 1:%1" ).arg( mScale ) ); newCoordXForm.setParameters( mMapUnitsPerPixel, dxmin, dymin, myHeight ); mRenderContext.setMapToPixel( newCoordXForm ); @@ -406,10 +406,12 @@ void QgsMapRenderer::render( QPainter* painter ) } // Force render of layers that are being edited + // or if there's a labeling engine that needs the layer to register features if ( ml->type() == QgsMapLayer::VectorLayer ) { QgsVectorLayer* vl = qobject_cast( ml ); - if ( vl->isEditable() ) + if ( vl->isEditable() || + ( mRenderContext.labelingEngine() && mRenderContext.labelingEngine()->willUseLayer( vl ) ) ) { ml->setCacheImage( 0 ); } @@ -576,7 +578,7 @@ void QgsMapRenderer::render( QPainter* painter ) { // set correct extent mRenderContext.setExtent( mExtent ); - mRenderContext.setCoordinateTransform(NULL); + mRenderContext.setCoordinateTransform( NULL ); mLabelingEngine->drawLabeling( mRenderContext ); mLabelingEngine->exit(); @@ -813,7 +815,7 @@ void QgsMapRenderer::updateFullExtent() QgsMapLayer * lyr = registry->mapLayer( *it ); if ( lyr == NULL ) { - QgsDebugMsg( QString("WARNING: layer '%1' not found in map layer registry!").arg( *it ) ); + QgsDebugMsg( QString( "WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) ); } else { diff --git a/src/core/qgsmaprenderer.h b/src/core/qgsmaprenderer.h index 2832e788295..c9a7bb37753 100644 --- a/src/core/qgsmaprenderer.h +++ b/src/core/qgsmaprenderer.h @@ -47,6 +47,8 @@ class QgsLabelingEngineInterface //! called when we're going to start with rendering virtual void init() = 0; + //! called to find out whether the layer is used for labeling + virtual bool willUseLayer( QgsVectorLayer* layer ) = 0; //! called when starting rendering of a layer virtual int prepareLayer( QgsVectorLayer* layer, int& attrIndex ) = 0; //! called for every feature diff --git a/src/plugins/labeling/pallabeling.cpp b/src/plugins/labeling/pallabeling.cpp index 2ea20bb178b..27a8d75399e 100644 --- a/src/plugins/labeling/pallabeling.cpp +++ b/src/plugins/labeling/pallabeling.cpp @@ -288,6 +288,14 @@ PalLabeling::~PalLabeling() } +bool PalLabeling::willUseLayer( QgsVectorLayer* layer ) +{ + LayerSettings lyrTmp; + lyrTmp.readFromLayer( layer ); + return lyrTmp.enabled; +} + + int PalLabeling::prepareLayer( QgsVectorLayer* layer, int& attrIndex ) { // start with a temporary settings class, find out labeling info @@ -298,7 +306,7 @@ int PalLabeling::prepareLayer( QgsVectorLayer* layer, int& attrIndex ) return 0; // find out which field will be needed - int fldIndex = layer->dataProvider()->fieldNameIndex( lyrTmp.fieldName ); + int fldIndex = layer->fieldNameIndex( lyrTmp.fieldName ); if ( fldIndex == -1 ) return 0; attrIndex = fldIndex; diff --git a/src/plugins/labeling/pallabeling.h b/src/plugins/labeling/pallabeling.h index 4dbfbf2edb6..5ebc2955d33 100644 --- a/src/plugins/labeling/pallabeling.h +++ b/src/plugins/labeling/pallabeling.h @@ -123,6 +123,8 @@ class PalLabeling : public QgsLabelingEngineInterface //! called when we're going to start with rendering virtual void init(); + //! called to find out whether the layer is used for labeling + virtual bool willUseLayer( QgsVectorLayer* layer ); //! hook called when drawing layer before issuing select() virtual int prepareLayer( QgsVectorLayer* layer, int& attrIndex ); //! hook called when drawing for every feature in a layer