Skip to content
Permalink
Browse files

Fix issue #7169

If removing multiple attributes, remove the indices in descending order, so it does not get confused
  • Loading branch information
m-kuhn authored and jef-n committed Mar 27, 2013
1 parent 6596f48 commit 0d3a387993a035d072323d8fd734848583b48537
Showing with 28 additions and 40 deletions.
  1. +2 −40 src/app/qgsattributetabledialog.cpp
  2. +17 −0 src/core/qgsvectorlayer.cpp
  3. +9 −0 src/core/qgsvectorlayer.h
@@ -493,23 +493,13 @@ void QgsAttributeTableDialog::on_mRemoveAttribute_clicked()
QgsAttributeTableModel* masterModel = mMainView->masterModel();

mLayer->beginEditCommand( tr( "Deleted attribute" ) );
bool deleted = false;
QList<int>::const_iterator it = attributes.constBegin();
for ( ; it != attributes.constEnd(); ++it )
{
if ( mLayer->deleteAttribute( *it ) )
{
deleted = true;
}
}

if ( deleted )
if ( mLayer->deleteAttributes( attributes ) )
{
mLayer->endEditCommand();
}
else
{
QMessageBox::critical( 0, tr( "Attribute Error" ), tr( "The attribute(s) could not be deleted" ) );
QgisApp::instance()->messageBar()->pushMessage( tr( "Attribute error" ), tr( "The attribute(s) could not be deleted" ), QgsMessageBar::WARNING, QgisApp::instance()->messageTimeout() );
mLayer->destroyEditCommand();
}
// update model - a field has been added or updated
@@ -518,34 +508,6 @@ void QgsAttributeTableDialog::on_mRemoveAttribute_clicked()
}
}





























void QgsAttributeTableDialog::filterQueryChanged( const QString& query )
{
QString str;
@@ -2980,6 +2980,23 @@ bool QgsVectorLayer::deleteAttribute( int index )
return mEditBuffer->deleteAttribute( index );
}

bool QgsVectorLayer::deleteAttributes( QList<int> attrs )
{
bool deleted = false;

qSort( attrs.begin(), attrs.end(), qGreater<int>() );

foreach( int attr, attrs )
{
if ( deleteAttribute( attr ) )
{
deleted = true;
}
}

return deleted;
}

bool QgsVectorLayer::deleteFeature( QgsFeatureId fid )
{
if ( !mEditBuffer )
@@ -667,6 +667,15 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
/** delete an attribute field (but does not commit it) */
bool deleteAttribute( int attr );

/**
* Deletes a list of attribute fields (but does not commit it)
*
* @param attrs the indices of the attributes to delete
* @return true if at least one attribute has been deleted
*
*/
bool deleteAttributes( QList<int> attrs );

/** Insert a copy of the given features into the layer (but does not commit it) */
bool addFeatures( QgsFeatureList features, bool makeSelected = true );

0 comments on commit 0d3a387

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