Skip to content

Commit

Permalink
Show labels from labeling plugin also in map composer (though not sca…
Browse files Browse the repository at this point in the history
…led correctly)

git-svn-id: http://svn.osgeo.org/qgis/trunk@12897 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Feb 7, 2010
1 parent 71f1842 commit f46c6f6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/core/composer/qgscomposermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmaprenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/core/qgsmaprenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class QPainter;

class QgsMapToPixel;
class QgsMapLayer;
class QgsMapRenderer;
class QgsScaleCalculator;
class QgsCoordinateReferenceSystem;
class QgsDistanceArea;
Expand All @@ -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
Expand All @@ -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;
};


Expand Down
2 changes: 1 addition & 1 deletion src/plugins/labeling/labeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
17 changes: 14 additions & 3 deletions src/plugins/labeling/pallabeling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -404,6 +408,7 @@ void PalLabeling::exit()
{
delete mPal;
mPal = NULL;
mMapRenderer = NULL;
}

LayerSettings& PalLabeling::layer( const char* layerName )
Expand All @@ -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();

Expand Down Expand Up @@ -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();
}
6 changes: 4 additions & 2 deletions src/plugins/labeling/pallabeling.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class LabelCandidate
class PalLabeling : public QgsLabelingEngineInterface
{
public:
PalLabeling( QgsMapRenderer* renderer );
PalLabeling();
~PalLabeling();

LayerSettings& layer( const char* layerName );
Expand All @@ -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()
Expand All @@ -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 );
Expand Down

0 comments on commit f46c6f6

Please sign in to comment.