QgsLayoutManager class

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.

Constructors, destructors, conversion operators

QgsLayoutManager(QgsProject* project = nullptr) explicit
Constructor for QgsLayoutManager.

Public functions

auto addLayout(QgsMasterLayoutInterface* layout) -> bool
Adds a layout to the manager.
void clear()
Removes and deletes all layouts from the manager.
auto duplicateLayout(const QgsMasterLayoutInterface* layout, const QString& newName) -> QgsMasterLayoutInterface*
Duplicates an existing layout from the manager.
auto generateUniqueTitle(QgsMasterLayoutInterface::Type type = QgsMasterLayoutInterface::PrintLayout) const -> QString
Generates a unique title for a new layout of the specified type, which does not clash with any already contained by the manager.
auto layoutByName(const QString& name) const -> QgsMasterLayoutInterface*
Returns the layout with a matching name, or nullptr if no matching layouts were found.
auto layouts() const -> QList<QgsMasterLayoutInterface*>
Returns a list of all layouts contained in the manager.
auto printLayouts() const -> QList<QgsPrintLayout*>
Returns a list of all print layouts contained in the manager.
auto readXml(const QDomElement& element, const QDomDocument& doc) -> bool
Reads the manager's state from a DOM element, restoring all layouts present in the XML document.
auto removeLayout(QgsMasterLayoutInterface* layout) -> bool
Removes a layout from the manager.
auto writeXml(QDomDocument& doc) const -> QDomElement
Returns a DOM element representing the state of the manager.

Signals

void layoutAboutToBeAdded(const QString& name)
Emitted when a layout is about to be added to the manager.
void layoutAboutToBeRemoved(const QString& name)
Emitted when a layout is about to be removed from the manager.
void layoutAdded(const QString& name)
Emitted when a layout has been added to the manager.
void layoutRemoved(const QString& name)
Emitted when a layout was removed from the manager.
void layoutRenamed(QgsMasterLayoutInterface* layout, const QString& newName)
Emitted when a layout is renamed.

Function documentation

QgsLayoutManager::QgsLayoutManager(QgsProject* project = nullptr) explicit

Constructor for QgsLayoutManager.

The project will become the parent object for this manager.

bool QgsLayoutManager::addLayout(QgsMasterLayoutInterface* layout)

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

void QgsLayoutManager::clear()

Removes and deletes all layouts from the manager.

QgsMasterLayoutInterface* QgsLayoutManager::duplicateLayout(const QgsMasterLayoutInterface* layout, const QString& newName)

Duplicates an existing layout from the manager.

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

bool QgsLayoutManager::readXml(const QDomElement& element, const QDomDocument& doc)

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

bool QgsLayoutManager::removeLayout(QgsMasterLayoutInterface* layout)

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

QDomElement QgsLayoutManager::writeXml(QDomDocument& doc) const

Returns a DOM element representing the state of the manager.