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

Do multiple operations on a document with only one undo cycle. More...

#include <builder.h>

Inheritance diagram for lc::operation::Builder:
Collaboration diagram for lc::operation::Builder:

Public Member Functions

 Builder (Document_SPtr document, const std::string &description)
 
void append (DocumentOperation_SPtr operation)
 Add an operation to the Builder. More...
 
virtual void undo () const override
 Undo a given operation. More...
 
virtual void redo () const override
 Redo a given operation. More...
 
- Public Member Functions inherited from lc::operation::DocumentOperation
 DocumentOperation (Document_SPtr document, const std::string &description)
 
Document_SPtr document () const
 
virtual void execute ()
 execute this operation More...
 
virtual ~DocumentOperation ()
 
- Public Member Functions inherited from lc::operation::Undoable
 Undoable (const std::string &text)
 Name of this operartion. More...
 
virtual ~Undoable ()
 
virtual std::string text ()
 Name of the operation. More...
 

Protected Member Functions

virtual void processInternal () override
 

Private Attributes

std::vector
< DocumentOperation_SPtr > 
_operations
 

Detailed Description

Do multiple operations on a document with only one undo cycle.

Definition at line 13 of file builder.h.

Constructor & Destructor Documentation

Builder::Builder ( Document_SPtr  document,
const std::string &  description 
)

Definition at line 6 of file builder.cpp.

6  :
7  DocumentOperation(document, description) {
8 
9 }
DocumentOperation(Document_SPtr document, const std::string &description)

Member Function Documentation

void Builder::append ( DocumentOperation_SPtr  operation)

Add an operation to the Builder.

Parameters
operationOperation to add The operation should have the same document than the builder

Definition at line 11 of file builder.cpp.

11  {
12  if(operation->document() != document()) {
13  throw "Operation should have the same document";
14  }
15 
16  _operations.push_back(operation);
17 }
std::vector< DocumentOperation_SPtr > _operations
Definition: builder.h:31
void Builder::processInternal ( )
overrideprotectedvirtual

This function gets called when an operation starts and when the document is locked for you so you can do your work

Implements lc::operation::DocumentOperation.

Definition at line 31 of file builder.cpp.

31  {
32  for(auto operation : _operations) {
33  operation->processInternal();
34  }
35 }
std::vector< DocumentOperation_SPtr > _operations
Definition: builder.h:31
void Builder::redo ( ) const
overridevirtual

Redo a given operation.

This can get called if we want to redo a operation. Redo is usually called after an undo operation. If in the undo operation entities where removed, it needs to get added again. it doesn't have to do any re.calculation but just remember what entities have been added or removed.

Implements lc::operation::Undoable.

Definition at line 25 of file builder.cpp.

25  {
26  for(auto operation : _operations) {
27  operation->redo();
28  }
29 }
std::vector< DocumentOperation_SPtr > _operations
Definition: builder.h:31
void Builder::undo ( ) const
overridevirtual

Undo a given operation.

For any operation that means for example when it added entities to the document it now needs to remove all created entities on the document. When the operation added a layer or block, it will call functions to remove that block

Implements lc::operation::Undoable.

Definition at line 19 of file builder.cpp.

19  {
20  for(auto it = _operations.rbegin(); it != _operations.rend(); it++) {
21  (*it)->undo();
22  }
23 }
std::vector< DocumentOperation_SPtr > _operations
Definition: builder.h:31

Member Data Documentation

std::vector<DocumentOperation_SPtr> lc::operation::Builder::_operations
private

Definition at line 31 of file builder.h.


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