In the documentation of the Avogadro::Extension baseclass for creating
your own extensions, it is stated that:
“To perform an action the extension should implement performAction and
perform the correct action based on the action it receives. The actual
action should will be performed by the parent object (usually
MainWindow) as a result of a redo call on the returned QUndoCommand from
the performAction function. Thus, to implement functionality you should
subclass QUndoCommand accordingly based on the required functionality of
the extension and return the command based on the action being peformed”
While this as such is clear, I wonder what is the advantage/usage of
using this QUndo command. Alternatively, one could trigger an action
directly from the performAction function. I experimented a bit here, and
it just seems to work. Am I overlooking something?
Regards,
Bertwim
While this as such is clear, I wonder what is the advantage/usage of
using this QUndo command. Alternatively, one could trigger an action
directly from the performAction function. I experimented a bit here, and
it just seems to work. Am I overlooking something?
Yes, you can have your extension “just do” something in performAction() However, that bit of “just do” is permanent – the user can’t use undo/redo for it. If this behavior is OK (e.g., with the input generation dialogs), then performAction is all you need.
If, on the other hand, you might want to undo the extension (e.g., add/remove hydrogens, etc.) – you should implement a subclass of QUndoCommand which actually “does the work” in the redo() method, and provides an undo() method which reverts it.
Hmm… I’m re-reading what I wrote. Does it make sense to you now?
-Geoff
Yes, it certainly does. In my case, i’m creating a molecular dynamics
extension. An “undo” might not be directly neccessary here, but it
doesn’t hurt either.
Regards,
Bertwim
Geoffrey Hutchison wrote:
While this as such is clear, I wonder what is the advantage/usage of
using this QUndo command. Alternatively, one could trigger an action
directly from the performAction function. I experimented a bit here, and
it just seems to work. Am I overlooking something?
Yes, you can have your extension “just do” something in performAction() However, that bit of “just do” is permanent – the user can’t use undo/redo for it. If this behavior is OK (e.g., with the input generation dialogs), then performAction is all you need.
If, on the other hand, you might want to undo the extension (e.g., add/remove hydrogens, etc.) – you should implement a subclass of QUndoCommand which actually “does the work” in the redo() method, and provides an undo() method which reverts it.
Hmm… I’m re-reading what I wrote. Does it make sense to you now?
-Geoff