[QGIS Commit] r12897 - in trunk/qgis/src: core core/composer plugins/labeling

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Feb 7 16:03:04 EST 2010


Author: wonder
Date: 2010-02-07 16:03:03 -0500 (Sun, 07 Feb 2010)
New Revision: 12897

Modified:
   trunk/qgis/src/core/composer/qgscomposermap.cpp
   trunk/qgis/src/core/qgsmaprenderer.cpp
   trunk/qgis/src/core/qgsmaprenderer.h
   trunk/qgis/src/plugins/labeling/labeling.cpp
   trunk/qgis/src/plugins/labeling/pallabeling.cpp
   trunk/qgis/src/plugins/labeling/pallabeling.h
Log:
Show labels from labeling plugin also in map composer (though not scaled correctly)


Modified: trunk/qgis/src/core/composer/qgscomposermap.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposermap.cpp	2010-02-07 21:02:25 UTC (rev 12896)
+++ trunk/qgis/src/core/composer/qgscomposermap.cpp	2010-02-07 21:03:03 UTC (rev 12897)
@@ -112,6 +112,8 @@
   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 )

Modified: trunk/qgis/src/core/qgsmaprenderer.cpp
===================================================================
--- trunk/qgis/src/core/qgsmaprenderer.cpp	2010-02-07 21:02:25 UTC (rev 12896)
+++ trunk/qgis/src/core/qgsmaprenderer.cpp	2010-02-07 21:03:03 UTC (rev 12897)
@@ -279,7 +279,7 @@
 
   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

Modified: trunk/qgis/src/core/qgsmaprenderer.h
===================================================================
--- trunk/qgis/src/core/qgsmaprenderer.h	2010-02-07 21:02:25 UTC (rev 12896)
+++ trunk/qgis/src/core/qgsmaprenderer.h	2010-02-07 21:03:03 UTC (rev 12897)
@@ -30,6 +30,7 @@
 
 class QgsMapToPixel;
 class QgsMapLayer;
+class QgsMapRenderer;
 class QgsScaleCalculator;
 class QgsCoordinateReferenceSystem;
 class QgsDistanceArea;
@@ -46,7 +47,7 @@
     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 @@
     //! called when we're done with rendering
     virtual void exit() = 0;
 
+    //! called when passing engine among map renderers
+    virtual QgsLabelingEngineInterface* clone() = 0;
 };
 
 

Modified: trunk/qgis/src/plugins/labeling/labeling.cpp
===================================================================
--- trunk/qgis/src/plugins/labeling/labeling.cpp	2010-02-07 21:02:25 UTC (rev 12896)
+++ trunk/qgis/src/plugins/labeling/labeling.cpp	2010-02-07 21:03:03 UTC (rev 12897)
@@ -105,7 +105,7 @@
  */
 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 );

Modified: trunk/qgis/src/plugins/labeling/pallabeling.cpp
===================================================================
--- trunk/qgis/src/plugins/labeling/pallabeling.cpp	2010-02-07 21:02:25 UTC (rev 12896)
+++ trunk/qgis/src/plugins/labeling/pallabeling.cpp	2010-02-07 21:03:03 UTC (rev 12897)
@@ -257,8 +257,8 @@
 
 // -------------
 
-PalLabeling::PalLabeling( QgsMapRenderer* mapRenderer )
-    : mMapRenderer( mapRenderer ), mPal( NULL )
+PalLabeling::PalLabeling()
+    : mMapRenderer( NULL ), mPal( NULL )
 {
 
   // find out engine defaults
@@ -298,6 +298,8 @@
 
 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::init()
+void PalLabeling::init( QgsMapRenderer* mr )
 {
+  mMapRenderer = mr;
+
   // delete if exists already
   if ( mPal )
     delete mPal;
@@ -404,6 +408,7 @@
 {
   delete mPal;
   mPal = NULL;
+  mMapRenderer = NULL;
 }
 
 LayerSettings& PalLabeling::layer( const char* layerName )
@@ -421,6 +426,7 @@
 
 void PalLabeling::drawLabeling( QgsRenderContext& context )
 {
+  Q_ASSERT( mMapRenderer != NULL );
   QPainter* painter = context.painter();
   QgsRectangle extent = context.extent();
 
@@ -611,3 +617,8 @@
   p->setBrush( color );
   p->drawPath( path );
 }
+
+QgsLabelingEngineInterface* PalLabeling::clone()
+{
+  return new PalLabeling();
+}

Modified: trunk/qgis/src/plugins/labeling/pallabeling.h
===================================================================
--- trunk/qgis/src/plugins/labeling/pallabeling.h	2010-02-07 21:02:25 UTC (rev 12896)
+++ trunk/qgis/src/plugins/labeling/pallabeling.h	2010-02-07 21:03:03 UTC (rev 12897)
@@ -99,7 +99,7 @@
 class PalLabeling : public QgsLabelingEngineInterface
 {
   public:
-    PalLabeling( QgsMapRenderer* renderer );
+    PalLabeling();
     ~PalLabeling();
 
     LayerSettings& layer( const char* layerName );
@@ -122,7 +122,7 @@
     // 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 @@
     //! 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 );



More information about the QGIS-commit mailing list