Class: QgsPropertyCollection

class qgis.core.QgsPropertyCollection(name: str = '')

Bases: QgsAbstractPropertyCollection

Constructor for QgsPropertyCollection

Parameters

name (str = '') – collection name

QgsPropertyCollection(other: QgsPropertyCollection) Copy constructor.

A grouped map of multiple QgsProperty objects, each referenced by a integer key value.

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. Examples of such enums are :

See also

QgsPalLabeling.Property()

See also

QgsAbstract3DSymbol.Property()

See also

QgsWidgetWrapper.Property()

Methods

clear

count

Returns the number of properties contained within the collection.

hasActiveProperties

rtype

bool

hasDynamicProperties

rtype

bool

hasProperty

param key

isActive

param key

loadVariant

param configuration

prepare

param context

property

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

propertyKeys

rtype

object

referencedFields

param context

setProperty

Adds a property to the collection and takes ownership of it.

toVariant

param definitions

value

param key

clear(self)
count(self) → int

Returns the number of properties contained within the collection.

Return type

int

hasActiveProperties(self) → bool
Return type

bool

hasDynamicProperties(self) → bool
Return type

bool

hasProperty(self, key: int) → bool
Parameters

key (int) –

Return type

bool

isActive(self, key: int) → bool
Parameters

key (int) –

Return type

bool

loadVariant(self, configuration: Any, definitions: Dict[int, QgsPropertyDefinition]) → bool
Parameters
  • configuration (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 a reference to a matching property from the collection, if one exists.

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

hasProperty()

propertyKeys(self) → object
Return type

object

referencedFields(self, context: QgsExpressionContext = QgsExpressionContext()) → Set[str]
Parameters

context (QgsExpressionContext = QgsExpressionContext()) –

Return type

Set[str]

setProperty(self, key: int, property: QgsProperty)

Adds a property to the collection and takes ownership of it.

Parameters
  • key (int) – 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 (QgsProperty) – property to add. Ownership is transferred to the collection. Setting an invalid property will remove the property from the collection.

setProperty(self, key: int, value: Any) 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

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

definitions (Dict[int) –

Return type

Any

value(self, key: int, context: QgsExpressionContext, defaultValue: Any = None) → Any
Parameters
Return type

Any