Navigation Menu

Skip to content

Commit

Permalink
Fix new labeling to work with render caching.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@12540 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Dec 20, 2009
1 parent f2c040c commit a81156f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
2 changes: 2 additions & 0 deletions python/core/qgsmaprenderer.sip
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions src/core/qgsmaprenderer.cpp
Expand Up @@ -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
Expand All @@ -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 );
Expand Down Expand Up @@ -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<QgsVectorLayer *>( ml );
if ( vl->isEditable() )
if ( vl->isEditable() ||
( mRenderContext.labelingEngine() && mRenderContext.labelingEngine()->willUseLayer( vl ) ) )
{
ml->setCacheImage( 0 );
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsmaprenderer.h
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/plugins/labeling/pallabeling.cpp
Expand Up @@ -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
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/labeling/pallabeling.h
Expand Up @@ -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
Expand Down

0 comments on commit a81156f

Please sign in to comment.