[QGIS Commit] r12344 - in trunk/qgis/src: core core/symbology-ng gui/symbology-ng

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Dec 6 17:26:00 EST 2009


Author: jef
Date: 2009-12-06 17:26:00 -0500 (Sun, 06 Dec 2009)
New Revision: 12344

Modified:
   trunk/qgis/src/core/qgsvectorlayer.cpp
   trunk/qgis/src/core/qgsvectorlayer.h
   trunk/qgis/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
   trunk/qgis/src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp
Log:
[FEATURE] add QgsVectorLayer::fieldNameIndex()

Modified: trunk/qgis/src/core/qgsvectorlayer.cpp
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.cpp	2009-12-06 21:30:51 UTC (rev 12343)
+++ trunk/qgis/src/core/qgsvectorlayer.cpp	2009-12-06 22:26:00 UTC (rev 12344)
@@ -329,7 +329,7 @@
     {
       foreach( QString attrName, mRendererV2->usedAttributes() )
       {
-        int attrNum = QgsFeatureRendererV2::fieldNameIndex( pendingFields(), attrName );
+        int attrNum = fieldNameIndex( attrName );
         attributes.append( attrNum );
       }
       // make sure the renderer is ready for classification ("symbolForFeature")
@@ -831,7 +831,7 @@
     QgsAttributeList attributes;
     foreach( QString attrName, mRendererV2->usedAttributes() )
     {
-      int attrNum = QgsFeatureRendererV2::fieldNameIndex( pendingFields(), attrName );
+      int attrNum = fieldNameIndex( attrName );
       attributes.append( attrNum );
       QgsDebugMsg( "attrs: " + attrName + " - " + QString::number( attrNum ) );
     }
@@ -4468,3 +4468,17 @@
   else
     return QPair<QString, QString>( "1", "0" );
 }
+
+int QgsVectorLayer::fieldNameIndex( const QString& fieldName ) const
+{
+  const QgsFieldMap &theFields = pendingFields();
+
+  for ( QgsFieldMap::const_iterator it = theFields.constBegin(); it != theFields.constEnd(); ++it )
+  {
+    if ( it->name() == fieldName )
+    {
+      return it.key();
+    }
+  }
+  return -1;
+}

Modified: trunk/qgis/src/core/qgsvectorlayer.h
===================================================================
--- trunk/qgis/src/core/qgsvectorlayer.h	2009-12-06 21:30:51 UTC (rev 12343)
+++ trunk/qgis/src/core/qgsvectorlayer.h	2009-12-06 22:26:00 UTC (rev 12344)
@@ -528,6 +528,11 @@
     /** Execute redo operation. To be called only from QgsVectorLayerUndoCommand. */
     void redoEditCommand( QgsUndoCommand* cmd );
 
+    /** Returns the index of a field name or -1 if the field does not exist
+      @note this method was added in version 1.4
+     */
+    int fieldNameIndex( const QString& fieldName ) const;
+
   public slots:
     /** Select feature by its ID, optionally emit signal selectionChanged() */
     void select( int featureId, bool emitSignal = TRUE );

Modified: trunk/qgis/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
===================================================================
--- trunk/qgis/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp	2009-12-06 21:30:51 UTC (rev 12343)
+++ trunk/qgis/src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp	2009-12-06 22:26:00 UTC (rev 12344)
@@ -267,7 +267,7 @@
 {
   QgsVectorDataProvider* provider = vlayer->dataProvider();
 
-  int attrNum = fieldNameIndex( vlayer->pendingFields(), attrName );
+  int attrNum = vlayer->fieldNameIndex( attrName );
 
   double minimum = provider->minimumValue( attrNum ).toDouble();
   double maximum = provider->maximumValue( attrNum ).toDouble();

Modified: trunk/qgis/src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp
===================================================================
--- trunk/qgis/src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp	2009-12-06 21:30:51 UTC (rev 12343)
+++ trunk/qgis/src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp	2009-12-06 22:26:00 UTC (rev 12344)
@@ -242,7 +242,7 @@
 void QgsCategorizedSymbolRendererV2Widget::addCategories()
 {
   QString attrName = cboCategorizedColumn->currentText();
-  int idx = QgsFeatureRendererV2::fieldNameIndex( mLayer->pendingFields(), attrName );
+  int idx = mLayer->fieldNameIndex( attrName );
   QList<QVariant> unique_vals;
   mLayer->dataProvider()->uniqueValues( idx, unique_vals );
 



More information about the QGIS-commit mailing list