Class: QgsLayoutManager

Manages storage of a set of layouts.

QgsLayoutManager handles the storage, serializing and deserializing of print layouts and reports. Usually this class is not constructed directly, but rather accessed through a QgsProject via QgsProject.layoutManager().

QgsLayoutManager retains ownership of all the layouts contained in the manager.

Class Hierarchy

Inheritance diagram of qgis.core.QgsLayoutManager

Base classes

QObject

Methods

accept

Accepts the specified style entity visitor, causing it to visit all style entities associated within the contained layouts.

addLayout

Adds a layout to the manager.

clear

Removes and deletes all layouts from the manager.

duplicateLayout

Duplicates an existing layout from the manager.

generateUniqueTitle

Generates a unique title for a new layout of the specified type, which does not clash with any already contained by the manager.

layoutByName

Returns the layout with a matching name, or None if no matching layouts were found.

layouts

Returns a list of all layouts contained in the manager.

printLayouts

Returns a list of all print layouts contained in the manager.

readXml

Reads the manager's state from a DOM element, restoring all layouts present in the XML document.

removeLayout

Removes a layout from the manager.

writeXml

Returns a DOM element representing the state of the manager.

Signals

layoutAboutToBeAdded

Emitted when a layout is about to be added to the manager

layoutAboutToBeRemoved

Emitted when a layout is about to be removed from the manager

layoutAdded

Emitted when a layout has been added to the manager

layoutRemoved

Emitted when a layout was removed from the manager

layoutRenamed

Emitted when a layout is renamed

class qgis.core.QgsLayoutManager[source]

Bases: QObject

__init__(project: QgsProject | None = None)

Constructor for QgsLayoutManager. The project will become the parent object for this manager.

Parameters:

project (Optional[QgsProject] = None)

accept(self, visitor: QgsStyleEntityVisitorInterface | None) bool[source]

Accepts the specified style entity visitor, causing it to visit all style entities associated within the contained layouts.

Returns True if the visitor should continue visiting other objects, or False if visiting should be canceled.

Added in version 3.10.

Parameters:

visitor (Optional[QgsStyleEntityVisitorInterface])

Return type:

bool

addLayout(self, layout: QgsMasterLayoutInterface | None) bool[source]

Adds a layout to the manager. Ownership of the layout is transferred to the manager. Returns True if the addition was successful, or False if the layout could not be added (eg as a result of a duplicate layout name).

See also

removeLayout()

See also

layoutAdded()

Parameters:

layout (Optional[QgsMasterLayoutInterface])

Return type:

bool

clear(self)[source]

Removes and deletes all layouts from the manager.

See also

removeLayout()

duplicateLayout(self, layout: QgsMasterLayoutInterface | None, newName: str | None) QgsMasterLayoutInterface | None[source]

Duplicates an existing layout from the manager. The new layout will automatically be stored in the manager. Returns the new layout if duplication was successful.

Parameters:
Return type:

Optional[QgsMasterLayoutInterface]

generateUniqueTitle(self, type: QgsMasterLayoutInterface.Type = QgsMasterLayoutInterface.PrintLayout) str[source]

Generates a unique title for a new layout of the specified type, which does not clash with any already contained by the manager.

Parameters:

type (QgsMasterLayoutInterface.Type = QgsMasterLayoutInterface.PrintLayout)

Return type:

str

signal layoutAboutToBeAdded(name: str)[source]

Emitted when a layout is about to be added to the manager

Parameters:

name (str)

signal layoutAboutToBeRemoved(name: str)[source]

Emitted when a layout is about to be removed from the manager

Parameters:

name (str)

signal layoutAdded(name: str)[source]

Emitted when a layout has been added to the manager

Parameters:

name (str)

layoutByName(self, name: str | None) QgsMasterLayoutInterface | None[source]

Returns the layout with a matching name, or None if no matching layouts were found.

Parameters:

name (Optional[str])

Return type:

Optional[QgsMasterLayoutInterface]

signal layoutRemoved(name: str)[source]

Emitted when a layout was removed from the manager

Parameters:

name (str)

signal layoutRenamed(layout: QgsMasterLayoutInterface, newName: str)[source]

Emitted when a layout is renamed

Parameters:
layouts(self) List[QgsMasterLayoutInterface]

Returns a list of all layouts contained in the manager.

Return type:

List[QgsMasterLayoutInterface]

printLayouts(self) List[QgsPrintLayout]

Returns a list of all print layouts contained in the manager.

Return type:

List[QgsPrintLayout]

readXml(self, element: QDomElement, doc: QDomDocument) bool[source]

Reads the manager’s state from a DOM element, restoring all layouts present in the XML document.

See also

writeXml()

Parameters:
  • element (QDomElement)

  • doc (QDomDocument)

Return type:

bool

removeLayout(self, layout: QgsMasterLayoutInterface | None) bool[source]

Removes a layout from the manager. The layout is deleted. Returns True if the removal was successful, or False if the removal failed (eg as a result of removing a layout which is not contained in the manager).

See also

addLayout()

See also

layoutRemoved()

See also

clear()

Parameters:

layout (Optional[QgsMasterLayoutInterface])

Return type:

bool

writeXml(self, doc: QDomDocument) QDomElement[source]

Returns a DOM element representing the state of the manager.

See also

readXml()

Parameters:

doc (QDomDocument)

Return type:

QDomElement