Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkLimitedLinearUndo.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkLimitedLinearUndo_h
14 #define mitkLimitedLinearUndo_h
15 
16 // MITK header
17 #include <mitkOperationEvent.h>
18 #include <mitkUndoModel.h>
19 #include <MitkCoreExports.h>
20 // STL header
21 #include <vector>
22 // ITK header
23 #ifdef __GNUC__
24 #pragma GCC visibility push(default)
25 #endif
26 #include <itkEventObject.h>
27 #ifdef __GNUC__
28 #pragma GCC visibility pop
29 #endif
30 
31 #include <deque>
32 
33 namespace mitk
34 {
42  {
43  public:
44  typedef std::deque<UndoStackItem *> UndoContainer;
45  typedef std::deque<UndoStackItem *>::reverse_iterator UndoContainerRevIter;
46 
48  itkFactorylessNewMacro(Self);
49  itkCloneMacro(Self);
50 
58  bool SetOperationEvent(UndoStackItem *stackItem) override;
59 
67  bool Undo() override;
68 
74  bool Undo(bool) override;
75 
77  virtual bool Undo(int oeid);
78 
86  bool Redo() override;
87 
89  bool Redo(bool) override;
90 
92  virtual bool Redo(int oeid);
93 
95  void Clear() override;
96 
98  void ClearRedoList() override;
99 
101  bool RedoListEmpty() override;
102 
104  bool UndoListEmpty() override;
105 
111  std::size_t GetUndoLimit() const override;
112 
119  void SetUndoLimit(std::size_t limit) override;
120 
123 
126 
132  OperationEvent *GetLastOfType(OperationActor *destination, OperationType opType) override;
133 
140  unsigned int RemoveInvalidOperations() override;
141 
142  protected:
145 
147  ~LimitedLinearUndo() override;
148 
151 
153 
155 
156  private:
157  int FirstObjectEventIdOfCurrentGroup(UndoContainer &stack);
158 
159  std::size_t m_UndoLimit;
160 
161  };
162 
163 #ifdef __GNUC__
164 #pragma GCC visibility push(default)
165 #endif
166 
170  itkEventMacroDeclaration(UndoStackEvent, itk::ModifiedEvent);
171  itkEventMacroDeclaration(UndoEmptyEvent, UndoStackEvent);
172  itkEventMacroDeclaration(RedoEmptyEvent, UndoStackEvent);
173  itkEventMacroDeclaration(UndoNotEmptyEvent, UndoStackEvent);
174  itkEventMacroDeclaration(RedoNotEmptyEvent, UndoStackEvent);
176  itkEventMacroDeclaration(UndoFullEvent, UndoStackEvent);
177  itkEventMacroDeclaration(RedoFullEvent, UndoStackEvent);
178 
179 #ifdef __GNUC__
180 #pragma GCC visibility pop
181 #endif
182 
183 } // namespace mitk
184 
185 #endif
#define MITKCORE_EXPORT
A linear undo model with one undo and one redo stack.
void SetUndoLimit(std::size_t limit) override
Sets a limit on the size of the undo history.
~LimitedLinearUndo() override
Destructor. Deletes all undo and redo entries.
bool UndoListEmpty() override
Returns true if the UndoList is empty.
std::deque< UndoStackItem * > UndoContainer
unsigned int RemoveInvalidOperations() override
Removes invalid operations from the undo/redo stack.
LimitedLinearUndo()
Constructor.
bool RedoListEmpty() override
Returns true if the RedoList is empty.
std::size_t GetUndoLimit() const override
Gets the limit on the size of the undo history.
OperationEvent * GetLastOfType(OperationActor *destination, OperationType opType) override
Returns the last OperationEvent in the Undo-list matching the given destination and operation type.
void Clear() override
Clears both the UndoList and RedoList.
mitkClassMacro(LimitedLinearUndo, UndoModel)
void ClearList(UndoContainer *list)
Convenience method to free the memory of elements in the list and clear it.
bool Undo(bool) override
Undoes the last changes.
bool Redo(bool) override
Redoes changes (parameter currently unused).
bool Redo() override
Redoes the last undone changes.
bool SetOperationEvent(UndoStackItem *stackItem) override
Store an operation event on the undo stack.
virtual bool Undo(int oeid)
Undoes all changes until ObjectEventID oeid.
int GetLastGroupEventIdInList() override
Returns the GroupEventId of the top element in the OperationHistory.
bool Undo() override
Undoes the last changes.
std::deque< UndoStackItem * >::reverse_iterator UndoContainerRevIter
int GetLastObjectEventIdInList() override
Returns the ObjectEventId of the top element in the OperationHistory.
virtual bool Redo(int oeid)
Redoes all changes until ObjectEventID oeid.
void ClearRedoList() override
Clears the RedoList.
abstract class, that can be used by Undo to undo an operation.
Pairs a do-operation with its inverse undo-operation.
Abstract superclass for all undo models.
Definition: mitkUndoModel.h:36
Represents an entry on the undo or redo stack.
Find image slices visible on a given plane.
int OperationType
Type alias for operation type identifiers.
Definition: mitkOperation.h:24
itkEventMacroDeclaration(BoundingShapeInteractionEvent, itk::AnyEvent)