| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2020 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 <QtGui/qtguiglobal.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_GUI_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_GUI_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, const QString &prefix = QString()) const; | 
| 117 |     QAction *createRedoAction(QObject *parent, const QString &prefix = QString()) const; | 
| 118 | #endif // QT_NO_ACTION | 
| 119 |  | 
| 120 |     bool isActive() const; | 
| 121 |     bool isClean() const; | 
| 122 |     int cleanIndex() const; | 
| 123 |  | 
| 124 |     void beginMacro(const QString &text); | 
| 125 |     void endMacro(); | 
| 126 |  | 
| 127 |     void setUndoLimit(int limit); | 
| 128 |     int undoLimit() const; | 
| 129 |  | 
| 130 |     const QUndoCommand *command(int index) const; | 
| 131 |  | 
| 132 | public Q_SLOTS: | 
| 133 |     void setClean(); | 
| 134 |     void resetClean(); | 
| 135 |     void setIndex(int idx); | 
| 136 |     void undo(); | 
| 137 |     void redo(); | 
| 138 |     void setActive(bool active = true); | 
| 139 |  | 
| 140 | Q_SIGNALS: | 
| 141 |     void indexChanged(int idx); | 
| 142 |     void cleanChanged(bool clean); | 
| 143 |     void canUndoChanged(bool canUndo); | 
| 144 |     void canRedoChanged(bool canRedo); | 
| 145 |     void undoTextChanged(const QString &undoText); | 
| 146 |     void redoTextChanged(const QString &redoText); | 
| 147 |  | 
| 148 | private: | 
| 149 |     Q_DISABLE_COPY(QUndoStack) | 
| 150 |     friend class QUndoGroup; | 
| 151 | }; | 
| 152 |  | 
| 153 | #endif // QT_CONFIG(undostack) | 
| 154 |  | 
| 155 | QT_END_NAMESPACE | 
| 156 |  | 
| 157 | #endif // QUNDOSTACK_H | 
| 158 |  |