| #pragma once |
| |
| #ifndef T_UNDO_INCLUDED |
| #define T_UNDO_INCLUDED |
| |
| #include <memory> |
| |
| |
| #include "tsmartpointer.h" |
| |
| |
| #include <QObject> |
| #include <QString> |
| |
| #undef DVAPI |
| #undef DVVAR |
| #ifdef TNZCORE_EXPORTS |
| #define DVAPI DV_EXPORT_API |
| #define DVVAR DV_EXPORT_VAR |
| #else |
| #define DVAPI DV_IMPORT_API |
| #define DVVAR DV_IMPORT_VAR |
| #endif |
| |
| |
| |
| |
| |
| class DVAPI TUndo { |
| public: |
| bool m_isLastInBlock; |
| |
| public: |
| TUndo() {} |
| virtual ~TUndo() {} |
| |
| virtual int getSize() const = 0; |
| |
| virtual void undo() const = 0; |
| virtual void redo() const = 0; |
| |
| virtual void onAdd() {} |
| |
| |
| virtual QString getHistoryString() { |
| return QObject::tr("Unidentified Action"); |
| } |
| virtual int getHistoryType() { return 0; } |
| |
| private: |
| |
| TUndo(const TUndo &undo); |
| TUndo &operator=(const TUndo &undo); |
| }; |
| |
| |
| |
| |
| |
| class DVAPI TUndoManager final : public QObject { |
| Q_OBJECT |
| |
| public: |
| TUndoManager(); |
| ~TUndoManager(); |
| |
| static TUndoManager *manager(); |
| |
| void beginBlock(); |
| void endBlock(); |
| |
| void add(TUndo *undo); |
| |
| bool undo(); |
| bool redo(); |
| |
| void reset(); |
| |
| |
| |
| |
| |
| void popUndo(int n = -1, bool forward = false); |
| |
| |
| |
| |
| void skip(); |
| |
| |
| |
| void setUndoMemorySize(int memorySyze); |
| |
| |
| int getHistoryCount(); |
| int getCurrentHistoryIndex(); |
| TUndo *getUndoItem(int index); |
| |
| Q_SIGNALS: |
| |
| void historyChanged(); |
| |
| void somethingChanged(); |
| |
| private: |
| struct TUndoManagerImp; |
| std::unique_ptr<TUndoManagerImp> m_imp; |
| |
| private: |
| |
| TUndoManager(const TUndoManager &); |
| TUndoManager &operator=(const TUndoManager &); |
| }; |
| |
| |
| |
| |
| |
| struct TUndoScopedBlock { |
| TUndoScopedBlock() { TUndoManager::manager()->beginBlock(); } |
| ~TUndoScopedBlock() { TUndoManager::manager()->endBlock(); } |
| |
| private: |
| |
| TUndoScopedBlock(const TUndoScopedBlock &); |
| TUndoScopedBlock &operator=(const TUndoScopedBlock &); |
| }; |
| |
| #endif |