MeshLib C++ Docs
Loading...
Searching...
No Matches
MRAppendHistory.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRHistoryStore.h"
5#include <string>
6#include <memory>
7
8namespace MR
9{
12
13
15inline void AppendHistory( std::shared_ptr<HistoryAction> action )
16{
17 if ( const auto & s = HistoryStore::getViewerInstance() )
18 s->appendAction( std::move( action ) );
19}
20
22template<class HistoryActionType, typename... Args>
23void AppendHistory( Args&&... args )
24{
25 static_assert( std::is_base_of_v<HistoryAction, HistoryActionType> );
28 AppendHistory( std::make_shared<HistoryActionType>( std::forward<Args>( args )... ) );
29}
30
33template<class HistoryActionType>
35{
36public:
37 static_assert( std::is_base_of_v<HistoryAction, HistoryActionType> );
38 using Obj = typename HistoryActionType::Obj;
39
40 template<typename... Args>
41 Historian( std::string name, std::shared_ptr<Obj> obj, Args&&... args ) : obj_( std::move( obj ) )
42 {
44 action_ = std::make_shared<HistoryActionType>( std::move( name ), obj_, std::forward<Args>( args )... );
45 }
46
48 {
49 if ( action_ )
50 {
51 action_->action( HistoryAction::Type::Undo );
52 action_.reset();
53 }
54 canceled_ = true;
55 }
56
58 {
59 if ( action_ )
60 AppendHistory( std::move( action_ ) );
61 if ( !canceled_ )
62 HistoryActionType::setObjectDirty( obj_ );
63 }
64private:
65 std::shared_ptr<Obj> obj_;
66 std::shared_ptr<HistoryActionType> action_;
67 bool canceled_{ false };
68};
69
72MRVIEWER_API void FilterHistoryByCondition( HistoryStackFilter filteringCondition, bool deepFiltering = true );
73
76{
77public:
79 MRVIEWER_API ScopeHistory( const std::string& name );
80
82 MRVIEWER_API ~ScopeHistory();
83
85 const std::shared_ptr<CombinedHistoryAction>& combinedAction() const { return combinedAction_; }
86
87private:
88 HistoryStore* store_{ nullptr };
89 std::shared_ptr<CombinedHistoryAction> combinedAction_;
90 HistoryActionsVector* parentScopePtr_{ nullptr };
91};
92
93#define SCOPED_HISTORY(name) MR::ScopeHistory __startScopedHistoryMode(name)
94
95}
Definition MRAppendHistory.h:35
This class stores history stack for undo/redo.
Definition MRHistoryStore.h:16
static MRVIEWER_API HistoryStore * getViewerInstance()
The purpose of this class is to combine all actions appended to global history store in one big actio...
Definition MRAppendHistory.h:76
MRVIEWER_API ScopeHistory(const std::string &name)
creates new CombinedHistoryAction, and setups global history store to append all new actions there du...
MRVIEWER_API ~ScopeHistory()
created before CombinedHistoryAction if not empty is appended (with all sub-actions) in the global hi...
void AppendHistory(std::shared_ptr< HistoryAction > action)
Appends given history action to viewer's global history store.
Definition MRAppendHistory.h:15
Historian(std::string name, std::shared_ptr< Obj > obj, Args &&... args)
Definition MRAppendHistory.h:41
void cancelAction()
Definition MRAppendHistory.h:47
~Historian()
Definition MRAppendHistory.h:57
std::function< bool(const std::shared_ptr< HistoryAction > &)> HistoryStackFilter
Definition MRHistoryAction.h:33
std::vector< std::shared_ptr< HistoryAction > > HistoryActionsVector
Definition MRHistoryAction.h:34
const std::shared_ptr< CombinedHistoryAction > & combinedAction() const
returns the action being populated
Definition MRAppendHistory.h:85
typename HistoryActionType::Obj Obj
Definition MRAppendHistory.h:38
MRVIEWER_API void FilterHistoryByCondition(HistoryStackFilter filteringCondition, bool deepFiltering=true)
only for bindings generation
Definition MRCameraOrientationPlugin.h:8