Represents a pair of operations: undo and the according redo. More...
#include <mitkOperationEvent.h>
Public Member Functions | |
OperationEvent (OperationActor *destination, Operation *operation, Operation *undoOperation, std::string description="") | |
virtual | ~OperationEvent () |
Operation * | GetOperation () |
OperationActor * | GetDestination () |
virtual void | ReverseOperations () |
virtual void | ReverseAndExecute () |
virtual bool | IsValid () |
Protected Member Functions | |
void | OnObjectDeleted () |
Friends | |
class | UndoModel |
Represents a pair of operations: undo and the according redo.
Additionally to the base class UndoStackItem, which only provides a description of an item, OperationEvent does the actual accounting of the undo/redo stack. This class holds two Operation objects (operation and its inverse operation) and the corresponding OperationActor. The operations may be swapped by the undo models, when an OperationEvent is moved from their undo to their redo stack or vice versa.
Note, that memory management of operation and undooperation is done by this class. Memory of both objects is freed in the destructor. For this, the method IsValid() is needed which holds information of the state of m_Destination. In case the object referenced by m_Destination is already deleted, isValid() returns false. In more detail if the destination happens to be an itk::Object (often the case), OperationEvent is informed as soon as the object is deleted - from this moment on the OperationEvent gets invalid. You should check this flag before you call anything on destination
Definition at line 150 of file mitkOperationEvent.h.
mitk::OperationEvent::OperationEvent | ( | OperationActor * | destination, |
Operation * | operation, | ||
Operation * | undoOperation, | ||
std::string | description = "" |
||
) |
Definition at line 109 of file mitkOperationEvent.cpp.
References OnObjectDeleted().
: UndoStackItem(description), m_Destination(destination), m_Operation(operation), m_UndoOperation(undoOperation), m_Invalid(false) { //connect to delete event if (itk::Object* object = dynamic_cast<itk::Object*>( m_Destination )) { itk::SimpleMemberCommand< OperationEvent >::Pointer command = itk::SimpleMemberCommand< OperationEvent >::New(); command->SetCallbackFunction( this, &OperationEvent::OnObjectDeleted ); m_DeleteTag = object->AddObserver( itk::DeleteEvent(), command ); } }
mitk::OperationEvent::~OperationEvent | ( | ) | [virtual] |
Definition at line 127 of file mitkOperationEvent.cpp.
{ //remove the observer if the data m_Destination still is present if (!m_Invalid) { if (itk::Object* object = dynamic_cast<itk::Object*>( m_Destination )) { object->RemoveObserver( m_DeleteTag ); } } delete m_Operation; delete m_UndoOperation; }
mitk::OperationActor * mitk::OperationEvent::GetDestination | ( | ) |
Definition at line 163 of file mitkOperationEvent.cpp.
Referenced by mitk::LimitedLinearUndo::GetLastOfType().
{
return m_Destination;
}
mitk::Operation * mitk::OperationEvent::GetOperation | ( | ) |
Definition at line 104 of file mitkOperationEvent.cpp.
Referenced by mitk::CoordinateSupplier::ExecuteAction(), and mitk::LimitedLinearUndo::GetLastOfType().
{
return m_Operation;
}
bool mitk::OperationEvent::IsValid | ( | ) | [virtual] |
Definition at line 173 of file mitkOperationEvent.cpp.
Referenced by mitk::LimitedLinearUndo::GetLastOfType().
{
return !m_Invalid;
}
void mitk::OperationEvent::OnObjectDeleted | ( | ) | [protected] |
Definition at line 168 of file mitkOperationEvent.cpp.
Referenced by OperationEvent().
{
m_Invalid = true;
}
void mitk::OperationEvent::ReverseAndExecute | ( | ) | [virtual] |
Reimplemented from mitk::UndoStackItem.
Definition at line 156 of file mitkOperationEvent.cpp.
{ ReverseOperations(); if (m_Destination && m_Operation && !m_Invalid) m_Destination->ExecuteOperation( m_Operation ); }
void mitk::OperationEvent::ReverseOperations | ( | ) | [virtual] |
swaps the Undo and Redo- operation and changes m_Reversed
Reimplemented from mitk::UndoStackItem.
Definition at line 144 of file mitkOperationEvent.cpp.
References mitk::UndoStackItem::ReverseOperations().
{ if (m_Operation == NULL) return; Operation *tempOperation = m_Operation; m_Operation = m_UndoOperation; m_UndoOperation = tempOperation; UndoStackItem::ReverseOperations(); }
friend class UndoModel [friend] |
Definition at line 168 of file mitkOperationEvent.h.