1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QUNDOSTACK_H |
41 | #define QUNDOSTACK_H |
42 | |
43 | #include <QtWidgets/qtwidgetsglobal.h> |
44 | #include <QtCore/qobject.h> |
45 | #include <QtCore/qstring.h> |
46 | |
47 | QT_REQUIRE_CONFIG(undocommand); |
48 | |
49 | QT_BEGIN_NAMESPACE |
50 | |
51 | class QAction; |
52 | class QUndoCommandPrivate; |
53 | class QUndoStackPrivate; |
54 | |
55 | class Q_WIDGETS_EXPORT QUndoCommand |
56 | { |
57 | QUndoCommandPrivate *d; |
58 | |
59 | public: |
60 | explicit QUndoCommand(QUndoCommand *parent = nullptr); |
61 | explicit QUndoCommand(const QString &text, QUndoCommand *parent = nullptr); |
62 | virtual ~QUndoCommand(); |
63 | |
64 | virtual void undo(); |
65 | virtual void redo(); |
66 | |
67 | QString text() const; |
68 | QString actionText() const; |
69 | void setText(const QString &text); |
70 | |
71 | bool isObsolete() const; |
72 | void setObsolete(bool obsolete); |
73 | |
74 | virtual int id() const; |
75 | virtual bool mergeWith(const QUndoCommand *other); |
76 | |
77 | int childCount() const; |
78 | const QUndoCommand *child(int index) const; |
79 | |
80 | private: |
81 | Q_DISABLE_COPY(QUndoCommand) |
82 | friend class QUndoStack; |
83 | }; |
84 | |
85 | #if QT_CONFIG(undostack) |
86 | |
87 | class Q_WIDGETS_EXPORT QUndoStack : public QObject |
88 | { |
89 | Q_OBJECT |
90 | Q_DECLARE_PRIVATE(QUndoStack) |
91 | Q_PROPERTY(bool active READ isActive WRITE setActive) |
92 | Q_PROPERTY(int undoLimit READ undoLimit WRITE setUndoLimit) |
93 | Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged) |
94 | Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged) |
95 | Q_PROPERTY(QString undoText READ undoText NOTIFY undoTextChanged) |
96 | Q_PROPERTY(QString redoText READ redoText NOTIFY redoTextChanged) |
97 | Q_PROPERTY(bool clean READ isClean NOTIFY cleanChanged) |
98 | |
99 | public: |
100 | explicit QUndoStack(QObject *parent = nullptr); |
101 | ~QUndoStack(); |
102 | void clear(); |
103 | |
104 | void push(QUndoCommand *cmd); |
105 | |
106 | bool canUndo() const; |
107 | bool canRedo() const; |
108 | QString undoText() const; |
109 | QString redoText() const; |
110 | |
111 | int count() const; |
112 | int index() const; |
113 | QString text(int idx) const; |
114 | |
115 | #ifndef QT_NO_ACTION |
116 | QAction *createUndoAction(QObject *parent, |
117 | const QString &prefix = QString()) const; |
118 | QAction *createRedoAction(QObject *parent, |
119 | const QString &prefix = QString()) const; |
120 | #endif // QT_NO_ACTION |
121 | |
122 | bool isActive() const; |
123 | bool isClean() const; |
124 | int cleanIndex() const; |
125 | |
126 | void beginMacro(const QString &text); |
127 | void endMacro(); |
128 | |
129 | void setUndoLimit(int limit); |
130 | int undoLimit() const; |
131 | |
132 | const QUndoCommand *command(int index) const; |
133 | |
134 | public Q_SLOTS: |
135 | void setClean(); |
136 | void resetClean(); |
137 | void setIndex(int idx); |
138 | void undo(); |
139 | void redo(); |
140 | void setActive(bool active = true); |
141 | |
142 | Q_SIGNALS: |
143 | void indexChanged(int idx); |
144 | void cleanChanged(bool clean); |
145 | void canUndoChanged(bool canUndo); |
146 | void canRedoChanged(bool canRedo); |
147 | void undoTextChanged(const QString &undoText); |
148 | void redoTextChanged(const QString &redoText); |
149 | |
150 | private: |
151 | Q_DISABLE_COPY(QUndoStack) |
152 | friend class QUndoGroup; |
153 | }; |
154 | |
155 | #endif // QT_CONFIG(undostack) |
156 | |
157 | QT_END_NAMESPACE |
158 | |
159 | #endif // QUNDOSTACK_H |
160 | |