Enzo
Loading...
Searching...
No Matches
UndoGroup.h
1#pragma once
2
3#include "Engine/UndoRedo/UndoCommand.h"
4#include <memory>
5#include <vector>
6
7namespace enzo::nt {
8
10class UndoGroup : public UndoCommand
11{
12 public:
13 UndoGroup() {}
14
16 void addCommand(std::unique_ptr<UndoCommand> command)
17 {
18 commands_.push_back(std::move(command));
19 }
20
22 bool isEmpty() const { return commands_.empty(); }
23
24 void undo() override
25 {
26 for (auto it = commands_.rbegin(); it != commands_.rend(); ++it)
27 {
28 (*it)->undo();
29 }
30 }
31
32 void redo() override
33 {
34 for (auto& command : commands_)
35 {
36 command->redo();
37 }
38 }
39
40 UndoCommandType type() const override { return UndoCommandType::UndoGroup; }
41
42 private:
43 std::vector<std::unique_ptr<UndoCommand>> commands_;
44};
45
46} // namespace enzo::nt
Definition UndoCommand.h:8
Bundles several commands into a single atomic undo unit.
Definition UndoGroup.h:11
bool isEmpty() const
Returns true when the group holds no commands.
Definition UndoGroup.h:22
void addCommand(std::unique_ptr< UndoCommand > command)
Appends a command to the group, taking ownership.
Definition UndoGroup.h:16