Class: QgsAbstractPropertyCollection¶
Abstract base class for QgsPropertyCollection
like objects.
Note
This is an abstract class, with methods which must be implemented by a subclass.
The following methods must be implemented: clear()
, hasActiveProperties()
, hasDynamicProperties()
, hasProperty()
, isActive()
, loadVariant()
, prepare()
, property()
, propertyKeys()
, referencedFields()
, toVariant()
, value()
Class Hierarchy¶
Subclasses¶
A grouped map of multiple |
|
An ordered stack of |
Abstract Methods
Removes all properties from the collection. |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Loads this property collection from a QVariantMap, wrapped in a QVariant. |
|
Prepares the collection against a specified expression context. |
|
Returns a matching property from the collection, if one exists. |
|
Returns a list of property keys contained within the collection. |
|
Returns the set of any fields referenced by the active properties from the collection. |
|
Saves this property collection to a QVariantMap, wrapped in a QVariant. |
|
Returns the calculated value of the property with the specified key from within the collection. |
Methods
Returns the descriptive name of the property collection. |
|
Sets the descriptive name for the property collection. |
|
Calculates the current value of the property with the specified key and interprets it as an boolean. |
|
Calculates the current value of the property with the specified key and interprets it as a color. |
|
Calculates the current value of the property with the specified key and interprets it as a datetime. |
|
Calculates the current value of the property with the specified key and interprets it as a double. |
|
Calculates the current value of the property with the specified key and interprets it as an integer. |
|
Calculates the current value of the property with the specified key and interprets it as a string. |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsAbstractPropertyCollection. See the FAQ for more details.
Reads property collection state from an XML element. |
|
Writes the current state of the property collection into an XML element |
- class qgis.core.QgsAbstractPropertyCollection[source]¶
Bases:
object
- __init__(name: str | None = '')
Constructor for QgsAbstractPropertyCollection. The name parameter should be set to a descriptive name for the collection.
- Parameters:
name (Optional[str] = '')
- __init__(a0: QgsAbstractPropertyCollection)
- Parameters:
- abstract hasActiveProperties(self) bool [source]¶
Returns
True
if the collection has any active properties, orFalse
if all properties within the collection are deactivated.See also
- Return type:
bool
- abstract hasDynamicProperties(self) bool [source]¶
Returns
True
if the collection has any active, non-static properties, orFalse
if either all non-static properties within the collection are deactivated or if the collection only contains static properties.See also
- Return type:
bool
- abstract hasProperty(self, key: int) bool [source]¶
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
- Return type:
bool
- abstract isActive(self, key: int) bool [source]¶
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
- abstract loadVariant(self, configuration: Any, definitions: Dict[int, QgsPropertyDefinition]) bool [source]¶
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
- Parameters:
configuration (Any)
definitions (Dict[int, QgsPropertyDefinition])
- Return type:
bool
- name(self) str [source]¶
Returns the descriptive name of the property collection.
See also
- Return type:
str
- abstract prepare(self, context: QgsExpressionContext = QgsExpressionContext()) bool [source]¶
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
- abstract property(self, key: int) QgsProperty [source]¶
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:
- Returns:
matching property, or null if no matching, active property found.
See also
- abstract propertyKeys(self) Any ¶
Returns a list of property keys contained within the collection.
- Return type:
Any
- virtual readXml(self, collectionElem: QDomElement, definitions: Dict[int, QgsPropertyDefinition]) bool [source]¶
Reads property collection state from an XML element.
- Parameters:
collectionElem (QDomElement) – source DOM element for property collection’s state
definitions (Dict[int, QgsPropertyDefinition]) – property definitions
See also
- Return type:
bool
- abstract 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’sfields()
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 | None)[source]¶
Sets the descriptive name for the property collection.
See also
- Parameters:
name (Optional[str])
- abstract toVariant(self, definitions: Dict[int, QgsPropertyDefinition]) Any [source]¶
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
- Parameters:
definitions (Dict[int, QgsPropertyDefinition])
- Return type:
Any
- abstract value(self, key: int, context: QgsExpressionContext, defaultValue: Any = None) Any [source]¶
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()
andQgsProperty.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
See also
See also
See also
See also
- valueAsBool(self, key: int, context: QgsExpressionContext, defaultValue: bool = False)[source]¶
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) -> (bool) – default boolean to return if the property cannot be calculated as a boolean
- Returns:
value parsed to bool
ok:
True
if conversion was successful
See also
See also
See also
See also
See also
See also
- valueAsColor(self, key: int, context: QgsExpressionContext, defaultColor: QColor | Qt.GlobalColor = QColor())[source]¶
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, Qt.GlobalColor] = QColor()) -> (QColor) – default color to return if the property cannot be calculated as a color
- Returns:
value parsed to color
ok:
True
if conversion was successful
See also
See also
See also
See also
See also
See also
- valueAsDateTime(self, key: int, context: QgsExpressionContext, defaultDateTime: QDateTime | datetime.datetime = QDateTime())[source]¶
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, datetime.datetime] = QDateTime()) -> (QDateTime) – default datetime to return if the property cannot be calculated as a datetime
- Returns:
value parsed to datetime
ok:
True
if conversion was successful
See also
See also
See also
See also
See also
See also
Added in version 3.14.
- valueAsDouble(self, key: int, context: QgsExpressionContext, defaultValue: float = 0)[source]¶
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) -> (float) – default double to return if the property cannot be calculated as a double
- Returns:
value parsed to double
ok:
True
if conversion was successful
See also
See also
See also
See also
See also
See also
- valueAsInt(self, key: int, context: QgsExpressionContext, defaultValue: int = 0)[source]¶
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) -> (int) – default integer to return if the property cannot be calculated as a integer
- Returns:
value parsed to integer
ok:
True
if conversion was successful
See also
See also
See also
See also
See also
See also
- valueAsString(self, key: int, context: QgsExpressionContext, defaultString: str | None = '')[source]¶
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 (Optional[str] = '') -> (str) – default string to return if the property cannot be calculated as a string
- Returns:
value parsed to string
ok:
True
if conversion was successful
See also
See also
See also
See also
See also
See also
- virtual writeXml(self, collectionElem: QDomElement, definitions: Dict[int, QgsPropertyDefinition]) bool [source]¶
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, QgsPropertyDefinition]) – property definitions
See also
- Return type:
bool