Class: QgsLayoutUndoStack

An undo stack for QgsLayouts.

Class Hierarchy

Inheritance diagram of qgis.core.QgsLayoutUndoStack

Base classes

QObject

class qgis.core.QgsLayoutUndoStack[source]

Bases: QObject

__init__(layout: QgsLayout | None)

Constructor for QgsLayoutUndoStack, for the specified parent layout.

Parameters:

layout (Optional[QgsLayout])

beginCommand(self, object: QgsLayoutUndoObjectInterface | None, commandText: str | None, id: int = 0)[source]

Begins a new undo command for the specified object.

This must be followed by a call to endCommand() or cancelCommand() after the desired changes have been made to object.

The id argument can be used to specify an id number for the source event - this is used to determine whether QUndoCommand command compression can apply to the command.

See also

endCommand()

See also

cancelCommand()

Parameters:
beginMacro(self, commandText: str | None)[source]

Starts a macro command, with the given descriptive commandText.

Any commands added to the stack (either via direct manipulation of stack() or via beginCommand()/endCommand() calls) between a beginMacro() and endMacro() block are collapsed into a single undo command, which will be applied or rolled back in a single step.

See also

endMacro()

Parameters:

commandText (Optional[str])

blockCommands(self, blocked: bool)[source]

Sets whether undo commands for the layout should be temporarily blocked.

If blocked is True, subsequent undo commands will be blocked until a follow-up call to blockCommands( False ) is made.

Note that calls to blockCommands are stacked, so two calls blocking the commands will take two calls unblocking commands in order to release the block.

See also

isBlocked()

Parameters:

blocked (bool)

cancelCommand(self)[source]

Cancels the active command, discarding it without pushing to the undo history.

See also

endCommand()

See also

cancelCommand()

endCommand(self)[source]

Saves final state of an object and pushes the active command to the undo history.

See also

beginCommand()

See also

cancelCommand()

endMacro(self)[source]

Ends a macro command. This must be called after beginMacro(), when all child undo commands which form part of the macro have been completed.

Any commands added to the stack (either via direct manipulation of stack() or via beginCommand()/endCommand() calls) between a beginMacro() and endMacro() block are collapsed into a single undo command, which will be applied or rolled back in a single step.

See also

beginMacro()

isBlocked(self) bool[source]

Returns True if undo commands are currently blocked.

See also

blockCommands()

Return type:

bool

notifyUndoRedoOccurred(self, item: QgsLayoutItem | None)[source]

Notifies the stack that an undo or redo action occurred for a specified item.

Parameters:

item (Optional[QgsLayoutItem])

push(self, command: QUndoCommand | None)[source]

Manually pushes a command to the stack, and takes ownership of the command.

Parameters:

command (Optional[QUndoCommand])

stack(self) QUndoStack | None[source]

Returns a pointer to the internal QUndoStack.

Return type:

Optional[QUndoStack]

signal undoRedoOccurredForItems[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.