2

I'm developing a standalone application in pyqgis (python 3.6, qgis 3.2) for editing roads and ran into a problem connected to performing transactions. When the user of the app insert, update or delete one feature s/he often wants to perform undo or redo operation in case some wrong actions have been done. I found and tested the following

1) Creating undo stack for road layer

self.undo_stack: QUndoStack = self.trackLayer.undoStack()

2) Implementing the following functions

def perform_undo(self):
    self.undo_stack.undo()
    self.mapCanvas.refresh()
    self.adjust_undo_redo_buttons()

def perform_redo(self):
    self.undo_stack.redo()
    self.mapCanvas.refresh()
    self.adjust_undo_redo_buttons()

def adjust_undo_redo_buttons(self):
    self.action_undo_transaction.setEnabled(self.undo_stack.canUndo())
    self.action_redo_transaction.setEnabled(self.undo_stack.canRedo())

For single operations (insert one feature, change the location of one vertice) that works fine. But when it comes to changing the location of the vertice that is common to (for example) three roads the user has to perform undo three times.

For example, I know how to do this in proprietary product GE Smallworld GIS

 # Change area value of the selected records
 sel_recs << a_view.collections[:plot].all_at(32,11)
_local ok? << a_view.start_lwt()
_protect
    for rec _over sel_recs
    _loop
           rec.area +<< 20.0
    _endloop
    # doing some changes upon some records
    ok? << _true
_protection
    a_view.end_lwt(ok?, _true, "Increasing areas by 20")
_endprotect

I'm sure that there is some way to undo several operations at once. For example, it's easy to split some polygon into 6 parts and undo this transaction by one click in QGIS 3.2 Split a polygon into 6 parts

So what should I do to merge several operations on the data into one transaction in pyqgis?

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.