[QGIS Commit] r12346 - in trunk/qgis/src/core: . symbology-ng

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Dec 6 18:26:22 EST 2009


Author: jef
Date: 2009-12-06 18:26:22 -0500 (Sun, 06 Dec 2009)
New Revision: 12346

Modified:
   trunk/qgis/src/core/qgsvectorlayer.cpp
   trunk/qgis/src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
   trunk/qgis/src/core/symbology-ng/qgscategorizedsymbolrendererv2.h
   trunk/qgis/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
   trunk/qgis/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h
   trunk/qgis/src/core/symbology-ng/qgsrendererv2.cpp
   trunk/qgis/src/core/symbology-ng/qgsrendererv2.h
   trunk/qgis/src/core/symbology-ng/qgssinglesymbolrendererv2.cpp
   trunk/qgis/src/core/symbology-ng/qgssinglesymbolrendererv2.h
Log:
use QgsVectorLayer::fieldNameIndex() in symbology-ng and add python binding

Modified: trunk/qgis/src/core/qgsvectorlayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.cpp	2009-12-06 23:24:04 UTC (rev 12345)
+++ trunk/qgis/src/core/qgsvectorlayer.cpp	2009-12-06 23:26:22 UTC (rev 12346)
@@ -333,7 +333,7 @@
         attributes.append( attrNum );
       }
       // make sure the renderer is ready for classification ("symbolForFeature")
-      mRendererV2->startRender( rendererContext, pendingFields() );
+      mRendererV2->startRender( rendererContext, this );
     }
 
     // Add fields required for labels
@@ -686,14 +686,14 @@
 
 void QgsVectorLayer::drawRendererV2( QgsRenderContext& rendererContext, bool labeling )
 {
-  mRendererV2->startRender( rendererContext, pendingFields() );
+  mRendererV2->startRender( rendererContext, this );
 
   QgsSingleSymbolRendererV2* selRenderer = NULL;
   if ( !mSelectedFeatureIds.isEmpty() )
   {
     selRenderer = new QgsSingleSymbolRendererV2( QgsSymbolV2::defaultSymbol( geometryType() ) );
     selRenderer->symbol()->setColor( QgsRenderer::selectionColor() );
-    selRenderer->startRender( rendererContext, pendingFields() );
+    selRenderer->startRender( rendererContext, this );
   }
 
   QgsFeature fet;
@@ -728,14 +728,14 @@
   QHash< QgsSymbolV2*, QList<QgsFeature> > features; // key = symbol, value = array of features
 
   // startRender must be called before symbolForFeature() calls to make sure renderer is ready
-  mRendererV2->startRender( rendererContext, pendingFields() );
+  mRendererV2->startRender( rendererContext, this );
 
   QgsSingleSymbolRendererV2* selRenderer = NULL;
   if ( !mSelectedFeatureIds.isEmpty() )
   {
     selRenderer = new QgsSingleSymbolRendererV2( QgsSymbolV2::defaultSymbol( geometryType() ) );
     selRenderer->symbol()->setColor( QgsRenderer::selectionColor() );
-    selRenderer->startRender( rendererContext, pendingFields() );
+    selRenderer->startRender( rendererContext, this );
   }
 
   // 1. fetch features

Modified: trunk/qgis/src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp	2009-12-06 23:24:04 UTC (rev 12345)
+++ trunk/qgis/src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp	2009-12-06 23:26:22 UTC (rev 12346)
@@ -6,6 +6,7 @@
 #include "qgsvectorcolorrampv2.h"
 
 #include "qgsfeature.h"
+#include "qgsvectorlayer.h"
 #include "qgslogger.h"
 
 #include <QDomDocument>
@@ -172,13 +173,13 @@
   mCategories.clear();
 }
 
-void QgsCategorizedSymbolRendererV2::startRender( QgsRenderContext& context, const QgsFieldMap& fields )
+void QgsCategorizedSymbolRendererV2::startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer )
 {
   // make sure that the hash table is up to date
   rebuildHash();
 
   // find out classification attribute index from name
-  mAttrNum = fieldNameIndex( fields, mAttrName );
+  mAttrNum = vlayer ? vlayer->fieldNameIndex( mAttrName ) : -1;
 
   QgsCategoryList::iterator it = mCategories.begin();
   for ( ; it != mCategories.end(); ++it )

Modified: trunk/qgis/src/core/symbology-ng/qgscategorizedsymbolrendererv2.h
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgscategorizedsymbolrendererv2.h	2009-12-06 23:24:04 UTC (rev 12345)
+++ trunk/qgis/src/core/symbology-ng/qgscategorizedsymbolrendererv2.h	2009-12-06 23:26:22 UTC (rev 12346)
@@ -6,6 +6,7 @@
 #include <QHash>
 
 class QgsVectorColorRampV2;
+class QgsVectorLayer;
 
 class CORE_EXPORT QgsRendererCategoryV2
 {
@@ -47,7 +48,7 @@
 
     virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
 
-    virtual void startRender( QgsRenderContext& context, const QgsFieldMap& fields );
+    virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer );
 
     virtual void stopRender( QgsRenderContext& context );
 

Modified: trunk/qgis/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp	2009-12-06 23:24:04 UTC (rev 12345)
+++ trunk/qgis/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp	2009-12-06 23:26:22 UTC (rev 12346)
@@ -6,6 +6,7 @@
 #include "qgsvectorcolorrampv2.h"
 
 #include "qgsfeature.h"
+#include "qgsvectorlayer.h"
 #include "qgslogger.h"
 
 #include <QDomDocument>
@@ -123,10 +124,10 @@
 
 }
 
-void QgsGraduatedSymbolRendererV2::startRender( QgsRenderContext& context, const QgsFieldMap& fields )
+void QgsGraduatedSymbolRendererV2::startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer )
 {
   // find out classification attribute index from name
-  mAttrNum = fieldNameIndex( fields, mAttrName );
+  mAttrNum = vlayer ? vlayer->fieldNameIndex( mAttrName ) : -1;
 
   QgsRangeList::iterator it = mRanges.begin();
   for ( ; it != mRanges.end(); ++it )

Modified: trunk/qgis/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h	2009-12-06 23:24:04 UTC (rev 12345)
+++ trunk/qgis/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.h	2009-12-06 23:26:22 UTC (rev 12346)
@@ -45,7 +45,7 @@
 
     virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
 
-    virtual void startRender( QgsRenderContext& context, const QgsFieldMap& fields );
+    virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer );
 
     virtual void stopRender( QgsRenderContext& context );
 

Modified: trunk/qgis/src/core/symbology-ng/qgsrendererv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgsrendererv2.cpp	2009-12-06 23:24:04 UTC (rev 12345)
+++ trunk/qgis/src/core/symbology-ng/qgsrendererv2.cpp	2009-12-06 23:26:22 UTC (rev 12346)
@@ -304,14 +304,3 @@
   // empty list by default
   return QgsLegendSymbologyList();
 }
-
-
-int QgsFeatureRendererV2::fieldNameIndex( const QgsFieldMap& fields, const QString& fieldName )
-{
-  for ( QgsFieldMap::const_iterator it = fields.constBegin(); it != fields.constEnd(); ++it )
-  {
-    if ( it->name() == fieldName )
-      return it.key();
-  }
-  return -1;
-}

Modified: trunk/qgis/src/core/symbology-ng/qgsrendererv2.h
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgsrendererv2.h	2009-12-06 23:24:04 UTC (rev 12345)
+++ trunk/qgis/src/core/symbology-ng/qgsrendererv2.h	2009-12-06 23:26:22 UTC (rev 12346)
@@ -3,7 +3,6 @@
 #define QGSRENDERERV2_H
 
 #include "qgis.h"
-#include "qgsfield.h" // for QgsFieldMap
 
 #include <QList>
 #include <QString>
@@ -17,6 +16,7 @@
 class QgsSymbolV2;
 class QgsRenderContext;
 class QgsFeature;
+class QgsVectorLayer;
 
 typedef QList<QgsSymbolV2*> QgsSymbolV2List;
 typedef QMap<QString, QgsSymbolV2* > QgsSymbolV2Map;
@@ -62,7 +62,7 @@
     // to be overridden
     virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature ) = 0;
 
-    virtual void startRender( QgsRenderContext& context, const QgsFieldMap& fields ) = 0;
+    virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer ) = 0;
 
     virtual void stopRender( QgsRenderContext& context ) = 0;
 
@@ -92,12 +92,6 @@
     //! return a list of symbology items for the legend
     virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
 
-    /** Returns the index of a field name or -1 if the field does not exist
-      * copied from QgsVectorDataProvider... d'oh... probably should be elsewhere
-      */
-    static int fieldNameIndex( const QgsFieldMap& fields, const QString& fieldName );
-
-
   protected:
     QgsFeatureRendererV2( QString type );
 

Modified: trunk/qgis/src/core/symbology-ng/qgssinglesymbolrendererv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssinglesymbolrendererv2.cpp	2009-12-06 23:24:04 UTC (rev 12345)
+++ trunk/qgis/src/core/symbology-ng/qgssinglesymbolrendererv2.cpp	2009-12-06 23:26:22 UTC (rev 12346)
@@ -23,7 +23,7 @@
   return mSymbol;
 }
 
-void QgsSingleSymbolRendererV2::startRender( QgsRenderContext& context, const QgsFieldMap& fields )
+void QgsSingleSymbolRendererV2::startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer )
 {
   mSymbol->startRender( context );
 }

Modified: trunk/qgis/src/core/symbology-ng/qgssinglesymbolrendererv2.h
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgssinglesymbolrendererv2.h	2009-12-06 23:24:04 UTC (rev 12345)
+++ trunk/qgis/src/core/symbology-ng/qgssinglesymbolrendererv2.h	2009-12-06 23:26:22 UTC (rev 12346)
@@ -13,7 +13,7 @@
 
     virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
 
-    virtual void startRender( QgsRenderContext& context, const QgsFieldMap& fields );
+    virtual void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer );
 
     virtual void stopRender( QgsRenderContext& context );
 



More information about the QGIS-commit mailing list