I'm trying to rollback automatically the changes in features of a in-memory vector layer that don't meet certain criteria.

The code I'm using for testing looks like this:


def some_function()
  tmpLayer = QgsVectorLayer("LineString", "Aristas_tmp", "memory")     


@pyqtSlot(int, QgsGeometry)
def onLineGeometryChange(self, featureId, geom ):
  capa_aristas = find_layer("Aristas_tmp")
  # Disconects the signal to avoid entering an endless loop

(find_layer is a function taken from MMQGIS plugin that iterates through the QgsMapLayerRegistry)

This code has the effect of undoing any change made to the layer, but with some problems:

  1. There are inconsitencies in the GUI, i.e.: the layer leaves edit mode (the pencil in the legend disappears and further edits are not allowed), but the buttons in the digitize toolbar are still enabled.
  2. If enter edit mode again, the last edited feature appears in the destination location of the previous edit, but if I move it again, the rollback moves it to the right place (the initial position)
  3. If I repeat the process 5 or 6 times, QGIS crashes with this message: Fatal: ASSERT: "mChangedGeometries.isEmpty()" in file /tmp/buildd/qgis-1.9.0+git20121010+dd67935~squeeze1/src/core/qgsvectorlayer.cpp, line 4042

(as you can see, I'm running QGIS 1.9.0-master)

I guess I hit some kind of bug, but want to be sure that I'm calling the API in a proper way.

Anyone can confirm if this usage of rollback() is "legal"?

  • I changed capa_aristas.rollBack() with capa_aristas.destroyEditCommand(). It seems that it works OK now, but I'll do more testing. – rpet Oct 12 '12 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.