LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lc::UndoManagerImpl Class Reference

#include <undomanagerimpl.h>

Inheritance diagram for lc::UndoManagerImpl:
Collaboration diagram for lc::UndoManagerImpl:

Public Member Functions

 UndoManagerImpl (unsigned int maximumUndoLevels)
 
virtual void redo ()
 redo an operation. More...
 
virtual void undo ()
 undo an operation. More...
 
virtual bool canUndo () const
 Check if undo can be done. More...
 
virtual bool canRedo () const
 Check if redo can be done. More...
 
virtual void removeUndoables ()
 Clears the Undo/Redo stack. More...
 
void on_CommitProcessEvent (const lc::CommitProcessEvent &event)
 

Private Attributes

std::vector
< operation::Undoable_SPtr > 
_unDoables
 Undo list. More...
 
std::stack
< operation::Undoable_SPtr > 
_reDoables
 Redo stack. More...
 
const unsigned int _maximumUndoLevels
 Maximum undo level. More...
 

Detailed Description

UndoManagerImpl manages a stack of operations and allows for undo or re-do operations that where done on a canvas

Parameters
maximumUndoLevels

Definition at line 19 of file undomanagerimpl.h.

Constructor & Destructor Documentation

UndoManagerImpl::UndoManagerImpl ( unsigned int  maximumUndoLevels)

Definition at line 10 of file undomanagerimpl.cpp.

10  : _maximumUndoLevels(maximumUndoLevels) {
11 
12 }
const unsigned int _maximumUndoLevels
Maximum undo level.

Member Function Documentation

bool UndoManagerImpl::canRedo ( ) const
virtual

Check if redo can be done.

See also
lc::Undoable
lc::UndoManager
lc::UndoManagerImpl
Returns

Implements lc::UndoManager.

Definition at line 60 of file undomanagerimpl.cpp.

60  {
61  return !_reDoables.empty();
62 }
std::stack< operation::Undoable_SPtr > _reDoables
Redo stack.
bool UndoManagerImpl::canUndo ( ) const
virtual

Check if undo can be done.

See also
lc::Undoable
lc::UndoManager
lc::UndoManagerImpl
Returns

Implements lc::UndoManager.

Definition at line 63 of file undomanagerimpl.cpp.

63  {
64  return !_unDoables.empty();
65 }
std::vector< operation::Undoable_SPtr > _unDoables
Undo list.
void UndoManagerImpl::on_CommitProcessEvent ( const lc::CommitProcessEvent event)

Definition at line 15 of file undomanagerimpl.cpp.

15  {
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 }
virtual bool canRedo() const
Check if redo can be done.
: 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.
const unsigned int _maximumUndoLevels
Maximum undo level.
std::stack< operation::Undoable_SPtr > _reDoables
Redo stack.
void UndoManagerImpl::redo ( )
virtual

redo an operation.

See also
lc::Undoable
lc::UndoManager
lc::UndoManagerImpl

Implements lc::UndoManager.

Definition at line 43 of file undomanagerimpl.cpp.

43  {
44  if (canRedo()) {
45  operation::Undoable_SPtr undoable = _reDoables.top();
46  _reDoables.pop();
47  undoable->redo();
48  _unDoables.push_back(undoable);
49  }
50 }
virtual bool canRedo() const
Check if redo can be done.
std::vector< operation::Undoable_SPtr > _unDoables
Undo list.
std::stack< operation::Undoable_SPtr > _reDoables
Redo stack.
void UndoManagerImpl::removeUndoables ( )
virtual

Clears the Undo/Redo stack.

See also
lc::Undoable
lc::UndoManager
lc::UndoManagerImpl
Returns

Implements lc::UndoManager.

Definition at line 67 of file undomanagerimpl.cpp.

67  {
68  _unDoables.clear();
69 
70  while (!_reDoables.empty()) {
71  _reDoables.pop();
72  }
73 }
std::vector< operation::Undoable_SPtr > _unDoables
Undo list.
std::stack< operation::Undoable_SPtr > _reDoables
Redo stack.
void UndoManagerImpl::undo ( )
virtual

undo an operation.

See also
lc::Undoable
lc::UndoManager
lc::UndoManagerImpl

Implements lc::UndoManager.

Definition at line 51 of file undomanagerimpl.cpp.

51  {
52  if (canUndo()) {
53  operation::Undoable_SPtr undoable = _unDoables.back();
54  _unDoables.pop_back();
55  undoable->undo();
56  _reDoables.push(undoable);
57  }
58 }
std::vector< operation::Undoable_SPtr > _unDoables
Undo list.
std::stack< operation::Undoable_SPtr > _reDoables
Redo stack.
virtual bool canUndo() const
Check if undo can be done.

Member Data Documentation

const unsigned int lc::UndoManagerImpl::_maximumUndoLevels
private

Maximum undo level.

Definition at line 67 of file undomanagerimpl.h.

std::stack<operation::Undoable_SPtr> lc::UndoManagerImpl::_reDoables
private

Redo stack.

Definition at line 66 of file undomanagerimpl.h.

std::vector<operation::Undoable_SPtr> lc::UndoManagerImpl::_unDoables
private

Undo list.

Definition at line 65 of file undomanagerimpl.h.


The documentation for this class was generated from the following files: