QgsPropertyOverrideButton class

A button for controlling property overrides which may apply to a widget.

QgsPropertyOverrideButton is designed to be used alongside the QGIS properties framework (QgsProperty, QgsPropertyDefinition and QgsPropertyCollection).

It allows users to specify field or expression based overrides which should be applied to a property of an object. Eg, this widget is used for controlling data defined overrides in symbology, labeling and layouts.

Public types

enum Flag { FlagDisableCheckedWidgetOnlyWhenProjectColorSet = 1 << 1 }
Flags controlling button behavior.

Constructors, destructors, conversion operators

QgsPropertyOverrideButton(QWidget* parent = nullptr, const QgsVectorLayer* layer = nullptr)
Constructor for QgsPropertyOverrideButton.

Public functions

auto flags() const -> Flags
Returns the button's flags, which control the button behavior.
auto fullDescription() const -> QString
Returns the full definition description and current definition (internally generated on a contextual basis).
void init(int propertyKey, const QgsProperty& property, const QgsPropertiesDefinition& definitions, const QgsVectorLayer* layer = nullptr, bool auxiliaryStorageEnabled = false)
Initialize a newly constructed property button (useful if button was included in a UI layout).
void init(int propertyKey, const QgsProperty& property, const QgsPropertyDefinition& definition, const QgsVectorLayer* layer = nullptr, bool auxiliaryStorageEnabled = false)
Initialize a newly constructed property button (useful if button was included in a UI layout).
void init(int propertyKey, const QgsAbstractPropertyCollection& collection, const QgsPropertiesDefinition& definitions, const QgsVectorLayer* layer = nullptr, bool auxiliaryStorageEnabled = false)
Initialize a newly constructed property button (useful if button was included in a UI layout).
auto isActive() const -> bool
Returns true if the button has an active property.
auto propertyKey() const -> int
Returns the property key linked to the button.
void registerCheckedWidget(QWidget* widget, bool natural = true)
Register a sibling widget that gets checked when the property is active.
void registerEnabledWidget(QWidget* widget, bool natural = true)
Register a sibling widget that gets enabled when the property is active, and disabled when the property is inactive.
void registerExpressionContextGenerator(QgsExpressionContextGenerator* generator)
Register an expression context generator class that will be used to retrieve an expression context for the button when required.
void registerExpressionWidget(QWidget* widget)
Register a sibling widget (line edit, text edit) that will receive the property as an expression.
void registerVisibleWidget(QWidget* widget, bool natural = true)
Register a sibling widget that gets visible when the property is active, and hidden when the property is inactive.
void setFlags(QgsPropertyOverrideButton::Flags flags)
Sets the button's flags, which control the button behavior.
void setSymbol(std::shared_ptr<QgsSymbol> symbol)
Sets a symbol which can be used for previews inside the widget or in any dialog created by the widget.
void setToProperty(const QgsProperty& property)
Sets the widget to reflect the current state of a QgsProperty.
void setUsageInfo(const QString& info)
Set the usage information for the property.
void setVectorLayer(const QgsVectorLayer* layer)
Sets the vector layer associated with the button.
auto toProperty() const -> QgsProperty
Returns a QgsProperty object encapsulating the current state of the widget.
void updateFieldLists()
Updates list of fields.
auto usageInfo() const -> QString
Returns usage information for the property.
auto validDataType() const -> QgsPropertyDefinition::DataType
Returns the data type which the widget will accept.
auto vectorLayer() const -> const QgsVectorLayer*
Returns the vector layer associated with the button.

Signals

void activated(bool isActive)
Emitted when the activated status of the widget changes.
void changed()
Emitted when property definition changes.
void createAuxiliaryField()
Emitted when creating a new auxiliary field.

Public slots

void setActive(bool active)
Set whether the current property override definition is to be used.

Enum documentation

enum QgsPropertyOverrideButton::Flag

Flags controlling button behavior.

Enumerators
FlagDisableCheckedWidgetOnlyWhenProjectColorSet

Indicates that registered widgets will only be disabled when the property is set to follow a project color.

Function documentation

QgsPropertyOverrideButton::QgsPropertyOverrideButton(QWidget* parent = nullptr, const QgsVectorLayer* layer = nullptr)

Constructor for QgsPropertyOverrideButton.

Parameters
parent parent widget
layer associated vector layer

Flags QgsPropertyOverrideButton::flags() const

Returns the button's flags, which control the button behavior.

void QgsPropertyOverrideButton::init(int propertyKey, const QgsProperty& property, const QgsPropertiesDefinition& definitions, const QgsVectorLayer* layer = nullptr, bool auxiliaryStorageEnabled = false)

Initialize a newly constructed property button (useful if button was included in a UI layout).

Parameters
propertyKey key for corresponding property
property initial value of associated property to show in widget
definitions properties definitions for corresponding collection
layer associated vector layer
auxiliaryStorageEnabled If true, activate the button to store data defined in auxiliary storage

void QgsPropertyOverrideButton::init(int propertyKey, const QgsProperty& property, const QgsPropertyDefinition& definition, const QgsVectorLayer* layer = nullptr, bool auxiliaryStorageEnabled = false)

Initialize a newly constructed property button (useful if button was included in a UI layout).

Parameters
propertyKey key for corresponding property
property initial value of associated property to show in widget
definition properties definition for button
layer associated vector layer
auxiliaryStorageEnabled If true, activate the button to store data defined in auxiliary storage

void QgsPropertyOverrideButton::init(int propertyKey, const QgsAbstractPropertyCollection& collection, const QgsPropertiesDefinition& definitions, const QgsVectorLayer* layer = nullptr, bool auxiliaryStorageEnabled = false)

Initialize a newly constructed property button (useful if button was included in a UI layout).

Parameters
propertyKey key for corresponding property
collection associated property collection
definitions properties definitions for collection
layer associated vector layer
auxiliaryStorageEnabled If true, activate the button to store data defined in auxiliary storage

void QgsPropertyOverrideButton::registerCheckedWidget(QWidget* widget, bool natural = true)

Register a sibling widget that gets checked when the property is active.

if natural is false, widget gets unchecked when the property is active.

void QgsPropertyOverrideButton::registerEnabledWidget(QWidget* widget, bool natural = true)

Register a sibling widget that gets enabled when the property is active, and disabled when the property is inactive.

if natural is false, widget gets disabled when the property is active, and enabled when the property is inactive.

void QgsPropertyOverrideButton::registerExpressionWidget(QWidget* widget)

Register a sibling widget (line edit, text edit) that will receive the property as an expression.

void QgsPropertyOverrideButton::registerVisibleWidget(QWidget* widget, bool natural = true)

Register a sibling widget that gets visible when the property is active, and hidden when the property is inactive.

if natural is false, widget gets hidden when the property is active, and visible when the property is inactive.

void QgsPropertyOverrideButton::setFlags(QgsPropertyOverrideButton::Flags flags)

Sets the button's flags, which control the button behavior.

void QgsPropertyOverrideButton::setSymbol(std::shared_ptr<QgsSymbol> symbol)

Sets a symbol which can be used for previews inside the widget or in any dialog created by the widget.

If not specified, a default created symbol will be used instead.

void QgsPropertyOverrideButton::setUsageInfo(const QString& info)

Set the usage information for the property.

void QgsPropertyOverrideButton::setVectorLayer(const QgsVectorLayer* layer)

Sets the vector layer associated with the button.

This controls which fields are displayed within the widget's pop up menu.

QgsProperty QgsPropertyOverrideButton::toProperty() const

Returns a QgsProperty object encapsulating the current state of the widget.

void QgsPropertyOverrideButton::updateFieldLists()

Updates list of fields.

QString QgsPropertyOverrideButton::usageInfo() const

Returns usage information for the property.

QgsPropertyDefinition::DataType QgsPropertyOverrideButton::validDataType() const

Returns the data type which the widget will accept.

This is used to filter out fields from the associated vector layer to only show fields which are compatible with the property.

const QgsVectorLayer* QgsPropertyOverrideButton::vectorLayer() const

Returns the vector layer associated with the button.

This controls which fields are displayed within the widget's pop up menu.