Skip to content

Commit fc4fd9e

Browse files
author
wonder
committedDec 20, 2009
Fix new labeling to work with render caching.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12540 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed
 

‎python/core/qgsmaprenderer.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public:
1414

1515
//! called when we're going to start with rendering
1616
virtual void init() = 0;
17+
//! called to find out whether the layer is used for labeling
18+
virtual bool willUseLayer( QgsVectorLayer* layer ) = 0;
1719
//! called when starting rendering of a layer
1820
virtual int prepareLayer(QgsVectorLayer* layer, int& attrIndex) = 0;
1921
//! called for every feature

‎src/core/qgsmaprenderer.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ void QgsMapRenderer::adjustExtentToSize()
180180
dymax = mExtent.yMaximum() + whitespace;
181181
}
182182

183-
QgsDebugMsg( QString("Map units per pixel (x,y) : %1, %2\n" ).arg( mapUnitsPerPixelX ).arg( mapUnitsPerPixelY ) );
184-
QgsDebugMsg( QString("Pixmap dimensions (x,y) : %1, %2\n" ).arg( myWidth ).arg( myHeight ) );
185-
QgsDebugMsg( QString("Extent dimensions (x,y) : %1, %2\n" ).arg( mExtent.width() ).arg( mExtent.height() ) );
183+
QgsDebugMsg( QString( "Map units per pixel (x,y) : %1, %2\n" ).arg( mapUnitsPerPixelX ).arg( mapUnitsPerPixelY ) );
184+
QgsDebugMsg( QString( "Pixmap dimensions (x,y) : %1, %2\n" ).arg( myWidth ).arg( myHeight ) );
185+
QgsDebugMsg( QString( "Extent dimensions (x,y) : %1, %2\n" ).arg( mExtent.width() ).arg( mExtent.height() ) );
186186
QgsDebugMsg( mExtent.toString() );
187187

188188
// update extent
@@ -194,7 +194,7 @@ void QgsMapRenderer::adjustExtentToSize()
194194
// update the scale
195195
updateScale();
196196

197-
QgsDebugMsg( QString("Scale (assuming meters as map units) = 1:%1").arg( mScale ) );
197+
QgsDebugMsg( QString( "Scale (assuming meters as map units) = 1:%1" ).arg( mScale ) );
198198

199199
newCoordXForm.setParameters( mMapUnitsPerPixel, dxmin, dymin, myHeight );
200200
mRenderContext.setMapToPixel( newCoordXForm );
@@ -406,10 +406,12 @@ void QgsMapRenderer::render( QPainter* painter )
406406
}
407407

408408
// Force render of layers that are being edited
409+
// or if there's a labeling engine that needs the layer to register features
409410
if ( ml->type() == QgsMapLayer::VectorLayer )
410411
{
411412
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
412-
if ( vl->isEditable() )
413+
if ( vl->isEditable() ||
414+
( mRenderContext.labelingEngine() && mRenderContext.labelingEngine()->willUseLayer( vl ) ) )
413415
{
414416
ml->setCacheImage( 0 );
415417
}
@@ -576,7 +578,7 @@ void QgsMapRenderer::render( QPainter* painter )
576578
{
577579
// set correct extent
578580
mRenderContext.setExtent( mExtent );
579-
mRenderContext.setCoordinateTransform(NULL);
581+
mRenderContext.setCoordinateTransform( NULL );
580582

581583
mLabelingEngine->drawLabeling( mRenderContext );
582584
mLabelingEngine->exit();
@@ -813,7 +815,7 @@ void QgsMapRenderer::updateFullExtent()
813815
QgsMapLayer * lyr = registry->mapLayer( *it );
814816
if ( lyr == NULL )
815817
{
816-
QgsDebugMsg( QString("WARNING: layer '%1' not found in map layer registry!").arg( *it ) );
818+
QgsDebugMsg( QString( "WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) );
817819
}
818820
else
819821
{

‎src/core/qgsmaprenderer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class QgsLabelingEngineInterface
4747

4848
//! called when we're going to start with rendering
4949
virtual void init() = 0;
50+
//! called to find out whether the layer is used for labeling
51+
virtual bool willUseLayer( QgsVectorLayer* layer ) = 0;
5052
//! called when starting rendering of a layer
5153
virtual int prepareLayer( QgsVectorLayer* layer, int& attrIndex ) = 0;
5254
//! called for every feature

‎src/plugins/labeling/pallabeling.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,14 @@ PalLabeling::~PalLabeling()
288288
}
289289

290290

291+
bool PalLabeling::willUseLayer( QgsVectorLayer* layer )
292+
{
293+
LayerSettings lyrTmp;
294+
lyrTmp.readFromLayer( layer );
295+
return lyrTmp.enabled;
296+
}
297+
298+
291299
int PalLabeling::prepareLayer( QgsVectorLayer* layer, int& attrIndex )
292300
{
293301
// start with a temporary settings class, find out labeling info
@@ -298,7 +306,7 @@ int PalLabeling::prepareLayer( QgsVectorLayer* layer, int& attrIndex )
298306
return 0;
299307

300308
// find out which field will be needed
301-
int fldIndex = layer->dataProvider()->fieldNameIndex( lyrTmp.fieldName );
309+
int fldIndex = layer->fieldNameIndex( lyrTmp.fieldName );
302310
if ( fldIndex == -1 )
303311
return 0;
304312
attrIndex = fldIndex;

‎src/plugins/labeling/pallabeling.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ class PalLabeling : public QgsLabelingEngineInterface
123123

124124
//! called when we're going to start with rendering
125125
virtual void init();
126+
//! called to find out whether the layer is used for labeling
127+
virtual bool willUseLayer( QgsVectorLayer* layer );
126128
//! hook called when drawing layer before issuing select()
127129
virtual int prepareLayer( QgsVectorLayer* layer, int& attrIndex );
128130
//! hook called when drawing for every feature in a layer

0 commit comments

Comments
 (0)
Please sign in to comment.