[Qgis-developer] Adding features with an editing buffer - undo action unavailable in the GUI?

Ricardo Filipe Soares Garcia da ricardo.garcia.silva at gmail.com
Sun May 20 16:26:32 PDT 2012

Hi list

I am writing a plugin that creates new features. According to the
pyqgis cookbook[0], and the API docs[1], when I call the addFeatures
method on a QgsVectorLayer, the features should get added to the
layers editing buffer. It is my understanding that this action ought
to be undo-able, since the changes haven't been commited yet. But the
undo icon in the QGIS GUI doesn't seem to be aware of the changes that
the plugin is making to the layer. Do I have to hook up the changes to
the undo/redo stack myself? How can I do this?

The code is available on github[2], and here is an excerpt:

def create_point(self):
        layer = self.canvas.currentLayer()
        point = self.calculate_point() # returns a QgsPoint
        f = qgis.core.QgsFeature()
        geom = qgis.core.QgsGeometry.fromPoint(point)
        layer.addFeatures([f], False)

Please note that the new feature is being created successfully. I just
want the user to have the ability to undo the feature creation.

Also, when I press the 'toggle editing' button in the digitizing
toolbar, in order to save the changes I am getting a strange

- If I choose to save my changes, everything goes fine,
- If I choose to close without saving, QGIS crashes with:

Fatal: ASSERT: "mAddedFeatures.isEmpty()" in file
/home/ricardo/dev/Quantum-GIS/src/core/qgsvectorlayer.cpp, line 3982

and a lot more output in the stacktrace.

Thanks for you help!

[0] - http://www.qgis.org/pyqgis-cookbook/vector.html#modifying-vector-layers-with-an-editing-buffer
[1] - http://qgis.org/api/classQgsVectorLayer.html#a9936fbfbd69efc6583062e16c6c219ed
[2] - https://github.com/ricardogsilva/geomtools

___________________________ ___ __
Ricardo Garcia Silva

More information about the Qgis-developer mailing list