Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkUndoController.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 mitkUndoController_h
14 #define mitkUndoController_h
15 
16 #include <mitkOperationEvent.h>
17 #include <mitkUndoModel.h>
18 #include <MitkCoreExports.h>
19 #include <map>
20 
21 namespace mitk
22 {
29  inline constexpr unsigned int DEFAULT_UNDO_REDO_LIMIT = 50;
30 
41  {
42  public:
44  enum UndoType
45  {
46  LIMITEDLINEARUNDO = 10,
47  VERBOSE_LIMITEDLINEARUNDO = 11,
48  TREEUNDO = 20
49  };
50 
51  typedef std::map<UndoType, UndoModel::Pointer> UndoModelMap;
52  typedef std::map<UndoType, UndoModel::Pointer>::iterator UndoModelMapIter;
53 
55  static const UndoType DEFAULTUNDOMODEL;
56 
65  UndoController(UndoType undoType = DEFAULTUNDOMODEL);
66  virtual ~UndoController();
67 
74  bool SetOperationEvent(UndoStackItem *operationEvent);
75 
80  bool Undo();
81 
92  bool Undo(bool fine);
93 
98  bool Redo();
99 
106  bool Redo(bool fine);
107 
109  void Clear();
110 
113 
119 
126  bool SwitchUndoModel(UndoType undoType);
127 
136  bool AddUndoModel(UndoType undoType);
137 
148  bool RemoveUndoModel(UndoType undoType);
149 
155 
161 
170 
180 
181  private:
183  static UndoModel::Pointer m_CurUndoModel;
185  static UndoType m_CurUndoType;
187  static UndoModelMap m_UndoModelList;
188  };
189 } // namespace mitk
190 
191 #endif
#define MITKCORE_EXPORT
abstract class, that can be used by Undo to undo an operation.
Pairs a do-operation with its inverse undo-operation.
Controller that manages undo/redo operations by delegating to an UndoModel.
bool Undo()
Undo the last change (fine-grained, by ObjectEventId).
bool Redo(bool fine)
Redo the last undone change with control over granularity.
void Clear()
Clear both the undo and redo lists.
bool RedoListEmpty()
Check whether the redo list is empty.
int GetLastObjectEventIdInList()
Return the ObjectEventId of the top element in the undo history.
int GetLastGroupEventIdInList()
Return the GroupEventId of the top element in the undo history.
std::map< UndoType, UndoModel::Pointer > UndoModelMap
bool Undo(bool fine)
Undo the last change with control over granularity.
bool Redo()
Redo the last undone change (fine-grained, by ObjectEventId).
void ClearRedoList()
Clear the redo list only.
static UndoModel * GetCurrentUndoModel()
Return the currently active UndoModel.
std::map< UndoType, UndoModel::Pointer >::iterator UndoModelMapIter
bool SwitchUndoModel(UndoType undoType)
Switch to a different undo model type.
virtual ~UndoController()
UndoController(UndoType undoType=DEFAULTUNDOMODEL)
Construct an UndoController.
bool SetOperationEvent(UndoStackItem *operationEvent)
Store an operation event in the current undo model.
static const UndoType DEFAULTUNDOMODEL
Default UndoModel to use.
bool RemoveUndoModel(UndoType undoType)
Remove an undo model type from the list.
OperationEvent * GetLastOfType(OperationActor *destination, OperationType opType)
Return the last OperationEvent matching the given destination and operation type.
bool AddUndoModel(UndoType undoType)
Add a new undo model type and switch to it.
UndoType
Enumeration of available undo model types.
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.
constexpr unsigned int DEFAULT_UNDO_REDO_LIMIT
Default maximum number of operations kept on the undo/redo stack.
int OperationType
Type alias for operation type identifiers.
Definition: mitkOperation.h:24