File indexing completed on 2025-01-18 10:08:18
0001
0002
0003
0004 #ifndef QUNDOSTACK_H
0005 #define QUNDOSTACK_H
0006
0007 #include <QtGui/qtguiglobal.h>
0008 #include <QtCore/qobject.h>
0009 #include <QtCore/qstring.h>
0010
0011 QT_REQUIRE_CONFIG(undocommand);
0012
0013 QT_BEGIN_NAMESPACE
0014
0015 class QAction;
0016 class QUndoCommandPrivate;
0017 class QUndoStackPrivate;
0018
0019 class Q_GUI_EXPORT QUndoCommand
0020 {
0021 QUndoCommandPrivate *d;
0022
0023 public:
0024 explicit QUndoCommand(QUndoCommand *parent = nullptr);
0025 explicit QUndoCommand(const QString &text, QUndoCommand *parent = nullptr);
0026 virtual ~QUndoCommand();
0027
0028 virtual void undo();
0029 virtual void redo();
0030
0031 QString text() const;
0032 QString actionText() const;
0033 void setText(const QString &text);
0034
0035 bool isObsolete() const;
0036 void setObsolete(bool obsolete);
0037
0038 virtual int id() const;
0039 virtual bool mergeWith(const QUndoCommand *other);
0040
0041 int childCount() const;
0042 const QUndoCommand *child(int index) const;
0043
0044 private:
0045 Q_DISABLE_COPY(QUndoCommand)
0046 friend class QUndoStack;
0047 };
0048
0049 #if QT_CONFIG(undostack)
0050
0051 class Q_GUI_EXPORT QUndoStack : public QObject
0052 {
0053 Q_OBJECT
0054 Q_DECLARE_PRIVATE(QUndoStack)
0055 Q_PROPERTY(bool active READ isActive WRITE setActive)
0056 Q_PROPERTY(int undoLimit READ undoLimit WRITE setUndoLimit)
0057 Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged)
0058 Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged)
0059 Q_PROPERTY(QString undoText READ undoText NOTIFY undoTextChanged)
0060 Q_PROPERTY(QString redoText READ redoText NOTIFY redoTextChanged)
0061 Q_PROPERTY(bool clean READ isClean NOTIFY cleanChanged)
0062
0063 public:
0064 explicit QUndoStack(QObject *parent = nullptr);
0065 ~QUndoStack();
0066 void clear();
0067
0068 void push(QUndoCommand *cmd);
0069
0070 bool canUndo() const;
0071 bool canRedo() const;
0072 QString undoText() const;
0073 QString redoText() const;
0074
0075 int count() const;
0076 int index() const;
0077 QString text(int idx) const;
0078
0079 #ifndef QT_NO_ACTION
0080 QAction *createUndoAction(QObject *parent, const QString &prefix = QString()) const;
0081 QAction *createRedoAction(QObject *parent, const QString &prefix = QString()) const;
0082 #endif
0083
0084 bool isActive() const;
0085 bool isClean() const;
0086 int cleanIndex() const;
0087
0088 void beginMacro(const QString &text);
0089 void endMacro();
0090
0091 void setUndoLimit(int limit);
0092 int undoLimit() const;
0093
0094 const QUndoCommand *command(int index) const;
0095
0096 public Q_SLOTS:
0097 void setClean();
0098 void resetClean();
0099 void setIndex(int idx);
0100 void undo();
0101 void redo();
0102 void setActive(bool active = true);
0103
0104 Q_SIGNALS:
0105 void indexChanged(int idx);
0106 void cleanChanged(bool clean);
0107 void canUndoChanged(bool canUndo);
0108 void canRedoChanged(bool canRedo);
0109 void undoTextChanged(const QString &undoText);
0110 void redoTextChanged(const QString &redoText);
0111
0112 private:
0113 Q_DISABLE_COPY(QUndoStack)
0114 friend class QUndoGroup;
0115 };
0116
0117 #endif
0118
0119 QT_END_NAMESPACE
0120
0121 #endif