bool QgsMemoryProvider::renameAttributes( const QgsFieldNameMap& renamedAttributes ) { QgsFieldNameMap::const_iterator renameIt = renamedAttributes.constBegin(); bool result = true; for ( ; renameIt != renamedAttributes.constEnd(); ++renameIt ) { int fieldIndex = renameIt.key(); if ( fieldIndex < 0 || fieldIndex >= mFields.count() ) { result = false; continue; } if ( mFields.indexFromName( renameIt.value() ) >= 0 ) { //field name already in use result = false; continue; } mFields[ fieldIndex ].setName( renameIt.value() ); } return result; }
void QgsVectorLayerEditBuffer::updateFields( QgsFields& fields ) { // delete attributes from the higher indices to lower indices for ( int i = mDeletedAttributeIds.count() - 1; i >= 0; --i ) { fields.remove( mDeletedAttributeIds[i] ); } // add new fields for ( int i = 0; i < mAddedAttributes.count(); ++i ) { fields.append( mAddedAttributes[i], QgsFields::OriginEdit, i ); } // rename fields QgsFieldNameMap::const_iterator renameIt = mRenamedAttributes.constBegin(); for ( ; renameIt != mRenamedAttributes.constEnd(); ++renameIt ) { fields[ renameIt.key()].setName( renameIt.value() ); } }