Skip to content

Commit 04a2824

Browse files
committed
execute undo stack on rollBack() (fixes #4635)
1 parent 62ba02e commit 04a2824

File tree

1 file changed

+11
-29
lines changed

1 file changed

+11
-29
lines changed

src/core/qgsvectorlayer.cpp

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3908,41 +3908,22 @@ bool QgsVectorLayer::rollBack()
39083908

39093909
if ( isModified() )
39103910
{
3911-
while ( mAddedAttributeIds.size() > 0 )
3911+
while ( undoStack()->canUndo() )
39123912
{
3913-
int idx = *mAddedAttributeIds.begin();
3914-
mAddedAttributeIds.remove( idx );
3915-
mUpdatedFields.remove( idx );
3916-
emit attributeDeleted( idx );
3913+
undoStack()->undo();
39173914
}
39183915

3919-
while ( mDeletedAttributeIds.size() > 0 )
3920-
{
3921-
int idx = *mDeletedAttributeIds.begin();
3922-
mDeletedAttributeIds.remove( idx );
3923-
emit attributeAdded( idx );
3924-
}
3925-
3926-
// roll back changed attribute values
3927-
mChangedAttributeValues.clear();
3928-
3929-
// roll back changed geometries
3930-
mChangedGeometries.clear();
3931-
3932-
// Roll back added features
3933-
// Delete the features themselves before deleting the references to them.
3934-
mAddedFeatures.clear();
3935-
3936-
// Roll back deleted features
3937-
mDeletedFeatureIds.clear();
3916+
Q_ASSERT( mAddedAttributeIds.isEmpty() );
3917+
Q_ASSERT( mDeletedAttributeIds.isEmpty() );
3918+
Q_ASSERT( mChangedAttributeValues.isEmpty() );
3919+
Q_ASSERT( mChangedGeometries.isEmpty() );
3920+
Q_ASSERT( mAddedFeatures.isEmpty() );
39383921

39393922
updateFieldMap();
39403923
}
39413924

39423925
deleteCachedGeometries();
39433926

3944-
undoStack()->clear();
3945-
39463927
mEditable = false;
39473928
emit editingStopped();
39483929

@@ -4848,13 +4829,12 @@ void QgsVectorLayer::redoEditCommand( QgsUndoCommand* cmd )
48484829
if ( attrChIt.value().target.isNull() )
48494830
{
48504831
mChangedAttributeValues[fid].remove( attrChIt.key() );
4832+
if ( mChangedAttributeValues[fid].isEmpty() )
4833+
mChangedAttributeValues.remove( fid );
48514834
}
48524835
else
48534836
{
48544837
mChangedAttributeValues[fid][attrChIt.key()] = attrChIt.value().target;
4855-
QgsFeature f;
4856-
featureAtId( fid, f, false, true );
4857-
f.changeAttribute( attrChIt.key(), attrChIt.value().target );
48584838
}
48594839
}
48604840
else
@@ -4985,6 +4965,8 @@ void QgsVectorLayer::undoEditCommand( QgsUndoCommand* cmd )
49854965
if ( attrChIt.value().isFirstChange )
49864966
{
49874967
mChangedAttributeValues[fid].remove( attrChIt.key() );
4968+
if ( mChangedAttributeValues[fid].isEmpty() )
4969+
mChangedAttributeValues.remove( fid );
49884970
}
49894971
else
49904972
{

0 commit comments

Comments
 (0)