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
QUndoGroup Class Reference

The QUndoGroup class is a group of QUndoStack objects. More...

#include <qundogroup.h>

+ Inheritance diagram for QUndoGroup:
+ Collaboration diagram for QUndoGroup:

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.
 
- Public Slots inherited from QObject
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.
 
- Signals inherited from QObject
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.
 
QActioncreateUndoAction (QObject *parent, const QString &prefix=QString()) const
 Creates an undo QAction object with parent parent.
 
QActioncreateRedoAction (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().
 
- Public Member Functions inherited from QObject
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< QStringbindableObjectName ()
 
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).
 
QThreadthread () const
 Returns the thread in which the object lives.
 
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
 
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::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
void killTimer (Qt::TimerId id)
 
template<typename T >
findChild (QAnyStringView aName, 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 (QAnyStringView 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 >
findChild (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.
 
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 QObjectListchildren () 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< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () 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 Public Member Functions inherited from QObject
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)
 
- Protected Member Functions inherited from QObject
QObjectsender () 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)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Detailed Description

The QUndoGroup class is a group of QUndoStack objects.

Since
4.2 \inmodule QtGui

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.

Constructor & Destructor Documentation

◆ QUndoGroup()

QUndoGroup::QUndoGroup ( QObject * parent = nullptr)
explicit

Creates an empty QUndoGroup object with parent parent.

See also
addStack()

Definition at line 65 of file qundogroup.cpp.

◆ ~QUndoGroup()

QUndoGroup::~QUndoGroup ( )

Destroys the QUndoGroup.

Definition at line 73 of file qundogroup.cpp.

References QSet< T >::begin(), d, and it.

+ Here is the call graph for this function:

Member Function Documentation

◆ activeStack()

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.

See also
setActiveStack(), QUndoStack::setActive()

Definition at line 214 of file qundogroup.cpp.

References d.

◆ activeStackChanged

void QUndoGroup::activeStackChanged ( QUndoStack * stack)
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.

See also
setActiveStack(), QUndoStack::setActive()

Referenced by setActiveStack().

+ Here is the caller graph for this function:

◆ addStack()

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.

See also
removeStack(), stacks(), QUndoStack::QUndoStack()

Definition at line 94 of file qundogroup.cpp.

References d, and other().

+ Here is the call graph for this function:

◆ canRedo()

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.

See also
canUndo(), setActiveStack()

Definition at line 356 of file qundogroup.cpp.

References d.

Referenced by createRedoAction().

+ Here is the caller graph for this function:

◆ canRedoChanged

void QUndoGroup::canRedoChanged ( bool canRedo)
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.

See also
QUndoStack::canRedoChanged(), setActiveStack()

Referenced by createRedoAction(), and setActiveStack().

+ Here is the caller graph for this function:

◆ canUndo()

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.

See also
canRedo(), setActiveStack()

Definition at line 341 of file qundogroup.cpp.

References d.

Referenced by createUndoAction().

+ Here is the caller graph for this function:

◆ canUndoChanged

void QUndoGroup::canUndoChanged ( bool canUndo)
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.

See also
QUndoStack::canUndoChanged(), setActiveStack()

Referenced by createUndoAction(), and setActiveStack().

+ Here is the caller graph for this function:

◆ cleanChanged

void QUndoGroup::cleanChanged ( bool clean)
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.

See also
QUndoStack::cleanChanged(), setActiveStack()

Referenced by setActiveStack().

+ Here is the caller graph for this function:

◆ createRedoAction()

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.

See also
createUndoAction(), canRedo(), QUndoCommand::text()

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().

+ Here is the call graph for this function:

◆ createUndoAction()

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.

See also
createRedoAction(), canUndo(), QUndoCommand::text()

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().

+ Here is the call graph for this function:

◆ indexChanged

void QUndoGroup::indexChanged ( int idx)
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.

See also
QUndoStack::indexChanged(), setActiveStack()

Referenced by setActiveStack().

+ Here is the caller graph for this function:

◆ isClean()

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.

See also
setActiveStack()

Definition at line 401 of file qundogroup.cpp.

References d.

◆ redo

void QUndoGroup::redo ( )
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.

See also
undo(), canRedo(), setActiveStack()

Definition at line 325 of file qundogroup.cpp.

References d.

Referenced by createRedoAction().

+ Here is the caller graph for this function:

◆ redoText()

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.

See also
undoText(), setActiveStack()

Definition at line 386 of file qundogroup.cpp.

References d.

Referenced by createRedoAction().

+ Here is the caller graph for this function:

◆ redoTextChanged

void QUndoGroup::redoTextChanged ( const QString & redoText)
signal

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.

See also
QUndoStack::redoTextChanged(), setActiveStack()

Referenced by createRedoAction(), and setActiveStack().

+ Here is the caller graph for this function:

◆ removeStack()

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.

See also
addStack(), stacks(), QUndoStack::~QUndoStack()

Definition at line 114 of file qundogroup.cpp.

References d, and setActiveStack().

+ Here is the call graph for this function:

◆ setActiveStack

void QUndoGroup::setActiveStack ( QUndoStack * stack)
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().

See also
QUndoStack::setActive(), activeStack()

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ stacks()

QList< QUndoStack * > QUndoGroup::stacks ( ) const

Returns a list of stacks in this group.

See also
addStack(), removeStack()

Definition at line 131 of file qundogroup.cpp.

References d.

◆ undo

void QUndoGroup::undo ( )
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.

See also
redo(), canUndo(), setActiveStack()

Definition at line 308 of file qundogroup.cpp.

References d.

Referenced by createUndoAction().

+ Here is the caller graph for this function:

◆ undoText()

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.

See also
redoText(), setActiveStack()

Definition at line 371 of file qundogroup.cpp.

References d.

Referenced by createUndoAction().

+ Here is the caller graph for this function:

◆ undoTextChanged

void QUndoGroup::undoTextChanged ( const QString & undoText)
signal

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.

See also
QUndoStack::undoTextChanged(), setActiveStack()

Referenced by createUndoAction(), and setActiveStack().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: