MeshLib Documentation
Loading...
Searching...
No Matches
MRChangeNameAction.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRHistoryAction.h"
4#include "MRObject.h"
5#include <memory>
6#include <string>
7
8namespace MR
9{
10
14{
15public:
17 ChangeNameAction( const std::string& actionName, std::shared_ptr<Object> obj ) :
18 obj_{ std::move( obj ) },
19 actionName_{ actionName }
20 {
21 objName_ = obj_->name();
22 }
23
24 virtual std::string name() const override
25 {
26 return actionName_;
27 }
28
29 virtual void action( HistoryAction::Type ) override
30 {
31 if ( !obj_ )
32 return;
33
34 auto n = obj_->name();
35 obj_->setName( std::move( objName_ ) );
36 objName_ = std::move( n );
37 }
38
39 [[nodiscard]] virtual size_t heapBytes() const override
40 {
41 return objName_.capacity() + actionName_.capacity();
42 }
43
44private:
45 std::shared_ptr<Object> obj_;
46 std::string objName_;
47
48 std::string actionName_;
49};
50
51} // namespace MR
Definition MRChangeNameAction.h:14
virtual void action(HistoryAction::Type) override
This function is called on history action (undo, redo, etc.)
Definition MRChangeNameAction.h:29
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
Definition MRChangeNameAction.h:39
ChangeNameAction(const std::string &actionName, std::shared_ptr< Object > obj)
construct before giving new name to the object
Definition MRChangeNameAction.h:17
virtual std::string name() const override
Definition MRChangeNameAction.h:24
Definition MRHistoryAction.h:12
Type
Definition MRHistoryAction.h:19
Definition MRCameraOrientationPlugin.h:8