Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qundostack.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QUNDOSTACK_H
5#define QUNDOSTACK_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/qobject.h>
9#include <QtCore/qstring.h>
10
11QT_REQUIRE_CONFIG(undocommand);
12
14
15class QAction;
17class QUndoStackPrivate;
18
19class Q_GUI_EXPORT QUndoCommand
20{
22
23public:
24 explicit QUndoCommand(QUndoCommand *parent = nullptr);
25 explicit QUndoCommand(const QString &text, QUndoCommand *parent = nullptr);
26 virtual ~QUndoCommand();
27
28 virtual void undo();
29 virtual void redo();
30
31 QString text() const;
32 QString actionText() const;
33 void setText(const QString &text);
34
35 bool isObsolete() const;
36 void setObsolete(bool obsolete);
37
38 virtual int id() const;
39 virtual bool mergeWith(const QUndoCommand *other);
40
41 int childCount() const;
42 const QUndoCommand *child(int index) const;
43
44private:
45 Q_DISABLE_COPY(QUndoCommand)
46 friend class QUndoStack;
47};
48
49#if QT_CONFIG(undostack)
50
51class Q_GUI_EXPORT QUndoStack : public QObject
52{
54 Q_DECLARE_PRIVATE(QUndoStack)
55 Q_PROPERTY(bool active READ isActive WRITE setActive)
56 Q_PROPERTY(int undoLimit READ undoLimit WRITE setUndoLimit)
57 Q_PROPERTY(bool canUndo READ canUndo NOTIFY canUndoChanged)
58 Q_PROPERTY(bool canRedo READ canRedo NOTIFY canRedoChanged)
59 Q_PROPERTY(QString undoText READ undoText NOTIFY undoTextChanged)
60 Q_PROPERTY(QString redoText READ redoText NOTIFY redoTextChanged)
61 Q_PROPERTY(bool clean READ isClean NOTIFY cleanChanged)
62
63public:
64 explicit QUndoStack(QObject *parent = nullptr);
65 ~QUndoStack();
66 void clear();
67
68 void push(QUndoCommand *cmd);
69
70 bool canUndo() const;
71 bool canRedo() const;
72 QString undoText() const;
73 QString redoText() const;
74
75 int count() const;
76 int index() const;
77 QString text(int idx) const;
78
79#ifndef QT_NO_ACTION
80 QAction *createUndoAction(QObject *parent, const QString &prefix = QString()) const;
81 QAction *createRedoAction(QObject *parent, const QString &prefix = QString()) const;
82#endif // QT_NO_ACTION
83
84 bool isActive() const;
85 bool isClean() const;
86 int cleanIndex() const;
87
88 void beginMacro(const QString &text);
89 void endMacro();
90
91 void setUndoLimit(int limit);
92 int undoLimit() const;
93
94 const QUndoCommand *command(int index) const;
95
96public Q_SLOTS:
97 void setClean();
98 void resetClean();
99 void setIndex(int idx);
100 void undo();
101 void redo();
102 void setActive(bool active = true);
103
105 void indexChanged(int idx);
106 void cleanChanged(bool clean);
107 void canUndoChanged(bool canUndo);
108 void canRedoChanged(bool canRedo);
109 void undoTextChanged(const QString &undoText);
110 void redoTextChanged(const QString &redoText);
111
112private:
113 Q_DISABLE_COPY(QUndoStack)
114 friend class QUndoGroup;
115};
116
117#endif // QT_CONFIG(undostack)
118
120
121#endif // QUNDOSTACK_H
bool isActive
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
\inmodule QtCore
Definition qobject.h:103
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QUndoGroup class is a group of QUndoStack objects.
Definition qundogroup.h:20
b clear()
QString text
Combined button and popup list for selecting options.
static void setIndex(int *index, int candidate, int min, int max, bool isIncreasing)
Definition qmdiarea.cpp:175
GLuint index
[2]
GLenum GLuint id
[7]
GLenum GLenum GLsizei count
GLint limit
#define QT_REQUIRE_CONFIG(feature)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
QSharedPointer< T > other(t)
[5]
QLayoutItem * child
[0]
stack endMacro()
insertRed setText("insert red text")
stack undo()
stack push(command1)
stack beginMacro("insert red text")
[3]