WSF
Undo.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11#ifndef UNDO_HPP
12#define UNDO_HPP
13
14#include <stack>
15#include <string>
16
17#include <QUndoCommand>
18
19#include "ViExport.hpp"
20#include "WsfPM_Platform.hpp"
21#include "WsfPProxy.hpp"
22class QAction;
23class WsfPProxyPath;
24
25namespace wizard
26{
27class UndoContext;
28class UndoProxyChange;
29
31{
32public:
33 enum Flags
34 {
36 };
37 friend class UndoContext;
38
39 static Undo* Instance() { return sInstance; }
40 static void Destroy()
41 {
42 delete sInstance;
43 sInstance = nullptr;
44 }
45
46 Undo();
47 Undo(const Undo&) = delete; // Copy
48 Undo(Undo&&) = default; // Move
49 Undo& operator=(const Undo&) = delete; // Copy assignment
50 Undo& operator=(Undo&&) = default; // Move assignment
51 ~Undo();
52
53 QAction* CreateUndoAction(QObject* aParent);
54
55 QAction* CreateRedoAction(QObject* aParent);
56
57 void BeforeProxyChange(WsfPProxy* aProxyPtr,
58 WsfPProxy::ProxyModifiedReason aProxyModifiedReason,
59 const WsfPProxyPath& aPath,
60 const std::string* aRenameName);
61
62 QUndoCommand* CurrentCommand() const;
63
64 void PushUndo(QUndoCommand* aUndoPtr);
65 QUndoStack* UndoStack() const { return mUndoStack; }
66
67 void ClearProxyChanges();
68 void BeginDiscardProxyChanges() { ++mDiscardProxyChanges; }
69 void EndDiscardProxyChanges() { --mDiscardProxyChanges; }
70 QUndoStack* GetUndoStack() { return mUndoStack; }
71
72private:
73 static Undo* sInstance;
74 QUndoStack* mUndoStack;
75 QUndoCommand* mCurrentGroup;
76 int mUndoContextCount;
77 int mUndoFlags;
78 int mDiscardProxyChanges;
79};
80
81class VI_EXPORT UndoProxyChange : public QUndoCommand
82{
83public:
92
93 static UndoProxyChange* createUndo(WsfPProxy* aProxyPtr,
94 WsfPProxy::ProxyModifiedReason aProxyModifiedReason,
95 const WsfPProxyPath& aPath,
96 const std::string* aRenameName);
97
98 ~UndoProxyChange() override;
99
100 void undo() override;
101 void redo() override;
102
103private:
104 UndoProxyChange(QUndoCommand* aParent, Action aAction, const WsfPProxyPath& aPath);
105
106protected:
107 // Toggles the action. Can implement undo and redo
108 void UndoRedo(WsfPProxy* aProxyPtr);
114 // for cRENAME_CHILD, mSwapName is the final name
115 std::string mSwapName;
116};
117
118// Groups undo events between constructor and destructor into a single action
120{
121public:
122 explicit UndoContext(const char* aUndoDescription = nullptr);
123 explicit UndoContext(const std::string& aUndoDescription);
124 explicit UndoContext(const QString& aUndoDescription);
125 ~UndoContext();
126 QUndoCommand* ParentCommand() const;
127 void SetFlags(int aFlags);
128 void ClearFlags(int aFlags);
129 void End();
130 void Push(QUndoCommand* aUndoPtr) { Undo::Instance()->PushUndo(aUndoPtr); }
131
132private:
133 void Init(const QString& aUndoDescription);
134
135 bool mEnded;
136 int mFlagsSet;
137 int mFlagsCleared;
138 // the flags that need to be toggled when this context goes out of scope
139 int mFlagsToggled;
140};
141} // namespace wizard
142#endif
#define VI_EXPORT
Definition ViExport.hpp:38
Represents a path or unique key to a value in the proxy.
Definition WsfPProxyPath.hpp:64
Definition WsfPProxyValue.hpp:33
Definition WsfPProxy.hpp:32
ProxyModifiedReason
Definition WsfPProxy.hpp:35
Definition Undo.hpp:120
UndoContext(const char *aUndoDescription=nullptr)
Definition Undo.cpp:332
void Push(QUndoCommand *aUndoPtr)
Definition Undo.hpp:130
QUndoCommand * ParentCommand() const
Definition Undo.cpp:410
void ClearFlags(int aFlags)
Definition Undo.cpp:403
void End()
Definition Undo.cpp:352
void SetFlags(int aFlags)
Definition Undo.cpp:397
Definition Undo.hpp:82
std::string mSwapName
Definition Undo.hpp:115
Action mAction
Definition Undo.hpp:111
WsfPProxy * mProxyPtr
Definition Undo.hpp:110
Action
Definition Undo.hpp:85
@ cNULL_ACTION
Definition Undo.hpp:90
@ cADD_CHILD
Definition Undo.hpp:86
@ cREMOVE_CHILD
Definition Undo.hpp:87
@ cRENAME_CHILD
Definition Undo.hpp:89
@ cASSIGN_VALUE
Definition Undo.hpp:88
WsfPProxyPath mChangePath
Definition Undo.hpp:112
bool mIsUndone
Definition Undo.hpp:109
WsfPProxyValue mSwapValue
Definition Undo.hpp:113
Definition Undo.hpp:31
Undo(const Undo &)=delete
Undo(Undo &&)=default
QAction * CreateUndoAction(QObject *aParent)
Definition Undo.cpp:76
void EndDiscardProxyChanges()
Definition Undo.hpp:69
Undo & operator=(const Undo &)=delete
QAction * CreateRedoAction(QObject *aParent)
Definition Undo.cpp:84
void PushUndo(QUndoCommand *aUndoPtr)
Definition Undo.cpp:58
QUndoStack * UndoStack() const
Definition Undo.hpp:65
static Undo * Instance()
Definition Undo.hpp:39
Flags
Definition Undo.hpp:34
@ cDISCARD_PROXY_CHANGES
Definition Undo.hpp:35
QUndoCommand * CurrentCommand() const
Definition Undo.cpp:53
void BeginDiscardProxyChanges()
Definition Undo.hpp:68
Undo & operator=(Undo &&)=default
QUndoStack * GetUndoStack()
Definition Undo.hpp:70
void BeforeProxyChange(WsfPProxy *aProxyPtr, WsfPProxy::ProxyModifiedReason aProxyModifiedReason, const WsfPProxyPath &aPath, const std::string *aRenameName)
Definition Undo.cpp:35
static void Destroy()
Definition Undo.hpp:40
Undo()
Definition Undo.cpp:19
friend class UndoContext
Definition Undo.hpp:37
Definition Runner.hpp:22
Copyrights Multiple, All Rights Reserved