Monday, October 13, 2008

Undo Commands

Undo Commands are part of TinkerCell Core's basic design

Undo commands all inherit from Qt's QUndoCommand class, so reading Qt's documentation on the undo framework first will be helpful. 

Undo commands are atomic operations, meaning that they can be undone and redone without causing side-effects. TinkerCell's general design is to define everything in terms of these atomic operations.  In otherwords, all edits to a model can be done using undo commands. 

The general way of using undo commands is to create a new undo command and then push() it to the current scene's history stack. GraphicsScene includes a large set of functions that automatically do this as well as emit the appropriate signal allowing other tools to respond to a command (see blog on GraphicsScene). 

The CompositeCommand is a very useful command. It allows multiple commands to be combined into one. For example, "paste" operation is a composite command that combines the insert command and the rename command (in order to rename newly inserted duplicates). 

No comments: