Class: QgsAbstractPropertyCollection

class qgis.core.QgsAbstractPropertyCollection

Bases: sip.wrapper

Abstract base class for QgsPropertyCollection like objects.

New in version 3.0.

QgsAbstractPropertyCollection(name: str = ‘’) Constructor for QgsAbstractPropertyCollection. The name parameter should be set to a descriptive name for the collection.

QgsAbstractPropertyCollection(QgsAbstractPropertyCollection)

Methods

clear

Removes all properties from the collection.

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

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

isActive

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

loadVariant

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

name

Returns the descriptive name of the property collection.

prepare

Prepares the collection against a specified expression context.

property

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

propertyKeys

Returns a list of property keys contained within the collection.

readXml

Reads property collection state from an XML element.

referencedFields

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

setName

Sets the descriptive name for the property collection.

toVariant

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

value

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

valueAsBool

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

valueAsColor

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

valueAsDateTime

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

valueAsDouble

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

valueAsInt

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

valueAsString

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

writeXml

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

clear(self)

Removes all properties from the collection.

hasActiveProperties(self) bool

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

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

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

Parameters:

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

See also

property()

Return type:

bool

isActive(self, key: int) bool

Returns True if the collection 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, configuration: Any, definitions: Dict[int, QgsPropertyDefinition]) bool

Loads this property collection from a QVariantMap, wrapped in a QVariant. You can use QgsXmlUtils.readVariant to save it to an XML document.

See also

toVariant()

Parameters:
  • configuration (Any) –

  • definitions (Dict[int) –

Return type:

bool

name(self) str

Returns the descriptive name of the property collection.

See also

setName()

Return type:

str

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

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.

Parameters:

context (QgsExpressionContext = QgsExpressionContext()) –

Return type:

bool

property(self, key: int) QgsProperty

Returns 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

Returns a list of property keys contained within the collection.

Return type:

object

readXml(self, collectionElem: QDomElement, definitions: Dict[int, QgsPropertyDefinition]) bool

Reads property collection state from an XML element.

Parameters:
  • collectionElem (QDomElement) – source DOM element for property collection’s state

  • definitions (Dict[int) – property definitions

See also

writeXml()

Return type:

bool

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

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

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]

setName(self, name: str)

Sets the descriptive name for the property collection.

See also

name()

Parameters:

name (str) –

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

Saves this property collection to a QVariantMap, wrapped in a QVariant. You can use QgsXmlUtils.writeVariant to save it to an XML document.

See also

loadVariant()

Parameters:

definitions (Dict[int) –

Return type:

Any

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

Returns the calculated value of the property with the specified key from within the collection. If you need the validity of the value (like ok provided from the valueAs* variants) refer to the property() and QgsProperty.value()

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.

  • 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

See also

valueAsString()

See also

valueAsColor()

See also

valueAsDouble()

See also

valueAsInt()

See also

valueAsBool()

valueAsBool(self, key: int, context: QgsExpressionContext, defaultValue: bool = False) Tuple[bool, bool]

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

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.

  • context (QgsExpressionContext) – QgsExpressionContext to evaluate the property for.

  • defaultValue (bool = False) – default boolean to return if the property cannot be calculated as a boolean

Return type:

Tuple[bool, bool]

Returns:

  • value parsed to bool

  • ok: will be set to True if conversion was successful

See also

value()

See also

valueAsString()

See also

valueAsColor()

See also

valueAsDouble()

See also

valueAsInt()

valueAsColor(self, key: int, context: QgsExpressionContext, defaultColor: QColor | Qt.GlobalColor | QGradient = QColor()) Tuple[QColor, bool]

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

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.

  • context (QgsExpressionContext) – QgsExpressionContext to evaluate the property for.

  • defaultColor (Union[QColor) – default color to return if the property cannot be calculated as a color

Return type:

Tuple[QColor, bool]

Returns:

  • value parsed to color

  • ok: will be set to True if conversion was successful

See also

value()

See also

valueAsString()

See also

valueAsDouble()

See also

valueAsInt()

See also

valueAsBool()

valueAsDateTime(self, key: int, context: QgsExpressionContext, defaultDateTime: QDateTime | datetime.datetime = QDateTime()) Tuple[QDateTime, bool]

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

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.

  • context (QgsExpressionContext) – QgsExpressionContext to evaluate the property for.

  • defaultDateTime (Union[QDateTime) – default datetime to return if the property cannot be calculated as a datetime

Return type:

Tuple[QDateTime, bool]

Returns:

  • value parsed to datetime

  • ok: will be set to True if conversion was successful

See also

value()

See also

valueAsString()

See also

valueAsColor()

See also

valueAsDouble()

See also

valueAsInt()

See also

valueAsBool()

New in version 3.14.

valueAsDouble(self, key: int, context: QgsExpressionContext, defaultValue: float = 0) Tuple[float, bool]

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

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.

  • context (QgsExpressionContext) – QgsExpressionContext to evaluate the property for.

  • defaultValue (float = 0) – default double to return if the property cannot be calculated as a double

Return type:

Tuple[float, bool]

Returns:

  • value parsed to double

  • ok: will be set to True if conversion was successful

See also

value()

See also

valueAsString()

See also

valueAsColor()

See also

valueAsInt()

See also

valueAsBool()

valueAsInt(self, key: int, context: QgsExpressionContext, defaultValue: int = 0) Tuple[int, bool]

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

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.

  • context (QgsExpressionContext) – QgsExpressionContext to evaluate the property for.

  • defaultValue (int = 0) – default integer to return if the property cannot be calculated as a integer

Return type:

Tuple[int, bool]

Returns:

  • value parsed to integer

  • ok: will be set to True if conversion was successful

See also

value()

See also

valueAsString()

See also

valueAsColor()

See also

valueAsDouble()

See also

valueAsBool()

valueAsString(self, key: int, context: QgsExpressionContext, defaultString: str = '') Tuple[str, bool]

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

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.

  • context (QgsExpressionContext) – QgsExpressionContext to evaluate the property for.

  • defaultString (str = '') – default string to return if the property cannot be calculated as a string

Return type:

Tuple[str, bool]

Returns:

  • value parsed to string

  • ok: will be set to True if conversion was successful

See also

value()

See also

valueAsColor()

See also

valueAsDouble()

See also

valueAsInt()

See also

valueAsBool()

writeXml(self, collectionElem: QDomElement, definitions: Dict[int, QgsPropertyDefinition]) bool

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

Parameters:
  • collectionElem (QDomElement) – destination element for the property collection’s state

  • definitions (Dict[int) – property definitions

See also

readXml()

Return type:

bool