LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
undomanagerimpl.cpp
Go to the documentation of this file.
1 #include "undomanagerimpl.h"
2 
5 #include <nano-signal-slot/nano_signal_slot.hpp>
6 
7 using namespace lc;
8 
9 
10 UndoManagerImpl::UndoManagerImpl(unsigned int maximumUndoLevels) : _maximumUndoLevels(maximumUndoLevels) {
11 
12 }
13 
14 
16  operation::Undoable_SPtr undoable = std::dynamic_pointer_cast<operation::Undoable>(event.operation());
17 
18  if (undoable.get() != nullptr) {
19  // // LOG4CXX_DEBUG(logger, "Process: " + undoable->text());
20 
21  // Check if Redo is possible, if so we might need to purge objects from memory
22  // as long as we can redo, purge these objects
23  while (canRedo()) {
24  operation::Undoable_SPtr undoable = _reDoables.top();
25  _reDoables.pop();
26  // Need to get a list of absolete entities, they are all entities that are created in the _reDoables list
27  // document()->absolueteEntity(entity);
28  }
29 
30  // Add undoable to stack
31  _unDoables.push_back(undoable);
32 
33  // Remove old undoables
34  if (_unDoables.size() > this->_maximumUndoLevels) {
35  // Need to get a list of absolete entities, they are all entities that are delete in the _unDoables list
36  // document()->absolueteEntity(entity);
37  _unDoables.erase(_unDoables.begin(), _unDoables.begin() + 1);
38  }
39  }
40 }
41 
42 
44  if (canRedo()) {
45  operation::Undoable_SPtr undoable = _reDoables.top();
46  _reDoables.pop();
47  undoable->redo();
48  _unDoables.push_back(undoable);
49  }
50 }
52  if (canUndo()) {
53  operation::Undoable_SPtr undoable = _unDoables.back();
54  _unDoables.pop_back();
55  undoable->undo();
56  _reDoables.push(undoable);
57  }
58 }
59 
61  return !_reDoables.empty();
62 }
64  return !_unDoables.empty();
65 }
66 
68  _unDoables.clear();
69 
70  while (!_reDoables.empty()) {
71  _reDoables.pop();
72  }
73 }
virtual bool canRedo() const
Check if redo can be done.
virtual void redo()
redo an operation.
: Abstract class for a Undoable operations All operations you wnt to beable to get place in the undo ...
Definition: undoable.h:18
std::vector< operation::Undoable_SPtr > _unDoables
Undo list.
virtual void undo()
undo an operation.
virtual void removeUndoables()
Clears the Undo/Redo stack.
Definition: cadentity.h:12
const unsigned int _maximumUndoLevels
Maximum undo level.
std::stack< operation::Undoable_SPtr > _reDoables
Redo stack.
UndoManagerImpl(unsigned int maximumUndoLevels)
void on_CommitProcessEvent(const lc::CommitProcessEvent &event)
virtual bool canUndo() const
Check if undo can be done.