[Qgis-developer] Disable undo feature for user geometry edits within plugin / general undoStack() questions

John Stevenson john.stevenson at thinkwhere.com
Thu Jan 7 09:06:35 PST 2016


Hi,

I am writing a plugin that modifies a spatialite database in response to geometry edits made by the user.  The attribute table for the modified feature is modified when an item is added or edited, and additional tables within the database are updated with the new information.  The undo button does not revert the database changes (and can cause crashed in Linux), so I would like to prevent the user being able to use it.

So far, I have worked out how to disable the undo button (and shortcut) by disabling the corresponding action.  But when I connect that to a signal, it fires but the undo is still enabled, but with a different corresponding action.

So far I have a class that initiates on beginEditing whose contents include the following:

```
def __init__(self, iface, layer, db):
    ..... various lines here ....
    self.undo_stack = layer.undoStack()

def connect_signals(self):
    ....various lines here....
    self.undo_stack.indexChanged.connect(self.disable_undo_button)
    self.undo_stack.canUndoChanged.connect(self.disable_undo_button)
    self.undo_stack.cleanChanged.connect(self.disable_undo_button)
    self.undo_stack.undoTextChanged.connect(self.disable_undo_button)

def disable_undo_button(self):
    """
   Disable GUI undo buttons to prevent user trying to undo edits, which
    is prone to causing crashes.
    """
    print('Disabling undo button')
    actions_to_disable = ['&Undo', '&Redo']
    for action in self.iface.editMenu().actions():
        menu_item_action_text = action.text()
        if menu_item_action_text in actions_to_disable:
            action.setDisabled(True)
            print(id(action))
```

The disable_undo_button() function works, so it seems that another action is being added as the current undo without any of the signals that I am listening for being called.

- When is the final change made to the undoStack?
- Is there a signal that I can listen for to disable undo afterwards?
- or is there generally a better way to disable undo functionality?

Cheers
John


John Stevenson
Senior Developer


[cid:imaged86623.PNG at a338e0da.42aa3eed]<http://www.thinkwhere.com>


t: 01786 476060 (Office)
t: 01786 476093 (Direct Dial)
w:www.thinkwhere.com<http://www.thinkwhere.com>


Glendevon House
Castle Business Park
Stirling FK9 4TZ


[cid:imagec95a8b.PNG at 7b323e42.469672cb]<https://twitter.com/thinkWhere1> [cid:image5e2fd2.PNG at 3bddb98a.4893db0f] <http://www.linkedin.com/company/1509510?trk=companies_home_ycp_logo_forth-valley-gis>


This email and its attachments are private and confidential. If you believe you have received this email in error, please contact the sender immediately on 01786 476060. If you are not the intended recipient, you may not rely on, use or disclose this email or any attachments in any way.

thinkWhere Limited does not accept any liability for any damage that may be caused to the recipient's system or data by this email or any attachments. Please note that our email system may be subject to random monitoring by us. This Company accepts no liability for personal emails.

thinkWhere is a limited company registered in Scotland with Registered Number SC315349 and having its Registered Office at Glendevon House, Castle Business Park, Stirling, FK9 4TZ.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160107/5c9cd381/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: imaged86623.PNG
Type: image/png
Size: 7004 bytes
Desc: imaged86623.PNG
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160107/5c9cd381/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: imagec95a8b.PNG
Type: image/png
Size: 3618 bytes
Desc: imagec95a8b.PNG
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160107/5c9cd381/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image5e2fd2.PNG
Type: image/png
Size: 3751 bytes
Desc: image5e2fd2.PNG
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160107/5c9cd381/attachment-0005.png>


More information about the Qgis-developer mailing list