I am testing a script that add features from one *.shp file to another. But also I need to wait for user to save or discard changes. But it seems that adding features from script using
dataProvider() automatically commit changes without waiting for user to do it.
Here is my code
layer_first = QgsProject.instance().mapLayersByName(u'layer_first') layer_second = QgsProject.instance().mapLayersByName(u'layer_second') feat = [n.geometry() for n in layer_first.getSelectedFeatures()] f_pnt = QgsFeature() f_pnt.setGeometry(feat) layer_second.startEditing() layer_second.dataProvider().addFeatures([f_pnt])
layer_second.rollback(True) # doesn't work qgis.utils.iface.actionRollbackEdits().trigger() # also doesn't work with edit(layer_second): # works only from edit session which is not preferrable layer_second.dataProvider().addFeatures([f_pnt])