Skip to content
Permalink
Browse files

Show labels from labeling plugin also in map composer (though not sca…

…led correctly)

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12897 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Feb 7, 2010
1 parent 837059c commit f373b74d8c8f49a53e136422e96821ad4dbef32d
@@ -112,6 +112,8 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
QgsMapRenderer theMapRenderer;
theMapRenderer.setExtent( extent );
theMapRenderer.setOutputSize( size, dpi );
if ( mMapRenderer->labelingEngine() )
theMapRenderer.setLabelingEngine( mMapRenderer->labelingEngine()->clone() );

//use stored layer set or read current set from main canvas
if ( mKeepLayerSet )
@@ -279,7 +279,7 @@ void QgsMapRenderer::render( QPainter* painter )

mRenderContext.setLabelingEngine( mLabelingEngine );
if ( mLabelingEngine )
mLabelingEngine->init();
mLabelingEngine->init( this );

// know we know if this render is just a repeat of the last time, we
// can clear caches if it has changed
@@ -30,6 +30,7 @@ class QPainter;

class QgsMapToPixel;
class QgsMapLayer;
class QgsMapRenderer;
class QgsScaleCalculator;
class QgsCoordinateReferenceSystem;
class QgsDistanceArea;
@@ -46,7 +47,7 @@ class QgsLabelingEngineInterface
virtual ~QgsLabelingEngineInterface() {}

//! called when we're going to start with rendering
virtual void init() = 0;
virtual void init( QgsMapRenderer* mp ) = 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
@@ -58,6 +59,8 @@ class QgsLabelingEngineInterface
//! called when we're done with rendering
virtual void exit() = 0;

//! called when passing engine among map renderers
virtual QgsLabelingEngineInterface* clone() = 0;
};


@@ -105,7 +105,7 @@ class LabelingTool : public QgsMapTool
*/
void Labeling::initGui()
{
mLBL = new PalLabeling( mQGisIface->mapCanvas()->mapRenderer() );
mLBL = new PalLabeling();

// Create the action for tool
mQActionPointer = new QAction( QIcon( ":/labeling/labeling.png" ), tr( "Labeling" ), this );
@@ -257,8 +257,8 @@ void LayerSettings::registerFeature( QgsFeature& f )

// -------------

PalLabeling::PalLabeling( QgsMapRenderer* mapRenderer )
: mMapRenderer( mapRenderer ), mPal( NULL )
PalLabeling::PalLabeling()
: mMapRenderer( NULL ), mPal( NULL )
{

// find out engine defaults
@@ -298,6 +298,8 @@ bool PalLabeling::willUseLayer( QgsVectorLayer* layer )

int PalLabeling::prepareLayer( QgsVectorLayer* layer, int& attrIndex )
{
Q_ASSERT( mMapRenderer != NULL );

// start with a temporary settings class, find out labeling info
LayerSettings lyrTmp;
lyrTmp.readFromLayer( layer );
@@ -374,8 +376,10 @@ void PalLabeling::registerFeature( QgsVectorLayer* layer, QgsFeature& f )
}


void PalLabeling::init()
void PalLabeling::init( QgsMapRenderer* mr )
{
mMapRenderer = mr;

// delete if exists already
if ( mPal )
delete mPal;
@@ -404,6 +408,7 @@ void PalLabeling::exit()
{
delete mPal;
mPal = NULL;
mMapRenderer = NULL;
}

LayerSettings& PalLabeling::layer( const char* layerName )
@@ -421,6 +426,7 @@ LayerSettings& PalLabeling::layer( const char* layerName )

void PalLabeling::drawLabeling( QgsRenderContext& context )
{
Q_ASSERT( mMapRenderer != NULL );
QPainter* painter = context.painter();
QgsRectangle extent = context.extent();

@@ -611,3 +617,8 @@ void PalLabeling::drawLabelBuffer( QPainter* p, QString text, const QFont& font,
p->setBrush( color );
p->drawPath( path );
}

QgsLabelingEngineInterface* PalLabeling::clone()
{
return new PalLabeling();
}
@@ -99,7 +99,7 @@ class LabelCandidate
class PalLabeling : public QgsLabelingEngineInterface
{
public:
PalLabeling( QgsMapRenderer* renderer );
PalLabeling();
~PalLabeling();

LayerSettings& layer( const char* layerName );
@@ -122,7 +122,7 @@ class PalLabeling : public QgsLabelingEngineInterface
// implemented methods from labeling engine interface

//! called when we're going to start with rendering
virtual void init();
virtual void init( QgsMapRenderer* mr );
//! called to find out whether the layer is used for labeling
virtual bool willUseLayer( QgsVectorLayer* layer );
//! hook called when drawing layer before issuing select()
@@ -134,6 +134,8 @@ class PalLabeling : public QgsLabelingEngineInterface
//! called when we're done with rendering
virtual void exit();

//! called when passing engine among map renderers
virtual QgsLabelingEngineInterface* clone();

void drawLabelCandidateRect( pal::LabelPosition* lp, QPainter* painter, const QgsMapToPixel* xform );
void drawLabel( pal::LabelPosition* label, QPainter* painter, const QgsMapToPixel* xform, bool drawBuffer = false );

0 comments on commit f373b74

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