Skip to content

Commit 24c20e8

Browse files
author
jef
committedDec 6, 2009
[FEATURE] add QgsVectorLayer::fieldNameIndex()
git-svn-id: http://svn.osgeo.org/qgis/trunk@12344 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 944c457 commit 24c20e8

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed
 

‎src/core/qgsvectorlayer.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ void QgsVectorLayer::drawLabels( QgsRenderContext& rendererContext )
329329
{
330330
foreach( QString attrName, mRendererV2->usedAttributes() )
331331
{
332-
int attrNum = QgsFeatureRendererV2::fieldNameIndex( pendingFields(), attrName );
332+
int attrNum = fieldNameIndex( attrName );
333333
attributes.append( attrNum );
334334
}
335335
// make sure the renderer is ready for classification ("symbolForFeature")
@@ -831,7 +831,7 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
831831
QgsAttributeList attributes;
832832
foreach( QString attrName, mRendererV2->usedAttributes() )
833833
{
834-
int attrNum = QgsFeatureRendererV2::fieldNameIndex( pendingFields(), attrName );
834+
int attrNum = fieldNameIndex( attrName );
835835
attributes.append( attrNum );
836836
QgsDebugMsg( "attrs: " + attrName + " - " + QString::number( attrNum ) );
837837
}
@@ -4468,3 +4468,17 @@ QPair<QString, QString> QgsVectorLayer::checkedState( int idx )
44684468
else
44694469
return QPair<QString, QString>( "1", "0" );
44704470
}
4471+
4472+
int QgsVectorLayer::fieldNameIndex( const QString& fieldName ) const
4473+
{
4474+
const QgsFieldMap &theFields = pendingFields();
4475+
4476+
for ( QgsFieldMap::const_iterator it = theFields.constBegin(); it != theFields.constEnd(); ++it )
4477+
{
4478+
if ( it->name() == fieldName )
4479+
{
4480+
return it.key();
4481+
}
4482+
}
4483+
return -1;
4484+
}

‎src/core/qgsvectorlayer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,11 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
528528
/** Execute redo operation. To be called only from QgsVectorLayerUndoCommand. */
529529
void redoEditCommand( QgsUndoCommand* cmd );
530530

531+
/** Returns the index of a field name or -1 if the field does not exist
532+
@note this method was added in version 1.4
533+
*/
534+
int fieldNameIndex( const QString& fieldName ) const;
535+
531536
public slots:
532537
/** Select feature by its ID, optionally emit signal selectionChanged() */
533538
void select( int featureId, bool emitSignal = TRUE );

‎src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ QgsGraduatedSymbolRendererV2* QgsGraduatedSymbolRendererV2::createRenderer(
267267
{
268268
QgsVectorDataProvider* provider = vlayer->dataProvider();
269269

270-
int attrNum = fieldNameIndex( vlayer->pendingFields(), attrName );
270+
int attrNum = vlayer->fieldNameIndex( attrName );
271271

272272
double minimum = provider->minimumValue( attrNum ).toDouble();
273273
double maximum = provider->maximumValue( attrNum ).toDouble();

‎src/gui/symbology-ng/qgscategorizedsymbolrendererv2widget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static void _createCategories( QgsCategoryList& cats, QList<QVariant>& values, Q
242242
void QgsCategorizedSymbolRendererV2Widget::addCategories()
243243
{
244244
QString attrName = cboCategorizedColumn->currentText();
245-
int idx = QgsFeatureRendererV2::fieldNameIndex( mLayer->pendingFields(), attrName );
245+
int idx = mLayer->fieldNameIndex( attrName );
246246
QList<QVariant> unique_vals;
247247
mLayer->dataProvider()->uniqueValues( idx, unique_vals );
248248

0 commit comments

Comments
 (0)