QgsLayoutObject class

A base class for objects which belong to a layout.

Base classes

class QgsExpressionContextGenerator
Abstract interface for generating an expression context.

Derived classes

class QgsLayoutItem
Base class for graphical items within a QgsLayout.
class QgsLayoutItemMapItem
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
class QgsLayoutMultiFrame
Abstract base class for layout items with the ability to distribute the content to several frames (QgsLayoutFrame items).

Public types

enum DataDefinedProperty { NoProperty = 0, AllProperties, TestProperty, PresetPaperSize, PaperWidth, PaperHeight, NumPages, PaperOrientation, PageNumber, PositionX, PositionY, ItemWidth, ItemHeight, ItemRotation, Transparency, Opacity, BlendMode, ExcludeFromExports, FrameColor, BackgroundColor, MapRotation, MapScale, MapXMin, MapYMin, MapXMax, MapYMax, MapAtlasMargin, MapLayers, MapStylePreset, MapLabelMargin, PictureSource, PictureSvgBackgroundColor, PictureSvgStrokeColor, PictureSvgStrokeWidth, SourceUrl, LegendTitle, LegendColumnCount, ScalebarFillColor, ScalebarFillColor2, ScalebarLineColor, ScalebarLineWidth, AttributeTableSourceLayer }
Data defined properties for different item types.
enum PropertyValueType { EvaluatedValue = 0, OriginalValue }
Specifies whether the value returned by a function should be the original, user set value, or the current evaluated value for the property.

Public static functions

static auto propertyDefinitions() -> const QgsPropertiesDefinition&
Returns the layout object property definitions.

Constructors, destructors, conversion operators

QgsLayoutObject(QgsLayout* layout) explicit
Constructor for QgsLayoutObject, with the specified parent layout.

Public functions

auto createExpressionContext() const -> QgsExpressionContext override
Creates an expression context relating to the objects' current state.
auto customProperties() const -> QStringList
Returns list of keys stored in custom properties for the object.
auto customProperty(const QString& key, const QVariant& defaultValue = QVariant()) const -> QVariant
Read a custom property from the object.
auto dataDefinedProperties() -> QgsPropertyCollection&
Returns a reference to the object's property collection, used for data defined overrides.
auto dataDefinedProperties() const -> const QgsPropertyCollection&
Returns a reference to the object's property collection, used for data defined overrides.
auto layout() const -> const QgsLayout*
Returns the layout the object is attached to.
auto layout() -> QgsLayout*
Returns the layout the object is attached to.
void removeCustomProperty(const QString& key)
Remove a custom property from the object.
void setCustomProperty(const QString& key, const QVariant& value)
Set a custom property for the object.
void setDataDefinedProperties(const QgsPropertyCollection& collection)
Sets the objects's property collection, used for data defined overrides.

Signals

void changed()
Emitted when the object's properties change.

Public slots

void refresh() virtual
Refreshes the object, causing a recalculation of any property overrides.

Protected functions

auto readObjectPropertiesFromElement(const QDomElement& parentElement, const QDomDocument& document, const QgsReadWriteContext& context) -> bool
Sets object properties from a DOM element.
auto writeObjectPropertiesToElement(QDomElement& parentElement, QDomDocument& document, const QgsReadWriteContext& context) const -> bool
Stores object properties within an XML DOM element.

Protected variables

QgsObjectCustomProperties mCustomProperties
Custom properties for object.

Enum documentation

enum QgsLayoutObject::DataDefinedProperty

Data defined properties for different item types.

Enumerators
NoProperty

No property.

AllProperties

All properties for item.

TestProperty

Dummy property with no effect on item.

PresetPaperSize

Preset paper size for composition.

PaperWidth

Paper width (deprecated)

PaperHeight

Paper height (deprecated)

NumPages

Number of pages in composition (deprecated)

PaperOrientation

Paper orientation.

PageNumber

Page number for item placement.

PositionX

X position on page.

PositionY

Y position on page.

ItemWidth

Width of item.

ItemHeight

Height of item.

ItemRotation

Rotation of item.

Transparency

Item transparency (deprecated)

Opacity

Item opacity.

BlendMode

Item blend mode.

ExcludeFromExports

Exclude item from exports.

FrameColor

Item frame color.

BackgroundColor

Item background color.

MapRotation

Map rotation.

MapScale

Map scale.

MapXMin

Map extent x minimum.

MapYMin

Map extent y minimum.

MapXMax

Map extent x maximum.

MapYMax

Map extent y maximum.

MapAtlasMargin

Map atlas margin.

MapLayers

Map layer set.

MapStylePreset

Layer and style map theme.

MapLabelMargin

Map label margin.

PictureSource

Picture source url.

PictureSvgBackgroundColor

SVG background color.

PictureSvgStrokeColor

SVG stroke color.

PictureSvgStrokeWidth

SVG stroke width.

SourceUrl

Html source url.

LegendTitle

Legend title.

LegendColumnCount

Legend column count.

ScalebarFillColor

Scalebar fill color.

ScalebarFillColor2

Scalebar secondary fill color.

ScalebarLineColor

Scalebar line color.

ScalebarLineWidth

Scalebar line width,.

AttributeTableSourceLayer

Attribute table source layer.

enum QgsLayoutObject::PropertyValueType

Specifies whether the value returned by a function should be the original, user set value, or the current evaluated value for the property.

This may differ if a property has a data defined expression active.

Enumerators
EvaluatedValue

Return the current evaluated value for the property.

OriginalValue

Return the original, user set value.

Function documentation

QgsLayoutObject::QgsLayoutObject(QgsLayout* layout) explicit

Constructor for QgsLayoutObject, with the specified parent layout.

QgsExpressionContext QgsLayoutObject::createExpressionContext() const override

Creates an expression context relating to the objects' current state.

The context includes scopes for global, project and layout properties.

QStringList QgsLayoutObject::customProperties() const

Returns list of keys stored in custom properties for the object.

QVariant QgsLayoutObject::customProperty(const QString& key, const QVariant& defaultValue = QVariant()) const

Read a custom property from the object.

Parameters
key property key
defaultValue default value to return if property with matching key does not exist
Returns value of matching property

QgsPropertyCollection& QgsLayoutObject::dataDefinedProperties()

Returns a reference to the object's property collection, used for data defined overrides.

const QgsPropertyCollection& QgsLayoutObject::dataDefinedProperties() const

Returns a reference to the object's property collection, used for data defined overrides.

void QgsLayoutObject::removeCustomProperty(const QString& key)

Remove a custom property from the object.

Parameters
key property key

void QgsLayoutObject::setCustomProperty(const QString& key, const QVariant& value)

Set a custom property for the object.

Parameters
key property key. If a property with the same key already exists it will be overwritten.
value property value

void QgsLayoutObject::setDataDefinedProperties(const QgsPropertyCollection& collection)

Sets the objects's property collection, used for data defined overrides.

Parameters
collection property collection. Existing properties will be replaced.

bool QgsLayoutObject::readObjectPropertiesFromElement(const QDomElement& parentElement, const QDomDocument& document, const QgsReadWriteContext& context) protected

Sets object properties from a DOM element.

Parameters
parentElement is the parent DOM element for the object
document DOM document
context read write context
Returns true if read was successful

bool QgsLayoutObject::writeObjectPropertiesToElement(QDomElement& parentElement, QDomDocument& document, const QgsReadWriteContext& context) const protected

Stores object properties within an XML DOM element.

Parameters
parentElement is the parent DOM element to store the object's properties in
document DOM document
context read write context
Returns true if write was successful