Medical Imaging Interaction Toolkit  2025.12.02
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 #pragma GCC visibility push(default)
24 #include <itkEventObject.h>
25 #pragma GCC visibility pop
26 
27 #include <deque>
28 
29 namespace mitk
30 {
31  //##Documentation
32  //## @brief A linear undo model with one undo and one redo stack.
33  //##
34  //## Derived from UndoModel AND itk::Object. Invokes ITK-events to signal listening
35  //## GUI elements, whether each of the stacks is empty or not (to enable/disable button, ...)
37  {
38  public:
39  typedef std::deque<UndoStackItem *> UndoContainer;
40  typedef std::deque<UndoStackItem *>::reverse_iterator UndoContainerRevIter;
41 
43  itkFactorylessNewMacro(Self);
44  itkCloneMacro(Self);
45 
46  bool SetOperationEvent(UndoStackItem *stackItem) override;
47 
48  //##Documentation
49  //## @brief Undoes the last changes
50  //##
51  //## Reads the top element of the Undo-Stack,
52  //## executes the operation,
53  //## swaps the OperationEvent-Undo with the Operation
54  //## and sets it to Redo-Stack
55  bool Undo() override;
56  bool Undo(bool) override;
57 
58  //##Documentation
59  //## @brief Undoes all changes until ObjectEventID oeid
60  virtual bool Undo(int oeid);
61 
62  //##Documentation
63  //## @brief Undoes the last changes
64  //##
65  //## Reads the top element of the Redo-Stack,
66  //## executes the operation,
67  //## swaps the OperationEvent-Operation with the Undo-Operation
68  //## and sets it to Undo-Stack
69  bool Redo() override;
70  bool Redo(bool) override;
71 
72  //##Documentation
73  //## @brief Redoes all changes until ObjectEventID oeid
74  virtual bool Redo(int oeid);
75 
76  //##Documentation
77  //## @brief Clears UndoList and RedoList
78  void Clear() override;
79 
80  //##Documentation
81  //## @brief Clears the RedoList
82  void ClearRedoList() override;
83 
84  //##Documentation
85  //## @brief True, if RedoList is empty
86  bool RedoListEmpty() override;
87 
88  //##Documentation
89  //## @brief True, if UndoList is empty
90  bool UndoListEmpty() override;
91 
92  //##Documentation
93  //## @brief Gets the limit on the size of the undo history.
94  //## The undo limit determines how many items can be stored
95  //## in the undo stack. If the value is 0 that means that
96  //## there is no limit.
97  std::size_t GetUndoLimit() const override;
98 
99  //##Documentation
100  //## @brief Sets a limit on the size of the undo history.
101  //## If the limit is reached, the oldest undo items will
102  //## be dropped from the bottom of the undo stack.
103  //## The 0 value means that there is no limit.
104  //## @param limit the maximum number of items on the stack
105  void SetUndoLimit(std::size_t limit) override;
106 
107  //##Documentation
108  //## @brief Returns the ObjectEventId of the
109  //## top element in the OperationHistory
111 
112  //##Documentation
113  //## @brief Returns the GroupEventId of the
114  //## top element in the OperationHistory
116 
117  //##Documentation
118  //## @brief Returns the last specified OperationEvent in Undo-list
119  //## corresponding to the given values; if nothing found, then returns nullptr
120  OperationEvent *GetLastOfType(OperationActor *destination, OperationType opType) override;
121 
127  unsigned int RemoveInvalidOperations() override;
128 
129  protected:
130  //##Documentation
131  //## Constructor
133 
134  //##Documentation
135  //## Destructor
136  ~LimitedLinearUndo() override;
137 
138  //## @brief Convenience method to free the memory of
139  //## elements in the list and to clear the list
141 
143 
145 
146  private:
147  int FirstObjectEventIdOfCurrentGroup(UndoContainer &stack);
148 
149  std::size_t m_UndoLimit;
150 
151  };
152 
153 #pragma GCC visibility push(default)
154 
157  itkEventMacroDeclaration(UndoStackEvent, itk::ModifiedEvent);
158  itkEventMacroDeclaration(UndoEmptyEvent, UndoStackEvent);
159  itkEventMacroDeclaration(RedoEmptyEvent, UndoStackEvent);
160  itkEventMacroDeclaration(UndoNotEmptyEvent, UndoStackEvent);
161  itkEventMacroDeclaration(RedoNotEmptyEvent, UndoStackEvent);
163  itkEventMacroDeclaration(UndoFullEvent, UndoStackEvent);
164  itkEventMacroDeclaration(RedoFullEvent, UndoStackEvent);
165 
166 #pragma GCC visibility pop
167 
168 } // namespace mitk
169 
170 #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. If the limit is reached, the oldest undo items will be ...
~LimitedLinearUndo() override
bool UndoListEmpty() override
True, if UndoList is empty.
std::deque< UndoStackItem * > UndoContainer
unsigned int RemoveInvalidOperations() override
Removes invalid operations from the undo/redo stack. Iterates through m_UndoList and m_RedoList and r...
bool RedoListEmpty() override
True, if RedoList is empty.
std::size_t GetUndoLimit() const override
Gets the limit on the size of the undo history. The undo limit determines how many items can be store...
OperationEvent * GetLastOfType(OperationActor *destination, OperationType opType) override
Returns the last specified OperationEvent in Undo-list corresponding to the given values; if nothing ...
void Clear() override
Clears UndoList and RedoList.
void ClearList(UndoContainer *list)
bool Undo(bool) override
bool Redo(bool) override
bool Redo() override
Undoes the last changes.
bool SetOperationEvent(UndoStackItem *stackItem) override
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.
Represents a pair of operations: undo and the according redo.
superclass for all UndoModels
Definition: mitkUndoModel.h:33
Represents an entry of the undo or redo stack.
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
Find image slices visible on a given plane.
int OperationType
Definition: mitkOperation.h:23
itkEventMacroDeclaration(BoundingShapeInteractionEvent, itk::AnyEvent)