@@ -3908,41 +3908,22 @@ bool QgsVectorLayer::rollBack()
3908
3908
3909
3909
if ( isModified () )
3910
3910
{
3911
- while ( mAddedAttributeIds . size () > 0 )
3911
+ while ( undoStack ()-> canUndo () )
3912
3912
{
3913
- int idx = *mAddedAttributeIds .begin ();
3914
- mAddedAttributeIds .remove ( idx );
3915
- mUpdatedFields .remove ( idx );
3916
- emit attributeDeleted ( idx );
3913
+ undoStack ()->undo ();
3917
3914
}
3918
3915
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 () );
3938
3921
3939
3922
updateFieldMap ();
3940
3923
}
3941
3924
3942
3925
deleteCachedGeometries ();
3943
3926
3944
- undoStack ()->clear ();
3945
-
3946
3927
mEditable = false ;
3947
3928
emit editingStopped ();
3948
3929
@@ -4848,13 +4829,12 @@ void QgsVectorLayer::redoEditCommand( QgsUndoCommand* cmd )
4848
4829
if ( attrChIt.value ().target .isNull () )
4849
4830
{
4850
4831
mChangedAttributeValues [fid].remove ( attrChIt.key () );
4832
+ if ( mChangedAttributeValues [fid].isEmpty () )
4833
+ mChangedAttributeValues .remove ( fid );
4851
4834
}
4852
4835
else
4853
4836
{
4854
4837
mChangedAttributeValues [fid][attrChIt.key ()] = attrChIt.value ().target ;
4855
- QgsFeature f;
4856
- featureAtId ( fid, f, false , true );
4857
- f.changeAttribute ( attrChIt.key (), attrChIt.value ().target );
4858
4838
}
4859
4839
}
4860
4840
else
@@ -4985,6 +4965,8 @@ void QgsVectorLayer::undoEditCommand( QgsUndoCommand* cmd )
4985
4965
if ( attrChIt.value ().isFirstChange )
4986
4966
{
4987
4967
mChangedAttributeValues [fid].remove ( attrChIt.key () );
4968
+ if ( mChangedAttributeValues [fid].isEmpty () )
4969
+ mChangedAttributeValues .remove ( fid );
4988
4970
}
4989
4971
else
4990
4972
{
0 commit comments