UndoAction Class Reference

Base class for all undo actions added to the undo stack in a view. More...

#include <UndoAction.h>

List of all members.

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 SessionItemgetSessionItem () 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


Detailed Description

Base class for all undo actions added to the undo stack in a view.

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.


Constructor & Destructor Documentation

UndoAction::UndoAction ( bool  bRedoOnAdd = false  ) 

Creates the undo action.

Parameters:
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.

Parameters:
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.
See also:
setSessionItem()

virtual UndoAction::~UndoAction (  )  [virtual]

Destroys the undo action.


Member Function Documentation

void UndoAction::setSessionItem ( SessionItem pItem  ) 

Stores the ID for a given session item.

Parameters:
pItem The session item for which to store its ID.
See also:
SessionItem::getId()

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().

Warning:
The session manager does not currently store graphic objects or the graphic layers contained in a product view. Subclasses that need to access these objects should additionally store the ID for the parent graphic layer in a spatial data view or the ID for the product view and the graphic layer contained in the product view. This method should be overridden to obtain the parent session item from the session manager and used to access the desired session item not contained in the session manager.
Returns:
The SessionItem pointer for the session item with the stored ID. Returns NULL if no session item can be found in the session manager with the stored ID.
See also:
getSessionItemId()

const std::string& UndoAction::getSessionItemId (  )  const

Returns a stored session item ID.

Returns:
The ID for the session item that was passed into the constructor or in setSessionItem().
See also:
getSessionItem()

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.

Parameters:
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.

See also:
undoComplete()

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.

See also:
aboutToUndo()

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.

See also:
redoComplete()

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.

See also:
aboutToRedo()

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.

Parameters:
oldId The ID of the deleted session item.
newId The ID of the recreated session item, obtained with SessionItem::getId().
See also:
updateSessionItem()

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.


Software Development Kit - Opticks 4.9.0 Build 16218