QgsPropertyCollection class
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Contents
Properties within a collection are referenced by an integer key. This is done to avoid the cost of string creation and comparisons which would be required by a string key. The intended use case is that a context specific enum is cast to int and used for the key value.
Base classes
- class QgsAbstractPropertyCollection
- Abstract base class for QgsPropertyCollection like objects.
Constructors, destructors, conversion operators
- QgsPropertyCollection(const QString& name = QString())
- Constructor for QgsPropertyCollection.
- QgsPropertyCollection(const QgsPropertyCollection& other)
- Copy constructor.
Public functions
- void clear() override
- Removes all properties from the collection.
- auto count() const -> int
- Returns the number of properties contained within the collection.
- 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 collection 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 a matching property from the collection, if one exists.
- auto property(int key) -> QgsProperty& virtual
- Returns a reference to a matching property from the collection, if one exists.
- 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 collection.
- void setProperty(int key, const QgsProperty& property)
- Adds a property to the collection and takes ownership of it.
- void setProperty(int key, const QVariant& value)
- Convenience method, creates a QgsStaticProperty and stores it within the collection.
- 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 property with the specified key from within the collection.
Function documentation
QgsPropertyCollection:: QgsPropertyCollection(const QString& name = QString())
Constructor for QgsPropertyCollection.
| Parameters | |
|---|---|
| name | collection name |
bool QgsPropertyCollection:: hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the collection are deactivated.
bool QgsPropertyCollection:: 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 QgsPropertyCollection:: 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 QgsPropertyCollection:: isActive(int key) const override
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 QgsPropertyCollection:: loadVariant(const QVariant& configuration,
const QgsPropertiesDefinition& definitions) override
Loads this property collection from a QVariantMap, wrapped in a QVariant.
You can use QgsXmlUtils::
bool QgsPropertyCollection:: 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 QgsPropertyCollection:: property(int key) const override
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. |
QgsProperty& QgsPropertyCollection:: property(int key) virtual
Returns a reference to 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. |
QSet<QString> QgsPropertyCollection:: referencedFields(const QgsExpressionContext& context = QgsExpressionContext()) const override
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 QgsPropertyCollection:: setProperty(int key,
const QgsProperty& property)
Adds a property to the collection and takes ownership of it.
| Parameters | |
|---|---|
| key | integer key for property. Any existing property with the same key will be removed and replaced by this property. The intended use case is that a context specific enum is cast to int and used for the key value. |
| property | property to add. Ownership is transferred to the collection. Setting an invalid property will remove the property from the collection. |
void QgsPropertyCollection:: setProperty(int key,
const QVariant& value)
Convenience method, creates a QgsStaticProperty and stores it within the collection.
| Parameters | |
|---|---|
| key | integer key for property. Any existing property with the same key will be deleted and replaced by this property. The intended use case is that a context specific enum is cast to int and used for the key value. |
| value | static value for property |
QVariant QgsPropertyCollection:: toVariant(const QgsPropertiesDefinition& definitions) const override
Saves this property collection to a QVariantMap, wrapped in a QVariant.
You can use QgsXmlUtils::
QVariant QgsPropertyCollection:: value(int key,
const QgsExpressionContext& context,
const QVariant& defaultValue = QVariant()) const override
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 |