Class: QgsPropertyCollectionStack

class qgis.core.QgsPropertyCollectionStack

Bases: QgsAbstractPropertyCollection

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

New in version 3.0.

QgsPropertyCollectionStack() Constructor for QgsPropertyCollectionStack.

QgsPropertyCollectionStack(other: QgsPropertyCollectionStack) Copy constructor

Methods

appendCollection

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

at

Returns the collection at the corresponding index from the stack.

clear

Removes all collections from the stack.

collection

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

count

Returns the number of collections contained within the stack.

hasActiveProperties

Returns True if the collection has any active properties, or False if all properties within the collection are deactivated.

hasDynamicProperties

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.

hasProperty

param key:

isActive

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

loadVariant

param collection:

prepare

param context:

property

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

propertyKeys

rtype:

object

referencedFields

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

toVariant

param definitions:

value

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

appendCollection(self, collection: QgsPropertyCollection)

Appends a collection to the end of the stack, and transfers ownership of the collection to the stack. Properties from the newly added collection will take priority over any existing properties with the same name.

Parameters:

collection (QgsPropertyCollection) – collection to append. Ownership is transferred to the stack.

at(self, index: int) QgsPropertyCollection

Returns the collection at the corresponding index from the stack.

Parameters:

index (int) – position of collection, 0 based

Return type:

QgsPropertyCollection

Returns:

collection if one exists at the specified index

clear(self)

Removes all collections from the stack.

collection(self, name: str) QgsPropertyCollection

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

Parameters:

name (str) – name of collection to find

Return type:

QgsPropertyCollection

Returns:

collection if one exists with the specified name

count(self) int

Returns the number of collections contained within the stack.

Return type:

int

hasActiveProperties(self) bool

Returns True if the collection has any active properties, or False if all properties within the collection are deactivated.

See also

isActive()

Return type:

bool

hasDynamicProperties(self) bool

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.

Return type:

bool

hasProperty(self, key: int) bool
Parameters:

key (int) –

Return type:

bool

isActive(self, key: int) bool

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

Parameters:

key (int) – 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.

Return type:

bool

loadVariant(self, collection: Any, definitions: Dict[int, QgsPropertyDefinition]) bool
Parameters:
  • collection (Any) –

  • definitions (Dict[int) –

Return type:

bool

prepare(self, context: QgsExpressionContext = QgsExpressionContext()) bool
Parameters:

context (QgsExpressionContext = QgsExpressionContext()) –

Return type:

bool

property(self, key: int) QgsProperty

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

Parameters:

key (int) – 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.

Return type:

QgsProperty

Returns:

matching property, or null if no matching, active property found.

See also

hasActiveProperty()

propertyKeys(self) object
Return type:

object

referencedFields(self, context: QgsExpressionContext = QgsExpressionContext(), ignoreContext: bool = False) Set[str]

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

Parameters:
  • context (QgsExpressionContext = QgsExpressionContext()) – expression context the properties will be evaluated against.

  • ignoreContext (bool = False) – This parameter has been added in QGIS 3.14. When set to True, even fields not set in context’s fields() will be reported - this is useful e.g. with vector tiles where the actual available field names may not be known beforehand.

Return type:

Set[str]

toVariant(self, definitions: Dict[int, QgsPropertyDefinition]) Any
Parameters:

definitions (Dict[int) –

Return type:

Any

value(self, key: int, context: QgsExpressionContext, defaultValue: Any = None) Any

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

Parameters:
  • key (int) – 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 (QgsExpressionContext) – expression context to evaluate property against

  • defaultValue (Any = None) – default value to return if no matching, active property found or if the property value cannot be calculated

Return type:

Any

Returns:

calculated property value, or default value if property could not be evaluated