QgsLayoutGuideCollection class

Stores and manages the snap guides used by a layout.

Base classes

class QgsLayoutSerializableObject
An interface for layout objects which can be stored and read from DOM elements.

Public types

enum Roles { OrientationRole = Qt::UserRole, PositionRole, UnitsRole, PageRole, LayoutPositionRole }
Model roles.

Constructors, destructors, conversion operators

QgsLayoutGuideCollection(QgsLayout* layout, QgsLayoutPageCollection* pageCollection)
Constructor for QgsLayoutGuideCollection belonging to the specified layout, and linked to the specified pageCollection.

Public functions

void addGuide(QgsLayoutGuide* guide)
Adds a guide to the collection.
void applyGuidesToAllOtherPages(int sourcePage)
Resets all other pages' guides to match the guides from the specified sourcePage.
void clear()
Removes all guides from the collection.
auto guides() -> QList<QgsLayoutGuide*>
Returns a list of all guides contained in the collection.
auto guides(Qt::Orientation orientation, int page = -1) -> QList<QgsLayoutGuide*>
Returns the list of guides contained in the collection with the specified orientation and on a matching page.
auto guidesOnPage(int page) -> QList<QgsLayoutGuide*>
Returns the list of guides contained on a matching page.
auto layout() -> QgsLayout* override
Returns the layout the object belongs to.
auto readXml(const QDomElement& collectionElement, const QDomDocument& document, const QgsReadWriteContext& context) -> bool override
Sets the collection's state from a DOM element.
void removeGuide(QgsLayoutGuide* guide)
Removes the specified guide, and deletes it.
void setGuideLayoutPosition(QgsLayoutGuide* guide, double position)
Sets the absolute position (in layout coordinates) for guide within the layout.
void setVisible(bool visible)
Sets whether the guide lines should be visible.
auto stringType() const -> QString override
Returns the object type as a string.
void update()
Updates the position (and visibility) of all guide line items.
auto visible() const -> bool
Returns true if the guide lines should be drawn.
auto writeXml(QDomElement& parentElement, QDomDocument& document, const QgsReadWriteContext& context) const -> bool override
Stores the collection's state in a DOM element.

Enum documentation

enum QgsLayoutGuideCollection::Roles

Model roles.

Enumerators
OrientationRole

Guide orientation role.

PositionRole

Guide position role.

UnitsRole

Guide position units role.

PageRole

Guide page role.

LayoutPositionRole

Guide position in layout coordinates.

Function documentation

void QgsLayoutGuideCollection::addGuide(QgsLayoutGuide* guide)

Adds a guide to the collection.

Ownership of the guide is transferred to the collection, and the guide will automatically have the correct layout set.

void QgsLayoutGuideCollection::clear()

Removes all guides from the collection.

QList<QgsLayoutGuide*> QgsLayoutGuideCollection::guides(Qt::Orientation orientation, int page = -1)

Returns the list of guides contained in the collection with the specified orientation and on a matching page.

If page is -1, guides from all pages will be returned.

QList<QgsLayoutGuide*> QgsLayoutGuideCollection::guidesOnPage(int page)

Returns the list of guides contained on a matching page.

bool QgsLayoutGuideCollection::readXml(const QDomElement& collectionElement, const QDomDocument& document, const QgsReadWriteContext& context) override

Sets the collection's state from a DOM element.

collectionElement is the DOM node corresponding to the collection.

void QgsLayoutGuideCollection::removeGuide(QgsLayoutGuide* guide)

Removes the specified guide, and deletes it.

void QgsLayoutGuideCollection::setVisible(bool visible)

Sets whether the guide lines should be visible.

QString QgsLayoutGuideCollection::stringType() const override

Returns the object type as a string.

This string must be a unique, single word, character only representation of the item type, eg "LayoutScaleBar"

bool QgsLayoutGuideCollection::visible() const

Returns true if the guide lines should be drawn.

bool QgsLayoutGuideCollection::writeXml(QDomElement& parentElement, QDomDocument& document, const QgsReadWriteContext& context) const override

Stores the collection's state in a DOM element.

The parentElement should refer to the parent layout's DOM element.