Skip to content
Permalink
Browse files

Fix new labeling to work with render caching.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12540 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Dec 20, 2009
1 parent 6ac70a3 commit fc4fd9ee4cbda46e82aa45a1776a7940bed1eed7
@@ -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
@@ -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<QgsVectorLayer *>( 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
{
@@ -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
@@ -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;
@@ -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

0 comments on commit fc4fd9e

Please sign in to comment.
You can’t perform that action at this time.