@@ -3772,41 +3772,22 @@ bool QgsVectorLayer::rollBack()
3772
3772
3773
3773
if ( isModified () )
3774
3774
{
3775
- while ( mAddedAttributeIds . size () > 0 )
3775
+ while ( undoStack ()-> canUndo () )
3776
3776
{
3777
- int idx = *mAddedAttributeIds .begin ();
3778
- mAddedAttributeIds .remove ( idx );
3779
- mUpdatedFields .remove ( idx );
3780
- emit attributeDeleted ( idx );
3777
+ undoStack ()->undo ();
3781
3778
}
3782
3779
3783
- while ( mDeletedAttributeIds .size () > 0 )
3784
- {
3785
- int idx = *mDeletedAttributeIds .begin ();
3786
- mDeletedAttributeIds .remove ( idx );
3787
- emit attributeAdded ( idx );
3788
- }
3789
-
3790
- // roll back changed attribute values
3791
- mChangedAttributeValues .clear ();
3792
-
3793
- // roll back changed geometries
3794
- mChangedGeometries .clear ();
3795
-
3796
- // Roll back added features
3797
- // Delete the features themselves before deleting the references to them.
3798
- mAddedFeatures .clear ();
3799
-
3800
- // Roll back deleted features
3801
- mDeletedFeatureIds .clear ();
3780
+ Q_ASSERT ( mAddedAttributeIds .isEmpty () );
3781
+ Q_ASSERT ( mDeletedAttributeIds .isEmpty () );
3782
+ Q_ASSERT ( mChangedAttributeValues .isEmpty () );
3783
+ Q_ASSERT ( mChangedGeometries .isEmpty () );
3784
+ Q_ASSERT ( mAddedFeatures .isEmpty () );
3802
3785
3803
3786
updateFieldMap ();
3804
3787
}
3805
3788
3806
3789
deleteCachedGeometries ();
3807
3790
3808
- undoStack ()->clear ();
3809
-
3810
3791
mEditable = false ;
3811
3792
emit editingStopped ();
3812
3793
@@ -4741,13 +4722,12 @@ void QgsVectorLayer::redoEditCommand( QgsUndoCommand* cmd )
4741
4722
if ( attrChIt.value ().target .isNull () )
4742
4723
{
4743
4724
mChangedAttributeValues [fid].remove ( attrChIt.key () );
4725
+ if ( mChangedAttributeValues [fid].isEmpty () )
4726
+ mChangedAttributeValues .remove ( fid );
4744
4727
}
4745
4728
else
4746
4729
{
4747
4730
mChangedAttributeValues [fid][attrChIt.key ()] = attrChIt.value ().target ;
4748
- QgsFeature f;
4749
- featureAtId ( fid, f, false , true );
4750
- f.changeAttribute ( attrChIt.key (), attrChIt.value ().target );
4751
4731
}
4752
4732
}
4753
4733
else
@@ -4871,6 +4851,8 @@ void QgsVectorLayer::undoEditCommand( QgsUndoCommand* cmd )
4871
4851
if ( attrChIt.value ().isFirstChange )
4872
4852
{
4873
4853
mChangedAttributeValues [fid].remove ( attrChIt.key () );
4854
+ if ( mChangedAttributeValues [fid].isEmpty () )
4855
+ mChangedAttributeValues .remove ( fid );
4874
4856
}
4875
4857
else
4876
4858
{
0 commit comments