A linear undo model with one undo and one redo stack. More...
#include <mitkLimitedLinearUndo.h>
Public Types | |
typedef std::vector < UndoStackItem * > | UndoContainer |
typedef std::vector < UndoStackItem * > ::reverse_iterator | UndoContainerRevIter |
Public Member Functions | |
mitkClassMacro (LimitedLinearUndo, UndoModel) | |
virtual bool | SetOperationEvent (UndoStackItem *stackItem) |
virtual bool | Undo () |
Undoes the last changes. | |
virtual bool | Undo (bool) |
virtual bool | Undo (int oeid) |
Undoes all changes until ObjectEventID oeid. | |
virtual bool | Redo () |
Undoes the last changes. | |
virtual bool | Redo (bool) |
virtual bool | Redo (int oeid) |
Redoes all changes until ObjectEventID oeid. | |
virtual void | Clear () |
Clears UndoList and RedoList. | |
virtual void | ClearRedoList () |
Clears the RedoList. | |
virtual bool | RedoListEmpty () |
True, if RedoList is empty. | |
virtual int | GetLastObjectEventIdInList () |
Returns the ObjectEventId of the top element in the OperationHistory. | |
virtual int | GetLastGroupEventIdInList () |
Returns the GroupEventId of the top element in the OperationHistory. | |
virtual OperationEvent * | GetLastOfType (OperationActor *destination, OperationType opType) |
Returns the last specified OperationEvent in Undo-list corresponding to the given values; if nothing found, then returns NULL. | |
Static Public Member Functions | |
static Pointer | New () |
Protected Member Functions | |
LimitedLinearUndo () | |
virtual | ~LimitedLinearUndo () |
void | ClearList (UndoContainer *list) |
Protected Attributes | |
UndoContainer | m_UndoList |
UndoContainer | m_RedoList |
A linear undo model with one undo and one redo stack.
Derived from UndoModel AND itk::Object. Invokes ITK-events to signal listening GUI elements, whether each of the stacks is empty or not (to enable/disable button, ...)
Definition at line 38 of file mitkLimitedLinearUndo.h.
typedef std::vector<UndoStackItem*> mitk::LimitedLinearUndo::UndoContainer |
Definition at line 41 of file mitkLimitedLinearUndo.h.
typedef std::vector<UndoStackItem*>::reverse_iterator mitk::LimitedLinearUndo::UndoContainerRevIter |
Definition at line 42 of file mitkLimitedLinearUndo.h.
mitk::LimitedLinearUndo::LimitedLinearUndo | ( | ) | [protected] |
mitk::LimitedLinearUndo::~LimitedLinearUndo | ( | ) | [protected, virtual] |
Destructor
Definition at line 27 of file mitkLimitedLinearUndo.cpp.
{ //delete undo and redo list this->ClearList(&m_UndoList); this->ClearList(&m_RedoList); }
void mitk::LimitedLinearUndo::Clear | ( | ) | [virtual] |
Clears UndoList and RedoList.
Implements mitk::UndoModel.
Definition at line 149 of file mitkLimitedLinearUndo.cpp.
{ this->ClearList(&m_UndoList); InvokeEvent( UndoEmptyEvent() ); this->ClearList(&m_RedoList); InvokeEvent( RedoEmptyEvent() ); }
void mitk::LimitedLinearUndo::ClearList | ( | UndoContainer * | list ) | [protected] |
Definition at line 34 of file mitkLimitedLinearUndo.cpp.
{ while(!list->empty()) { UndoStackItem* item = list->back(); list->pop_back(); delete item; } }
void mitk::LimitedLinearUndo::ClearRedoList | ( | ) | [virtual] |
Clears the RedoList.
Implements mitk::UndoModel.
Definition at line 158 of file mitkLimitedLinearUndo.cpp.
{ this->ClearList(&m_RedoList); InvokeEvent( RedoEmptyEvent() ); }
int mitk::LimitedLinearUndo::GetLastGroupEventIdInList | ( | ) | [virtual] |
Returns the GroupEventId of the top element in the OperationHistory.
Implements mitk::UndoModel.
Definition at line 174 of file mitkLimitedLinearUndo.cpp.
{ return m_UndoList.back()->GetGroupEventId(); }
int mitk::LimitedLinearUndo::GetLastObjectEventIdInList | ( | ) | [virtual] |
Returns the ObjectEventId of the top element in the OperationHistory.
Implements mitk::UndoModel.
Definition at line 169 of file mitkLimitedLinearUndo.cpp.
{ return m_UndoList.back()->GetObjectEventId(); }
mitk::OperationEvent * mitk::LimitedLinearUndo::GetLastOfType | ( | OperationActor * | destination, |
OperationType | opType | ||
) | [virtual] |
Returns the last specified OperationEvent in Undo-list corresponding to the given values; if nothing found, then returns NULL.
Implements mitk::UndoModel.
Definition at line 179 of file mitkLimitedLinearUndo.cpp.
References mitk::OperationEvent::GetDestination(), mitk::OperationEvent::GetOperation(), mitk::Operation::GetOperationType(), and mitk::OperationEvent::IsValid().
{ // When/where is this function needed? In CoordinateSupplier... for ( UndoContainerRevIter iter = m_UndoList.rbegin(); iter != m_UndoList.rend(); ++iter ) { OperationEvent* opEvent = dynamic_cast<OperationEvent*>(*iter); if (!opEvent) continue; if ( opEvent->GetOperation() != NULL && opEvent->GetOperation()->GetOperationType() == opType && opEvent->IsValid() && opEvent->GetDestination() == destination ) return opEvent; } return NULL; }
mitk::LimitedLinearUndo::mitkClassMacro | ( | LimitedLinearUndo | , |
UndoModel | |||
) |
static Pointer mitk::LimitedLinearUndo::New | ( | ) | [static] |
Reimplemented in mitk::VerboseLimitedLinearUndo.
Referenced by mitk::UndoController::AddUndoModel(), and mitk::UndoController::UndoController().
bool mitk::LimitedLinearUndo::Redo | ( | bool | ) | [virtual] |
Implements mitk::UndoModel.
Definition at line 111 of file mitkLimitedLinearUndo.cpp.
{ return Redo(); }
bool mitk::LimitedLinearUndo::Redo | ( | int | oeid ) | [virtual] |
Redoes all changes until ObjectEventID oeid.
Definition at line 124 of file mitkLimitedLinearUndo.cpp.
References mitk::RenderingManager::GetInstance(), and mitk::RenderingManager::RequestUpdateAll().
{ if (m_RedoList.empty()) return false; do { m_RedoList.back()->ReverseAndExecute(); m_UndoList.push_back(m_RedoList.back()); m_RedoList.pop_back(); InvokeEvent( UndoNotEmptyEvent() ); if (m_RedoList.empty()) { InvokeEvent( RedoEmptyEvent() ); break; } } while ( m_RedoList.back()->GetObjectEventId() <= oeid ); //Update. This should belong into the ExecuteOperation() of OperationActors, but it seems not to be used everywhere mitk::RenderingManager::GetInstance()->RequestUpdateAll(); return true; }
bool mitk::LimitedLinearUndo::Redo | ( | ) | [virtual] |
Undoes the last changes.
Reads the top element of the Redo-Stack, executes the operation, swaps the OperationEvent-Operation with the Undo-Operation and sets it to Undo-Stack
Implements mitk::UndoModel.
Definition at line 116 of file mitkLimitedLinearUndo.cpp.
{ if (m_RedoList.empty()) return false; int redoObjectEventId = m_RedoList.back()->GetObjectEventId(); return Redo( redoObjectEventId ); }
bool mitk::LimitedLinearUndo::RedoListEmpty | ( | ) | [virtual] |
True, if RedoList is empty.
Implements mitk::UndoModel.
Definition at line 164 of file mitkLimitedLinearUndo.cpp.
{ return m_RedoList.empty(); }
bool mitk::LimitedLinearUndo::SetOperationEvent | ( | UndoStackItem * | stackItem ) | [virtual] |
Implements mitk::UndoModel.
Reimplemented in mitk::VerboseLimitedLinearUndo.
Definition at line 44 of file mitkLimitedLinearUndo.cpp.
{ OperationEvent* operationEvent = dynamic_cast<OperationEvent*>(stackItem); if (!operationEvent) return false; // clear the redolist, if a new operation is saved if (!m_RedoList.empty()) { this->ClearList(&m_RedoList); InvokeEvent( RedoEmptyEvent() ); } m_UndoList.push_back(operationEvent); InvokeEvent( UndoNotEmptyEvent() ); return true; }
bool mitk::LimitedLinearUndo::Undo | ( | bool | fine ) | [virtual] |
Implements mitk::UndoModel.
Definition at line 63 of file mitkLimitedLinearUndo.cpp.
{ if (fine) { // undo one object event ID return Undo(); } else { // undo one group event ID int oeid = FirstObjectEventIdOfCurrentGroup(m_UndoList); // get the Object Event ID of the first item with a differnt Group ID (as seen from the end of stack) return Undo(oeid); } }
bool mitk::LimitedLinearUndo::Undo | ( | int | oeid ) | [virtual] |
Undoes all changes until ObjectEventID oeid.
Definition at line 86 of file mitkLimitedLinearUndo.cpp.
References mitk::RenderingManager::GetInstance(), and mitk::RenderingManager::RequestUpdateAll().
{ if(m_UndoList.empty()) return false; do { m_UndoList.back()->ReverseAndExecute(); m_RedoList.push_back(m_UndoList.back()); // move to redo stack m_UndoList.pop_back(); InvokeEvent( RedoNotEmptyEvent() ); if (m_UndoList.empty()) { InvokeEvent( UndoEmptyEvent() ); return false; } } while ( m_UndoList.back()->GetObjectEventId() >= oeid ); //Update. Check Rendering Mechanism where to request updates mitk::RenderingManager::GetInstance()->RequestUpdateAll(); return true; }
bool mitk::LimitedLinearUndo::Undo | ( | ) | [virtual] |
Undoes the last changes.
Reads the top element of the Undo-Stack, executes the operation, swaps the OperationEvent-Undo with the Operation and sets it to Redo-Stack
Implements mitk::UndoModel.
Definition at line 78 of file mitkLimitedLinearUndo.cpp.
{ if(m_UndoList.empty()) return false; int undoObjectEventId = m_UndoList.back()->GetObjectEventId(); return Undo( undoObjectEventId ); }
UndoContainer mitk::LimitedLinearUndo::m_RedoList [protected] |
Definition at line 119 of file mitkLimitedLinearUndo.h.
UndoContainer mitk::LimitedLinearUndo::m_UndoList [protected] |
Definition at line 117 of file mitkLimitedLinearUndo.h.