Skip to content

Commit

Permalink
execute undo stack on rollBack() (fixes #4635)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n authored and alexbruy committed Feb 11, 2012
1 parent 09ce9d4 commit 4ba2c39
Showing 1 changed file with 11 additions and 29 deletions.
40 changes: 11 additions & 29 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -3772,41 +3772,22 @@ bool QgsVectorLayer::rollBack()

if ( isModified() )
{
while ( mAddedAttributeIds.size() > 0 )
while ( undoStack()->canUndo() )
{
int idx = *mAddedAttributeIds.begin();
mAddedAttributeIds.remove( idx );
mUpdatedFields.remove( idx );
emit attributeDeleted( idx );
undoStack()->undo();
}

while ( mDeletedAttributeIds.size() > 0 )
{
int idx = *mDeletedAttributeIds.begin();
mDeletedAttributeIds.remove( idx );
emit attributeAdded( idx );
}

// roll back changed attribute values
mChangedAttributeValues.clear();

// roll back changed geometries
mChangedGeometries.clear();

// Roll back added features
// Delete the features themselves before deleting the references to them.
mAddedFeatures.clear();

// Roll back deleted features
mDeletedFeatureIds.clear();
Q_ASSERT( mAddedAttributeIds.isEmpty() );
Q_ASSERT( mDeletedAttributeIds.isEmpty() );
Q_ASSERT( mChangedAttributeValues.isEmpty() );
Q_ASSERT( mChangedGeometries.isEmpty() );
Q_ASSERT( mAddedFeatures.isEmpty() );

updateFieldMap();
}

deleteCachedGeometries();

undoStack()->clear();

mEditable = false;
emit editingStopped();

Expand Down Expand Up @@ -4741,13 +4722,12 @@ void QgsVectorLayer::redoEditCommand( QgsUndoCommand* cmd )
if ( attrChIt.value().target.isNull() )
{
mChangedAttributeValues[fid].remove( attrChIt.key() );
if ( mChangedAttributeValues[fid].isEmpty() )
mChangedAttributeValues.remove( fid );
}
else
{
mChangedAttributeValues[fid][attrChIt.key()] = attrChIt.value().target;
QgsFeature f;
featureAtId( fid, f, false, true );
f.changeAttribute( attrChIt.key(), attrChIt.value().target );
}
}
else
Expand Down Expand Up @@ -4871,6 +4851,8 @@ void QgsVectorLayer::undoEditCommand( QgsUndoCommand* cmd )
if ( attrChIt.value().isFirstChange )
{
mChangedAttributeValues[fid].remove( attrChIt.key() );
if ( mChangedAttributeValues[fid].isEmpty() )
mChangedAttributeValues.remove( fid );
}
else
{
Expand Down

0 comments on commit 4ba2c39

Please sign in to comment.