[Qgis-developer] Remove editing functions from QgsVectorLayer

Martin Dobias wonder.sk at gmail.com
Tue Apr 16 02:47:07 PDT 2013

On Tue, Apr 16, 2013 at 11:26 AM, Nathan Woodrow <madmanwoo at gmail.com> wrote:
> Personally I'm not a fan of that.
> Why don't we make startEditing() return a edit buffer/edit session. So you
> could do this:
> session = layer.editSession()
> session.addFeature(feature)
> ...
> session.commitChanges()
> This would mean that everyone can keep their own edit buffers and can do
> what they want.  Means you could also doing this:
> with layer.editSession() as session:
>      session.addFeature(...)
> which will commit the features at the end.

But I think this is exactly what the 3rd party code should not be
doing (to automatically create and commit changes). If a developer
wants to do that, they should call
layer.dataProvider().addFeatures(...). It will be faster and it will
not mess the user's edit buffer - IMHO 3rd party code should not call
startEditing() or commitChanges()/rollback() at its will. And the only
case where you may want to use the editing buffer directly is when
e.g. creating a new tool for vector layer editing or something similar
where the user should be able to undo/redo the action performed by the
plugin code.


More information about the Qgis-developer mailing list