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

#include <blockops.h>

Inheritance diagram for lc::operation::ReplaceBlock:
Collaboration diagram for lc::operation::ReplaceBlock:

Public Member Functions

 ReplaceBlock (const Document_SPtr &document, const Block_CSPtr &oldBlock, const Block_CSPtr &newBlock)
 
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

Block_CSPtr _oldBlock
 
Block_CSPtr _newBlock
 

Detailed Description

Definition at line 37 of file blockops.h.

Constructor & Destructor Documentation

ReplaceBlock::ReplaceBlock ( const Document_SPtr &  document,
const Block_CSPtr &  oldBlock,
const Block_CSPtr &  newBlock 
)

Definition at line 44 of file blockops.cpp.

44  :
45  DocumentOperation(document, "ReplaceBlock"),
46  _oldBlock(oldBlock),
47  _newBlock(newBlock) {
48 
49 }
DocumentOperation(Document_SPtr document, const std::string &description)

Member Function Documentation

void ReplaceBlock::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 61 of file blockops.cpp.

61  {
62  auto entities = document()->entitiesByBlock(_oldBlock).asVector();
63 
64  for(auto entity : entities) {
65  document()->removeEntity(entity);
66  document()->insertEntity(entity->modify(
67  entity->layer(),
68  entity->metaInfo(),
69  _newBlock
70  ));
71  }
72 
73  document()->removeDocumentMetaType(_oldBlock);
74  document()->addDocumentMetaType(_newBlock);
75 
76  //TODO: should we modify the inserts ?
77 }
void ReplaceBlock::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 56 of file blockops.cpp.

56  {
57  document()->removeDocumentMetaType(_oldBlock);
58  document()->addDocumentMetaType(_newBlock);
59 }
void ReplaceBlock::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 51 of file blockops.cpp.

51  {
52  document()->removeDocumentMetaType(_newBlock);
53  document()->addDocumentMetaType(_oldBlock);
54 }

Member Data Documentation

Block_CSPtr lc::operation::ReplaceBlock::_newBlock
private

Definition at line 49 of file blockops.h.

Block_CSPtr lc::operation::ReplaceBlock::_oldBlock
private

Definition at line 48 of file blockops.h.


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