Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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")     
  tmpLayer.geometryChanged.connect(self.onLineGeometryChange)
  return

...

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

(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"?

share|improve this question
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.