20class UndoStack :
public QObject
23 Q_PROPERTY (QStringList undoActions READ undoActions NOTIFY undoActionsChanged)
24 Q_PROPERTY (QStringList redoActions READ redoActions NOTIFY redoActionsChanged)
25 Q_PROPERTY (
int index READ index WRITE setIndex NOTIFY indexChanged)
26 Q_PROPERTY (
bool canUndo READ canUndo NOTIFY canUndoChanged)
27 Q_PROPERTY (
bool canRedo READ canRedo NOTIFY canRedoChanged)
37 std::function<void (
const std::function<
void ()> &,
bool)>;
41 QObject * parent =
nullptr);
46 void push (QUndoCommand * cmd);
47 Q_INVOKABLE
void undo ();
48 Q_INVOKABLE
void redo ();
50 bool canUndo ()
const {
return stack_->canUndo (); }
51 bool canRedo ()
const {
return stack_->canRedo (); }
53 const QUndoCommand * command (
int index)
const
55 return stack_->command (index);
58 Q_INVOKABLE
void beginMacro (
const QString &text)
60 stack_->beginMacro (text);
62 Q_INVOKABLE
void endMacro () { stack_->endMacro (); }
64 QStringList undoActions ();
65 QStringList redoActions ();
67 int index ()
const {
return stack_->index (); }
68 void setIndex (
int idx);
70 auto count ()
const {
return stack_->count (); }
71 auto text (
int idx)
const {
return stack_->text (idx); }
74 void undoActionsChanged ();
75 void redoActionsChanged ();
77 void canUndoChanged ();
78 void canRedoChanged ();
82 static constexpr auto kStackContentKey =
"stackContent"sv;
83 friend void to_json (nlohmann::json &j,
const UndoStack &u);
84 friend void from_json (
const nlohmann::json &j, UndoStack &u);
92 bool command_or_children_require_graph_recalculation (
93 const QUndoCommand &cmd)
const;
99 bool command_or_children_require_engine_pause (
const QUndoCommand &cmd)
const;
107 void execute_with_engine_pause_if_needed (
108 const QUndoCommand &cmd,
109 const std::function<
void ()> &action);
112 utils::QObjectUniquePtr<QUndoStack> stack_;