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:[email protected]]<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:[email protected]]<https://twitter.com/thinkWhere1>
[cid:[email protected]]
<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.
_______________________________________________
Qgis-developer mailing list
[email protected]
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer