18class UndoStack :
public QAbstractListModel
22 Q_PROPERTY (
int rowCount READ rowCount NOTIFY rowCountChanged FINAL)
25 UndoStack (QObject * parent =
nullptr);
26 Q_DISABLE_COPY_MOVE (UndoStack)
27 ~UndoStack ()
override =
default;
33 enum UndoableActionRoles
35 UndoableActionPtrRole = Qt::UserRole + 1,
38 QHash<int, QByteArray> roleNames ()
const override;
39 int rowCount (
const QModelIndex &parent = QModelIndex ())
const override;
41 data (
const QModelIndex &index,
int role = Qt::DisplayRole)
const override;
43 Q_SIGNAL
void rowCountChanged (
int rowCount);
62 template <UndoableActionSub
class T>
void push (T * action);
69 std::optional<UndoableActionPtrVariant>
pop ();
76 std::optional<UndoableActionPtrVariant>
pop_last ();
77 auto size ()
const {
return actions_.size (); }
78 bool is_empty ()
const {
return actions_.empty (); }
79 bool empty ()
const {
return is_empty (); }
80 bool is_full ()
const {
return size () ==
max_size_; }
89 std::optional<UndoableActionPtrVariant>
peek ()
const;
91 void clear () {
actions_.clear (); };
98 template <UndoableActionSub
class T>
104 void get_plugins (std::vector<zrythm::plugins::Plugin *> &arr)
const;
106 friend void init_from (
108 const UndoStack &other,
112 static constexpr auto kMaxLengthKey =
"maxLength"sv;
113 friend void to_json (nlohmann::json &j,
const UndoStack &stack)
118 friend void from_json (
const nlohmann::json &j,
UndoStack &stack)
120 j.at (kMaxLengthKey).get_to (stack.
max_size_);