Warning, file /multimedia/subtitlecomposer/src/core/undo/undostack.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 SPDX-FileCopyrightText: 2020-2022 Mladen Milinkovic <max@smoothware.net> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef UNDOSTACK_H 0008 #define UNDOSTACK_H 0009 0010 #include <QUndoStack> 0011 0012 #include <QStack> 0013 0014 QT_FORWARD_DECLARE_CLASS(QItemSelectionModel) 0015 0016 namespace SubtitleComposer { 0017 class UndoAction; 0018 0019 class UndoStack : private QUndoStack 0020 { 0021 Q_OBJECT 0022 0023 struct Selection { 0024 Selection(); 0025 Selection(QItemSelectionModel *sel); 0026 int preCurrentRow; 0027 int postCurrentRow; 0028 QList<std::pair<int, int>> preSelection; 0029 QList<std::pair<int, int>> postSelection; 0030 }; 0031 0032 public: 0033 typedef enum { 0034 None = 0, 0035 Primary = 1, 0036 Secondary = 2, 0037 Both = Primary | Secondary, 0038 Invalid = -1 0039 } DirtyMode; 0040 0041 explicit UndoStack(QObject *parent = nullptr); 0042 virtual ~UndoStack(); 0043 0044 void clear(); 0045 void push(UndoAction *cmd); 0046 0047 void beginMacro(const QString &text); 0048 void endMacro(DirtyMode dirtyOverride = Invalid); 0049 0050 using QUndoStack::canUndo; 0051 using QUndoStack::canRedo; 0052 using QUndoStack::undoText; 0053 using QUndoStack::redoText; 0054 0055 using QUndoStack::count; 0056 using QUndoStack::index; 0057 using QUndoStack::text; 0058 0059 inline QAction *undoAction() const { return m_undoAction; } 0060 inline QAction *redoAction() const { return m_redoAction; } 0061 0062 // Subtitle handles/implements these 0063 // using QUndoStack::isActive; 0064 // using QUndoStack::isClean; 0065 // using QUndoStack::cleanIndex; 0066 0067 using QUndoStack::beginMacro; 0068 using QUndoStack::endMacro; 0069 0070 inline DirtyMode dirtyMode(int index) const { return m_dirtyStack.at(index); } 0071 using QUndoStack::command; 0072 0073 public slots: 0074 void undo(); 0075 void redo(); 0076 0077 private: 0078 void levelIncrease(int idx); 0079 void levelDecrease(int idx); 0080 0081 private: 0082 int m_level; 0083 QStack<Selection> m_selectionStack; 0084 QStack<DirtyMode> m_dirtyStack; 0085 QAction *m_undoAction; 0086 QAction *m_redoAction; 0087 }; 0088 0089 } 0090 0091 #endif // UNDOSTACK_H