17class UndoStack :
public QObject
20 Q_PROPERTY (QStringList undoActions READ undoActions NOTIFY undoActionsChanged)
21 Q_PROPERTY (QStringList redoActions READ redoActions NOTIFY redoActionsChanged)
22 Q_PROPERTY (
int index READ index WRITE setIndex NOTIFY indexChanged)
23 Q_PROPERTY (
bool canUndo READ canUndo NOTIFY canUndoChanged)
24 Q_PROPERTY (
bool canRedo READ canRedo NOTIFY canRedoChanged)
34 std::function<void (
const std::function<
void ()> &,
bool)>;
38 QObject * parent =
nullptr);
43 void push (QUndoCommand * cmd);
44 Q_INVOKABLE
void undo ();
45 Q_INVOKABLE
void redo ();
47 bool canUndo ()
const {
return stack_->canUndo (); }
48 bool canRedo ()
const {
return stack_->canRedo (); }
50 const QUndoCommand * command (
int index)
const
52 return stack_->command (index);
55 Q_INVOKABLE
void beginMacro (
const QString &text)
57 stack_->beginMacro (text);
59 Q_INVOKABLE
void endMacro () { stack_->endMacro (); }
61 QStringList undoActions ();
62 QStringList redoActions ();
64 int index ()
const {
return stack_->index (); }
65 void setIndex (
int idx);
67 auto count ()
const {
return stack_->count (); }
68 auto text (
int idx)
const {
return stack_->text (idx); }
71 void undoActionsChanged ();
72 void redoActionsChanged ();
74 void canUndoChanged ();
75 void canRedoChanged ();
79 static constexpr auto kStackContentKey =
"stackContent"sv;
80 friend void to_json (nlohmann::json &j,
const UndoStack &u);
81 friend void from_json (
const nlohmann::json &j, UndoStack &u);
89 bool command_or_children_require_graph_recalculation (
90 const QUndoCommand &cmd)
const;
96 bool command_or_children_require_engine_pause (
const QUndoCommand &cmd)
const;
104 void execute_with_engine_pause_if_needed (
105 const QUndoCommand &cmd,
106 const std::function<
void ()> &action);
109 utils::QObjectUniquePtr<QUndoStack> stack_;