![]() |
Qt 6.x
The Qt SDK
|
The QUndoGroup class is a group of QUndoStack objects. More...
#include <qundogroup.h>
Public Slots | |
void | undo () |
Calls QUndoStack::undo() on the active stack. | |
void | redo () |
Calls QUndoStack::redo() on the active stack. | |
void | setActiveStack (QUndoStack *stack) |
Sets the active stack of this group to stack. | |
![]() | |
void | deleteLater () |
\threadsafe | |
Signals | |
void | activeStackChanged (QUndoStack *stack) |
This signal is emitted whenever the active stack of the group changes. | |
void | indexChanged (int idx) |
This signal is emitted whenever the active stack emits QUndoStack::indexChanged() or the active stack changes. | |
void | cleanChanged (bool clean) |
This signal is emitted whenever the active stack emits QUndoStack::cleanChanged() or the active stack changes. | |
void | canUndoChanged (bool canUndo) |
This signal is emitted whenever the active stack emits QUndoStack::canUndoChanged() or the active stack changes. | |
void | canRedoChanged (bool canRedo) |
This signal is emitted whenever the active stack emits QUndoStack::canRedoChanged() or the active stack changes. | |
void | undoTextChanged (const QString &undoText) |
This signal is emitted whenever the active stack emits QUndoStack::undoTextChanged() or the active stack changes. | |
void | redoTextChanged (const QString &redoText) |
This signal is emitted whenever the active stack emits QUndoStack::redoTextChanged() or the active stack changes. | |
![]() | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. | |
Public Member Functions | |
QUndoGroup (QObject *parent=nullptr) | |
Creates an empty QUndoGroup object with parent parent. | |
~QUndoGroup () | |
Destroys the QUndoGroup. | |
void | addStack (QUndoStack *stack) |
Adds stack to this group. | |
void | removeStack (QUndoStack *stack) |
Removes stack from this group. | |
QList< QUndoStack * > | stacks () const |
Returns a list of stacks in this group. | |
QUndoStack * | activeStack () const |
Returns the active stack of this group. | |
QAction * | createUndoAction (QObject *parent, const QString &prefix=QString()) const |
Creates an undo QAction object with parent parent. | |
QAction * | createRedoAction (QObject *parent, const QString &prefix=QString()) const |
Creates an redo QAction object with parent parent. | |
bool | canUndo () const |
Returns the value of the active stack's QUndoStack::canUndo(). | |
bool | canRedo () const |
Returns the value of the active stack's QUndoStack::canRedo(). | |
QString | undoText () const |
Returns the value of the active stack's QUndoStack::undoText(). | |
QString | redoText () const |
Returns the value of the active stack's QUndoStack::redoText(). | |
bool | isClean () const |
Returns the value of the active stack's QUndoStack::isClean(). | |
![]() | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
template<typename T > | |
T | findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const |
bool | disconnect (const QObject *receiver, const char *member=nullptr) const |
void | dumpObjectTree () const |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
Additional Inherited Members | |
![]() | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a connection. | |
template<typename Func1 , typename Func2 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
![]() | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
![]() | |
QScopedPointer< QObjectData > | d_ptr |
![]() | |
QString | objectName |
the name of this object | |
![]() | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
The QUndoGroup class is a group of QUndoStack objects.
For an overview of the Qt's undo framework, see the \l{qundo.html}{overview}.
An application often has multiple undo stacks, one for each opened document. At the same time, an application usually has one undo action and one redo action, which triggers undo or redo in the active document.
QUndoGroup is a group of QUndoStack objects, one of which may be active. It has an undo() and redo() slot, which calls QUndoStack::undo() and QUndoStack::redo() for the active stack. It also has the functions createUndoAction() and createRedoAction(). The actions returned by these functions behave in the same way as those returned by QUndoStack::createUndoAction() and QUndoStack::createRedoAction() of the active stack.
Stacks are added to a group with addStack() and removed with removeStack(). A stack is implicitly added to a group when it is created with the group as its parent QObject.
It is the programmer's responsibility to specify which stack is active by calling QUndoStack::setActive(), usually when the associated document window receives focus. The active stack may also be set with setActiveStack(), and is returned by activeStack().
When a stack is added to a group using addStack(), the group does not take ownership of the stack. This means the stack has to be deleted separately from the group. When a stack is deleted, it is automatically removed from a group. A stack may belong to only one group. Adding it to another group will cause it to be removed from the previous group.
A QUndoGroup is also useful in conjunction with QUndoView. If a QUndoView is set to watch a group using QUndoView::setGroup(), it will update itself to display the active stack.
Definition at line 19 of file qundogroup.h.
Creates an empty QUndoGroup object with parent parent.
Definition at line 65 of file qundogroup.cpp.
QUndoGroup::~QUndoGroup | ( | ) |
QUndoStack * QUndoGroup::activeStack | ( | ) | const |
Returns the active stack of this group.
If none of the stacks are active, or if the group is empty, this function returns \nullptr.
Definition at line 214 of file qundogroup.cpp.
References d.
|
signal |
This signal is emitted whenever the active stack of the group changes.
This can happen when setActiveStack() or QUndoStack::setActive() is called, or when the active stack is removed form the group. stack is the new active stack. If no stack is active, stack is 0.
Referenced by setActiveStack().
void QUndoGroup::addStack | ( | QUndoStack * | stack | ) |
Adds stack to this group.
The group does not take ownership of the stack. Another way of adding a stack to a group is by specifying the group as the stack's parent QObject in QUndoStack::QUndoStack(). In this case, the stack is deleted when the group is deleted, in the usual manner of QObjects.
Definition at line 94 of file qundogroup.cpp.
bool QUndoGroup::canRedo | ( | ) | const |
Returns the value of the active stack's QUndoStack::canRedo().
If none of the stacks are active, or if the group is empty, this function returns false
.
Definition at line 356 of file qundogroup.cpp.
References d.
Referenced by createRedoAction().
|
signal |
This signal is emitted whenever the active stack emits QUndoStack::canRedoChanged() or the active stack changes.
canRedo is the new state, or false if the active stack is 0.
Referenced by createRedoAction(), and setActiveStack().
bool QUndoGroup::canUndo | ( | ) | const |
Returns the value of the active stack's QUndoStack::canUndo().
If none of the stacks are active, or if the group is empty, this function returns false
.
Definition at line 341 of file qundogroup.cpp.
References d.
Referenced by createUndoAction().
|
signal |
This signal is emitted whenever the active stack emits QUndoStack::canUndoChanged() or the active stack changes.
canUndo is the new state, or false if the active stack is 0.
Referenced by createUndoAction(), and setActiveStack().
|
signal |
This signal is emitted whenever the active stack emits QUndoStack::cleanChanged() or the active stack changes.
clean is the new state, or true if the active stack is 0.
Referenced by setActiveStack().
QAction * QUndoGroup::createRedoAction | ( | QObject * | parent, |
const QString & | prefix = QString() |
||
) | const |
Creates an redo QAction object with parent parent.
Triggering this action will cause a call to QUndoStack::redo() on the active stack. The text of this action will always be the text of the command which will be redone in the next call to redo(), prefixed by prefix. If there is no command available for redo, if the group is empty or if none of the stacks are active, this action will be disabled.
If prefix is empty, the default template "Redo %1" is used instead of prefix. Before Qt 4.8, the prefix "Redo" was used by default.
Definition at line 275 of file qundogroup.cpp.
References canRedo(), canRedoChanged(), QObject::connect(), QString::isEmpty(), QObject::parent(), redo(), redoText(), redoTextChanged(), QAction::setEnabled(), text, tr, and QAction::triggered().
QAction * QUndoGroup::createUndoAction | ( | QObject * | parent, |
const QString & | prefix = QString() |
||
) | const |
Creates an undo QAction object with parent parent.
Triggering this action will cause a call to QUndoStack::undo() on the active stack. The text of this action will always be the text of the command which will be undone in the next call to undo(), prefixed by prefix. If there is no command available for undo, if the group is empty or if none of the stacks are active, this action will be disabled.
If prefix is empty, the default template "Undo %1" is used instead of prefix. Before Qt 4.8, the prefix "Undo" was used by default.
Definition at line 237 of file qundogroup.cpp.
References canUndo(), canUndoChanged(), QObject::connect(), QString::isEmpty(), QObject::parent(), QAction::setEnabled(), text, tr, QAction::triggered(), undo(), undoText(), and undoTextChanged().
|
signal |
This signal is emitted whenever the active stack emits QUndoStack::indexChanged() or the active stack changes.
idx is the new current index, or 0 if the active stack is 0.
Referenced by setActiveStack().
bool QUndoGroup::isClean | ( | ) | const |
Returns the value of the active stack's QUndoStack::isClean().
If none of the stacks are active, or if the group is empty, this function returns true
.
Definition at line 401 of file qundogroup.cpp.
References d.
|
slot |
Calls QUndoStack::redo() on the active stack.
If none of the stacks are active, or if the group is empty, this function does nothing.
Definition at line 325 of file qundogroup.cpp.
References d.
Referenced by createRedoAction().
QString QUndoGroup::redoText | ( | ) | const |
Returns the value of the active stack's QUndoStack::redoText().
If none of the stacks are active, or if the group is empty, this function returns an empty string.
Definition at line 386 of file qundogroup.cpp.
References d.
Referenced by createRedoAction().
This signal is emitted whenever the active stack emits QUndoStack::redoTextChanged() or the active stack changes.
redoText is the new state, or an empty string if the active stack is 0.
Referenced by createRedoAction(), and setActiveStack().
void QUndoGroup::removeStack | ( | QUndoStack * | stack | ) |
Removes stack from this group.
If the stack was the active stack in the group, the active stack becomes 0.
Definition at line 114 of file qundogroup.cpp.
References d, and setActiveStack().
|
slot |
Sets the active stack of this group to stack.
If the stack is not a member of this group, this function does nothing.
Synonymous with calling QUndoStack::setActive() on stack.
The actions returned by createUndoAction() and createRedoAction() will now behave in the same way as those returned by stack's QUndoStack::createUndoAction() and QUndoStack::createRedoAction().
Definition at line 151 of file qundogroup.cpp.
References activeStackChanged(), canRedoChanged(), canUndoChanged(), cleanChanged(), QObject::connect(), d, disconnect(), emit, indexChanged(), redoTextChanged(), SIGNAL, and undoTextChanged().
Referenced by removeStack().
QList< QUndoStack * > QUndoGroup::stacks | ( | ) | const |
Returns a list of stacks in this group.
Definition at line 131 of file qundogroup.cpp.
References d.
|
slot |
Calls QUndoStack::undo() on the active stack.
If none of the stacks are active, or if the group is empty, this function does nothing.
Definition at line 308 of file qundogroup.cpp.
References d.
Referenced by createUndoAction().
QString QUndoGroup::undoText | ( | ) | const |
Returns the value of the active stack's QUndoStack::undoText().
If none of the stacks are active, or if the group is empty, this function returns an empty string.
Definition at line 371 of file qundogroup.cpp.
References d.
Referenced by createUndoAction().
This signal is emitted whenever the active stack emits QUndoStack::undoTextChanged() or the active stack changes.
undoText is the new state, or an empty string if the active stack is 0.
Referenced by createUndoAction(), and setActiveStack().