QgsAbstractPropertyCollection class

Abstract base class for QgsPropertyCollection like objects.

Derived classes

class QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
class QgsPropertyCollectionStack
An ordered stack of QgsPropertyCollection containers, where collections added later to the stack will take priority over earlier collections.

Constructors, destructors, conversion operators

QgsAbstractPropertyCollection(const QString& name = QString())
Constructor for QgsAbstractPropertyCollection.

Public functions

void clear() pure virtual
Removes all properties from the collection.
auto hasActiveProperties() const -> bool pure virtual
Returns true if the collection has any active properties, or false if all properties within the collection are deactivated.
auto hasDynamicProperties() const -> bool pure virtual
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 pure virtual
Returns true if the collection contains a property with the specified key.
auto isActive(int key) const -> bool pure virtual
Returns true if the collection contains an active property with the specified key.
auto loadVariant(const QVariant& configuration, const QgsPropertiesDefinition& definitions) -> bool pure virtual
Loads this property collection from a QVariantMap, wrapped in a QVariant.
auto name() const -> QString
Returns the descriptive name of the property collection.
auto prepare(const QgsExpressionContext& context = QgsExpressionContext()) const -> bool pure virtual
Prepares the collection against a specified expression context.
auto property(int key) const -> QgsProperty pure virtual
Returns a matching property from the collection, if one exists.
auto propertyKeys() const -> QSet<int> pure virtual
Returns a list of property keys contained within the collection.
auto readXml(const QDomElement& collectionElem, const QgsPropertiesDefinition& definitions) -> bool virtual
Reads property collection state from an XML element.
auto referencedFields(const QgsExpressionContext& context = QgsExpressionContext()) const -> QSet<QString> pure virtual
Returns the set of any fields referenced by the active properties from the collection.
void setName(const QString& name)
Sets the descriptive name for the property collection.
auto toVariant(const QgsPropertiesDefinition& definitions) const -> QVariant pure virtual
Saves this property collection to a QVariantMap, wrapped in a QVariant.
auto value(int key, const QgsExpressionContext& context, const QVariant& defaultValue = QVariant()) const -> QVariant pure virtual
Returns the calculated value of the property with the specified key from within the collection.
auto valueAsBool(int key, const QgsExpressionContext& context, bool defaultValue = false, bool* ok = nullptr) const -> bool
Calculates the current value of the property with the specified key and interprets it as an boolean.
auto valueAsColor(int key, const QgsExpressionContext& context, const QColor& defaultColor = QColor(), bool* ok = nullptr) const -> QColor
Calculates the current value of the property with the specified key and interprets it as a color.
auto valueAsDouble(int key, const QgsExpressionContext& context, double defaultValue = 0.0, bool* ok = nullptr) const -> double
Calculates the current value of the property with the specified key and interprets it as a double.
auto valueAsInt(int key, const QgsExpressionContext& context, int defaultValue = 0, bool* ok = nullptr) const -> int
Calculates the current value of the property with the specified key and interprets it as an integer.
auto valueAsString(int key, const QgsExpressionContext& context, const QString& defaultString = QString(), bool* ok = nullptr) const -> QString
Calculates the current value of the property with the specified key and interprets it as a string.
auto writeXml(QDomElement& collectionElem, const QgsPropertiesDefinition& definitions) const -> bool virtual
Writes the current state of the property collection into an XML element.

Function documentation

QgsAbstractPropertyCollection::QgsAbstractPropertyCollection(const QString& name = QString())

Constructor for QgsAbstractPropertyCollection.

The name parameter should be set to a descriptive name for the collection.

bool QgsAbstractPropertyCollection::hasActiveProperties() const pure virtual

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

bool QgsAbstractPropertyCollection::hasDynamicProperties() const pure virtual

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 QgsAbstractPropertyCollection::hasProperty(int key) const pure virtual

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 QgsAbstractPropertyCollection::isActive(int key) const pure virtual

Returns true if the collection 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 QgsAbstractPropertyCollection::loadVariant(const QVariant& configuration, const QgsPropertiesDefinition& definitions) pure virtual

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

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

QString QgsAbstractPropertyCollection::name() const

Returns the descriptive name of the property collection.

bool QgsAbstractPropertyCollection::prepare(const QgsExpressionContext& context = QgsExpressionContext()) const pure virtual

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 QgsAbstractPropertyCollection::property(int key) const pure virtual

Returns a matching property from the collection, if one exists.

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.

bool QgsAbstractPropertyCollection::readXml(const QDomElement& collectionElem, const QgsPropertiesDefinition& definitions) virtual

Reads property collection state from an XML element.

Parameters
collectionElem source DOM element for property collection's state
definitions property definitions

QSet<QString> QgsAbstractPropertyCollection::referencedFields(const QgsExpressionContext& context = QgsExpressionContext()) const pure virtual

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

Parameters
context expression context the properties will be evaluated against.

void QgsAbstractPropertyCollection::setName(const QString& name)

Sets the descriptive name for the property collection.

QVariant QgsAbstractPropertyCollection::toVariant(const QgsPropertiesDefinition& definitions) const pure virtual

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

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

QVariant QgsAbstractPropertyCollection::value(int key, const QgsExpressionContext& context, const QVariant& defaultValue = QVariant()) const pure virtual

Returns the calculated value of the property with the specified key from within the collection.

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

bool QgsAbstractPropertyCollection::valueAsBool(int key, const QgsExpressionContext& context, bool defaultValue = false, bool* ok = nullptr) const

Calculates the current value of the property with the specified key and interprets it as an boolean.

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.
context QgsExpressionContext to evaluate the property for.
defaultValue default boolean to return if the property cannot be calculated as a boolean
ok if specified, will be set to true if conversion was successful
Returns value parsed to bool

QColor QgsAbstractPropertyCollection::valueAsColor(int key, const QgsExpressionContext& context, const QColor& defaultColor = QColor(), bool* ok = nullptr) const

Calculates the current value of the property with the specified key and interprets it as a color.

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.
context QgsExpressionContext to evaluate the property for.
defaultColor default color to return if the property cannot be calculated as a color
ok if specified, will be set to true if conversion was successful
Returns value parsed to color

double QgsAbstractPropertyCollection::valueAsDouble(int key, const QgsExpressionContext& context, double defaultValue = 0.0, bool* ok = nullptr) const

Calculates the current value of the property with the specified key and interprets it as a double.

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.
context QgsExpressionContext to evaluate the property for.
defaultValue default double to return if the property cannot be calculated as a double
ok if specified, will be set to true if conversion was successful
Returns value parsed to double

int QgsAbstractPropertyCollection::valueAsInt(int key, const QgsExpressionContext& context, int defaultValue = 0, bool* ok = nullptr) const

Calculates the current value of the property with the specified key and interprets it as an integer.

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.
context QgsExpressionContext to evaluate the property for.
defaultValue default integer to return if the property cannot be calculated as a integer
ok if specified, will be set to true if conversion was successful
Returns value parsed to integer

QString QgsAbstractPropertyCollection::valueAsString(int key, const QgsExpressionContext& context, const QString& defaultString = QString(), bool* ok = nullptr) const

Calculates the current value of the property with the specified key and interprets it as a string.

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.
context QgsExpressionContext to evaluate the property for.
defaultString default string to return if the property cannot be calculated as a string
ok if specified, will be set to true if conversion was successful
Returns value parsed to string

bool QgsAbstractPropertyCollection::writeXml(QDomElement& collectionElem, const QgsPropertiesDefinition& definitions) const virtual

Writes the current state of the property collection into an XML element.

Parameters
collectionElem destination element for the property collection's state
definitions property definitions