#include <UndoAction.h>
Signals | |
| void | aboutToUndo () |
| void | undoComplete () |
| void | aboutToRedo () |
| void | redoComplete () |
| void | sessionItemChanged (const std::string &oldId, const std::string &newId) |
Public Member Functions | |
| UndoAction (bool bRedoOnAdd=false) | |
| UndoAction (SessionItem *pItem, bool bRedoOnAdd=false) | |
| virtual | ~UndoAction () |
| void | setSessionItem (SessionItem *pItem) |
| virtual SessionItem * | getSessionItem () const |
| const std::string & | getSessionItemId () const |
| virtual void | updateSessionItem (const std::string &oldId, const std::string &newId) |
| void | undo () |
| void | redo () |
Protected Member Functions | |
| virtual void | executeUndo ()=0 |
| virtual void | executeRedo ()=0 |
This class can be subclassed to create custom undo actions that will be executed when the user clicks the Undo or Redo toolbar buttons. Subclasses must override the executeUndo() and executeRedo() methods to perform the undo or redo. The inherited QUndoCommand::undo() and QUndoCommand::redo() method obligations are implemented in this class to emit signals before and after the undo or redo is performed and to change the mouse cursor to a wait cursor while the undo or redo is performed.
Since undo actions typically perform operations on a SessionItem, an UndoAction optionally stores a session item by its ID and provides the getSessionItem() accessor method as a convenience to retrieve the SessionItem pointer when performing the undo or redo. Since the stored session item may be deleted when performing the undo or redo, the sessionItemChanged() signal is provided to notify the application that the session item ID of other actions may need to be updated.
Definition at line 37 of file UndoAction.h.
| UndoAction::UndoAction | ( | bool | bRedoOnAdd = false |
) |
Creates the undo action.
| bRedoOnAdd | By default the redo() method is called when the action is added to an undo stack in a view. If this value is false the executeRedo() method is not called when the action is added to the undo stack. |
| UndoAction::UndoAction | ( | SessionItem * | pItem, | |
| bool | bRedoOnAdd = false | |||
| ) |
Creates the undo action.
| pItem | The session item to store by its ID. | |
| bRedoOnAdd | By default the redo() method is called when the action is added to an undo stack in a view. If this value is false the executeRedo() method is not called when the action is added to the undo stack. |
| virtual UndoAction::~UndoAction | ( | ) | [virtual] |
Destroys the undo action.
| void UndoAction::setSessionItem | ( | SessionItem * | pItem | ) |
Stores the ID for a given session item.
| pItem | The session item for which to store its ID. |
| virtual SessionItem* UndoAction::getSessionItem | ( | ) | const [virtual] |
Returns a SessionItem pointer for the stored ID.
This method retrieves the session item for the stored ID value by calling SessionManager::getSessionItem().
NULL if no session item can be found in the session manager with the stored ID.| const std::string& UndoAction::getSessionItemId | ( | ) | const |
Returns a stored session item ID.
| virtual void UndoAction::updateSessionItem | ( | const std::string & | oldId, | |
| const std::string & | newId | |||
| ) | [virtual] |
Updates the stored session item ID.
This method is called by the application when the sessionItemChanged() signal is emitted by another undo action. This is typically emitted when another action recreates a session item during undo or redo execution.
This implementation compares the old ID with the stored member and updates the member to the new ID if the old ID matches the stored member. This method should be overridden in a subclass if the subclass needs to store an additional session item ID.
| oldId | The previous ID for the session item that was deleted. | |
| newId | The ID for the recreated session item. |
| void UndoAction::undo | ( | ) |
Performs the undo to restore the application to its previous state.
This method is called by the application when the user clicks the Undo button on the toolbar. It provides a default implementation of the virtual QUndoCommand::undo() method. It emits the aboutToUndo() signal, changes the mouse cursor to a wait cursor, calls executeUndo(), restores the mouse cursor, and emits the undoComplete() signal.
| void UndoAction::redo | ( | ) |
Performs the redo to return the application to its modified state.
This method is called by the application when the user clicks the Redo button on the toolbar. It provides a default implementation of the virtual QUndoCommand::redo() method. It emits the aboutToRedo() signal, changes the mouse cursor to a wait cursor, calls executeRedo(), restores the mouse cursor, and emits the redoComplete() signal.
If this method is called in response to the undo action being added to the undo stack and the bRedoOnAdd parameter passed into the constructor is false, this method does nothing.
| void UndoAction::aboutToUndo | ( | ) | [signal] |
Emitted just before the undo is performed.
This signal is emitted in the default implementation of undo() before the executeUndo() method is called.
| void UndoAction::undoComplete | ( | ) | [signal] |
Emitted after the undo is performed.
This signal is emitted in the default implementation of undo() after the executeUndo() method is called.
| void UndoAction::aboutToRedo | ( | ) | [signal] |
Emitted just before the redo is performed.
This signal is emitted in the default implementation of redo() before the executeRedo() method is called.
| void UndoAction::redoComplete | ( | ) | [signal] |
Emitted after the redo is performed.
This signal is emitted in the default implementation of redo() after the executeRedo() method is called.
| void UndoAction::sessionItemChanged | ( | const std::string & | oldId, | |
| const std::string & | newId | |||
| ) | [signal] |
Emitted when a session item is deleted and recreated, thereby changing its ID.
This signal is emitted in subclasses that destroy and recreate session items during undo and redo execution. After destroying the session item the action should maintain the old ID string to use when emitting this signal after recreating the session item.
| oldId | The ID of the deleted session item. | |
| newId | The ID of the recreated session item, obtained with SessionItem::getId(). |
| virtual void UndoAction::executeUndo | ( | ) | [protected, pure virtual] |
Performs the undo to restore the application to its previous state.
This method must be overridden in subclasses to perform specific changes to the application. It is called from the default implementation of the undo() method.
| virtual void UndoAction::executeRedo | ( | ) | [protected, pure virtual] |
Performs the redo to return the application to its modified state.
This method must be overridden in subclasses to perform specific changes to the application. It is called from the default implementation of the redo() method.