Skip to content
Permalink
Browse files

[FEATURE] add QgsVectorLayer::fieldNameIndex()

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12344 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Dec 6, 2009
1 parent 8006e3c commit 60d9cca0159689c94c3f80b9b4b25dbb785942b8
@@ -329,7 +329,7 @@ void QgsVectorLayer::drawLabels( QgsRenderContext& rendererContext )
{
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 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
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 @@ QPair<QString, QString> QgsVectorLayer::checkedState( int idx )
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;
}
@@ -528,6 +528,11 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** 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 );
@@ -267,7 +267,7 @@ QgsGraduatedSymbolRendererV2* QgsGraduatedSymbolRendererV2::createRenderer(
{
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();
@@ -242,7 +242,7 @@ static void _createCategories( QgsCategoryList& cats, QList<QVariant>& values, Q
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 );

0 comments on commit 60d9cca

Please sign in to comment.
You can’t perform that action at this time.