QgsPropertyCollectionStack class

An ordered stack of QgsPropertyCollection containers, where collections added later to the stack will take priority over earlier collections.

Base classes

class QgsAbstractPropertyCollection
Abstract base class for QgsPropertyCollection like objects.

Constructors, destructors, conversion operators

QgsPropertyCollectionStack() defaulted
Constructor for QgsPropertyCollectionStack.
QgsPropertyCollectionStack(const QgsPropertyCollectionStack& other)
Copy constructor.

Public functions

void appendCollection(QgsPropertyCollection* collection)
Appends a collection to the end of the stack, and transfers ownership of the collection to the stack.
auto at(int index) -> QgsPropertyCollection*
Returns the collection at the corresponding index from the stack.
auto at(int index) const -> const QgsPropertyCollection*
Returns the collection at the corresponding index from the stack.
void clear() override
Removes all collections from the stack.
auto collection(const QString& name) -> QgsPropertyCollection*
Returns the first collection with a matching name from the stack.
auto count() const -> int
Returns the number of collections contained within the stack.
auto hasActiveProperties() const -> bool override
Returns true if the collection has any active properties, or false if all properties within the collection are deactivated.
auto hasDynamicProperties() const -> bool override
Returns true if the collection has any active, non-static properties, or false if either all non-static properties within the collection are deactivated or if the collection only contains static properties.
auto hasProperty(int key) const -> bool override
Returns true if the collection contains a property with the specified key.
auto isActive(int key) const -> bool override
Returns true if the stack contains an active property with the specified key.
auto loadVariant(const QVariant& configuration, const QgsPropertiesDefinition& definitions) -> bool override
Loads this property collection from a QVariantMap, wrapped in a QVariant.
auto prepare(const QgsExpressionContext& context = QgsExpressionContext()) const -> bool override
Prepares the collection against a specified expression context.
auto property(int key) const -> QgsProperty override
Returns the highest priority property with a matching key from within the stack.
auto propertyKeys() const -> QSet<int> override
Returns a list of property keys contained within the collection.
auto referencedFields(const QgsExpressionContext& context = QgsExpressionContext()) const -> QSet<QString> override
Returns the set of any fields referenced by the active properties from the stack.
auto toVariant(const QgsPropertiesDefinition& definitions) const -> QVariant override
Saves this property collection to a QVariantMap, wrapped in a QVariant.
auto value(int key, const QgsExpressionContext& context, const QVariant& defaultValue = QVariant()) const -> QVariant override
Returns the calculated value of the highest priority property with the specified key from within the stack.

Function documentation

void QgsPropertyCollectionStack::appendCollection(QgsPropertyCollection* collection)

Appends a collection to the end of the stack, and transfers ownership of the collection to the stack.

Parameters
collection collection to append. Ownership is transferred to the stack.

Properties from the newly added collection will take priority over any existing properties with the same name.

QgsPropertyCollection* QgsPropertyCollectionStack::at(int index)

Returns the collection at the corresponding index from the stack.

Parameters
index position of collection, 0 based
Returns collection if one exists at the specified index

const QgsPropertyCollection* QgsPropertyCollectionStack::at(int index) const

Returns the collection at the corresponding index from the stack.

Parameters
index position of collection, 0 based
Returns collection if one exists at the specified index

QgsPropertyCollection* QgsPropertyCollectionStack::collection(const QString& name)

Returns the first collection with a matching name from the stack.

Parameters
name name of collection to find
Returns collection if one exists with the specified name

bool QgsPropertyCollectionStack::hasActiveProperties() const override

Returns true if the collection has any active properties, or false if all properties within the collection are deactivated.

bool QgsPropertyCollectionStack::hasDynamicProperties() const override

Returns true if the collection has any active, non-static properties, or false if either all non-static properties within the collection are deactivated or if the collection only contains static properties.

bool QgsPropertyCollectionStack::hasProperty(int key) const override

Returns true if the collection contains a property with the specified key.

Parameters
key integer key for property. The intended use case is that a context specific enum is cast to int and used for the key value.

bool QgsPropertyCollectionStack::isActive(int key) const override

Returns true if the stack contains an active property with the specified key.

Parameters
key integer key for property to test. The intended use case is that a context specific enum is cast to int and used for the key value.

bool QgsPropertyCollectionStack::loadVariant(const QVariant& configuration, const QgsPropertiesDefinition& definitions) override

Loads this property collection from a QVariantMap, wrapped in a QVariant.

You can use QgsXmlUtils::readVariant to save it to an XML document.

bool QgsPropertyCollectionStack::prepare(const QgsExpressionContext& context = QgsExpressionContext()) const override

Prepares the collection against a specified expression context.

Calling prepare before evaluating the collection's properties multiple times allows precalculation of expensive setup tasks such as parsing expressions. Returns true if preparation was successful.

QgsProperty QgsPropertyCollectionStack::property(int key) const override

Returns the highest priority property with a matching key from within the stack.

Parameters
key integer key for property to return. The intended use case is that a context specific enum is cast to int and used for the key value.
Returns matching property, or null if no matching, active property found.

QSet<QString> QgsPropertyCollectionStack::referencedFields(const QgsExpressionContext& context = QgsExpressionContext()) const override

Returns the set of any fields referenced by the active properties from the stack.

Parameters
context expression context the properties will be evaluated against.

QVariant QgsPropertyCollectionStack::toVariant(const QgsPropertiesDefinition& definitions) const override

Saves this property collection to a QVariantMap, wrapped in a QVariant.

You can use QgsXmlUtils::writeVariant to save it to an XML document.

QVariant QgsPropertyCollectionStack::value(int key, const QgsExpressionContext& context, const QVariant& defaultValue = QVariant()) const override

Returns the calculated value of the highest priority property with the specified key from within the stack.

Parameters
key integer key for property to calculate. The intended use case is that a context specific enum is cast to int and used for the key value.
context expression context to evaluate property against
defaultValue default value to return if no matching, active property found or if the property value cannot be calculated
Returns calculated property value, or default value if property could not be evaluated