[QGIS Commit] r12540 - in trunk/qgis: python/core src/core src/plugins/labeling

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Dec 20 11:35:46 EST 2009


Author: wonder
Date: 2009-12-20 11:35:45 -0500 (Sun, 20 Dec 2009)
New Revision: 12540

Modified:
   trunk/qgis/python/core/qgsmaprenderer.sip
   trunk/qgis/src/core/qgsmaprenderer.cpp
   trunk/qgis/src/core/qgsmaprenderer.h
   trunk/qgis/src/plugins/labeling/pallabeling.cpp
   trunk/qgis/src/plugins/labeling/pallabeling.h
Log:
Fix new labeling to work with render caching.


Modified: trunk/qgis/python/core/qgsmaprenderer.sip
===================================================================
--- trunk/qgis/python/core/qgsmaprenderer.sip	2009-12-20 16:12:02 UTC (rev 12539)
+++ trunk/qgis/python/core/qgsmaprenderer.sip	2009-12-20 16:35:45 UTC (rev 12540)
@@ -14,6 +14,8 @@
 
   //! 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

Modified: trunk/qgis/src/core/qgsmaprenderer.cpp
===================================================================
--- trunk/qgis/src/core/qgsmaprenderer.cpp	2009-12-20 16:12:02 UTC (rev 12539)
+++ trunk/qgis/src/core/qgsmaprenderer.cpp	2009-12-20 16:35:45 UTC (rev 12540)
@@ -180,9 +180,9 @@
     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 @@
   // 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 @@
       }
 
       // 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 @@
   {
     // set correct extent
     mRenderContext.setExtent( mExtent );
-    mRenderContext.setCoordinateTransform(NULL);
+    mRenderContext.setCoordinateTransform( NULL );
 
     mLabelingEngine->drawLabeling( mRenderContext );
     mLabelingEngine->exit();
@@ -813,7 +815,7 @@
     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
     {

Modified: trunk/qgis/src/core/qgsmaprenderer.h
===================================================================
--- trunk/qgis/src/core/qgsmaprenderer.h	2009-12-20 16:12:02 UTC (rev 12539)
+++ trunk/qgis/src/core/qgsmaprenderer.h	2009-12-20 16:35:45 UTC (rev 12540)
@@ -47,6 +47,8 @@
 
     //! 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

Modified: trunk/qgis/src/plugins/labeling/pallabeling.cpp
===================================================================
--- trunk/qgis/src/plugins/labeling/pallabeling.cpp	2009-12-20 16:12:02 UTC (rev 12539)
+++ trunk/qgis/src/plugins/labeling/pallabeling.cpp	2009-12-20 16:35:45 UTC (rev 12540)
@@ -288,6 +288,14 @@
 }
 
 
+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 @@
     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;

Modified: trunk/qgis/src/plugins/labeling/pallabeling.h
===================================================================
--- trunk/qgis/src/plugins/labeling/pallabeling.h	2009-12-20 16:12:02 UTC (rev 12539)
+++ trunk/qgis/src/plugins/labeling/pallabeling.h	2009-12-20 16:35:45 UTC (rev 12540)
@@ -123,6 +123,8 @@
 
     //! 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



More information about the QGIS-commit mailing list