Class: QgsProperty¶
A store for object properties.
QgsProperty objects are used for storing properties for
objects, which can then be transformed to a QVariant value by evaluating
them against a supplied QgsExpressionContext. Multiple
QgsProperty objects can be grouped using a
QgsPropertyCollection for easier bulk storage, retrieval and
evaluation.
QgsProperty objects are implicitly shared and can be
inexpensively copied.
List of all members, including inherited members
Methods
Returns an expression string representing the state of the property, or an empty string if the property could not be converted to an expression |
|
Attempts to convert an existing expression based property to a base expression with corresponding transformer. |
|
Returns the expression used for the property value. |
|
Returns the current field name the property references. |
|
Returns whether the property is currently active. |
|
Returns |
|
Returns |
|
Loads this property from a QVariantMap, wrapped in a QVariant. |
|
Prepares the property against a specified expression context. |
|
Returns the property type. |
|
Returns the set of any fields referenced by the property for a specified expression context. |
|
Sets whether the property is currently active. |
|
Sets the expression to use for the property value. |
|
Sets the field name the property references. |
|
Sets the static value for the property. |
|
Sets an optional transformer to use for manipulating the calculated values for the property. |
|
Returns the current static value for the property. |
|
Saves this property to a QVariantMap, wrapped in a QVariant. |
|
Returns the existing transformer used for manipulating the calculated values for the property, if set. |
|
Calculates the current value of the property, including any transforms which are set for the property |
|
Calculates the current value of the property and interprets it as an boolean. |
|
Calculates the current value of the property and interprets it as a color. |
|
Calculates the current value of the property and interprets it as a datetime. |
|
Calculates the current value of the property and interprets it as a double. |
|
Calculates the current value of the property and interprets it as an integer. |
|
Calculates the current value of the property and interprets it as a string. |
Static Methods
Returns a new ExpressionBasedProperty created from the specified expression. |
|
Returns a new FieldBasedProperty created from the specified field name. |
|
Returns a new StaticProperty created from the specified value. |
|
Convert a map of |
|
Convert a map of QVariant to a map of |
- class qgis.core.QgsProperty[source]¶
Bases:
object- __init__()
Constructor for a QgsProperty. The property will be set to an InvalidProperty type.
- __init__(other: QgsProperty)
- Parameters:
other (QgsProperty)
- Type¶
alias of
PropertyType
- asExpression(self) str[source]¶
Returns an expression string representing the state of the property, or an empty string if the property could not be converted to an expression
- Return type:
str
- convertToTransformer(self) bool[source]¶
Attempts to convert an existing expression based property to a base expression with corresponding transformer. Returns
Trueif conversion was successful. Note that calling this method requires multiple parsing of expressions, so it should only be called in non-performance critical code.- Return type:
bool
- expressionString(self) str[source]¶
Returns the expression used for the property value. If the property is not a ExpressionBasedProperty this will return an empty string.
See also
- Return type:
str
- field(self) str[source]¶
Returns the current field name the property references. If the property is not a FieldBasedProperty this will return an empty string.
See also
- Return type:
str
- static fromExpression(expression: str | None, isActive: bool = True) QgsProperty[source]¶
Returns a new ExpressionBasedProperty created from the specified expression.
- Parameters:
expression (Optional[str])
isActive (bool = True)
- Return type:
- static fromField(fieldName: str | None, isActive: bool = True) QgsProperty[source]¶
Returns a new FieldBasedProperty created from the specified field name.
- Parameters:
fieldName (Optional[str])
isActive (bool = True)
- Return type:
- static fromValue(value: Any, isActive: bool = True) QgsProperty[source]¶
Returns a new StaticProperty created from the specified value.
- Parameters:
value (Any)
isActive (bool = True)
- Return type:
- isActive(self) bool[source]¶
Returns whether the property is currently active.
See also
- Return type:
bool
- isProjectColor(self) bool[source]¶
Returns
Trueif the property is set to a linked project color.Added in version 3.6.
- Return type:
bool
- isStaticValueInContext(self, context: QgsExpressionContext)[source]¶
Returns
Trueif the property is effectively a static value in the specifiedcontext.I.e. if the property type is QgsProperty.ExpressionBasedProperty with a fixed value expression (‘some static value’), this method will return
True.- Parameters:
context (QgsExpressionContext) – expression context
- Return type:
(bool, Any)
- Returns:
Trueif property is a static valuestaticValue: evaluated static value if property is effectively a static value
Added in version 3.24.
- loadVariant(self, property: Any) bool[source]¶
Loads this property from a QVariantMap, wrapped in a QVariant. You can use
QgsXmlUtils.readVariant to load it from an XML document.See also
- Parameters:
property (Any)
- Return type:
bool
- prepare(self, context: QgsExpressionContext = QgsExpressionContext()) bool[source]¶
Prepares the property against a specified expression context. Calling prepare before evaluating the property multiple times allows precalculation of expensive setup tasks such as parsing expressions. Returns
Trueif preparation was successful.- Parameters:
context (
QgsExpressionContext= QgsExpressionContext())- Return type:
bool
- static propertyMapToVariantMap(propertyMap: dict[str | None, QgsProperty]) dict[str, Any][source]¶
Convert a map of
QgsPropertyto a map of QVariant This is useful to save a map of propertiesAdded in version 3.20.
- Parameters:
propertyMap (dict[Optional[str], QgsProperty])
- Return type:
dict[str, Any]
- propertyType(self) Qgis.PropertyType[source]¶
Returns the property type.
- Return type:
- referencedFields(self, context: QgsExpressionContext = QgsExpressionContext(), ignoreContext: bool = False) set[str]¶
Returns the set of any fields referenced by the property for a specified expression context.
Note
The optional argument ignoreContext 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.- Parameters:
context (
QgsExpressionContext= QgsExpressionContext())ignoreContext (bool = False)
- Return type:
set[str]
- setActive(self, active: bool)[source]¶
Sets whether the property is currently active.
See also
- Parameters:
active (bool)
- setExpressionString(self, expression: str | None)[source]¶
Sets the expression to use for the property value. Calling this will transform the property into an ExpressionBasedProperty.
See also
- Parameters:
expression (Optional[str])
- setField(self, field: str | None)[source]¶
Sets the field name the property references. Calling this will transform the property into an FieldBasedProperty.
See also
- Parameters:
field (Optional[str])
- setStaticValue(self, value: Any)[source]¶
Sets the static value for the property. Calling this will transform the property into an StaticProperty.
See also
- Parameters:
value (Any)
- setTransformer(self, transformer: QgsPropertyTransformer | None)[source]¶
Sets an optional transformer to use for manipulating the calculated values for the property.
- Parameters:
transformer (Optional[QgsPropertyTransformer]) – transformer to install. Ownership is transferred to the property, and any existing transformer will be deleted. Set to
Noneto remove an existing transformer.
See also
- staticValue(self) Any[source]¶
Returns the current static value for the property. If the property is not a StaticProperty this will return an invalid variant.
See also
- Return type:
- toVariant(self) Any[source]¶
Saves this property to a QVariantMap, wrapped in a QVariant. You can use
QgsXmlUtils.writeVariant to save it to an XML document.See also
- Return type:
- transformer(self) QgsPropertyTransformer | None[source]¶
Returns the existing transformer used for manipulating the calculated values for the property, if set.
See also
- Return type:
Optional[QgsPropertyTransformer]
- value(self, context: QgsExpressionContext, defaultValue: Any = None)[source]¶
Calculates the current value of the property, including any transforms which are set for the property
- Parameters:
context (QgsExpressionContext) –
QgsExpressionContextto evaluate the property for. The variables and functions contained in the expression context can be used to alter the calculated value for the property, so that a property is able to respond to the current environment, layers and features within QGIS.defaultValue (Any = None) – default value to return if the property is not active or cannot be calculated
- Return type:
(Any, Optional[bool])
- Returns:
calculated value for property
ok:
Trueif conversion was successful
See also
See also
See also
See also
See also
- valueAsBool(self, context: QgsExpressionContext, defaultValue: bool = False)[source]¶
Calculates the current value of the property and interprets it as an boolean.
- Parameters:
context (QgsExpressionContext) –
QgsExpressionContextto evaluate the property for.defaultValue (bool = False) – default boolean to return if the property cannot be calculated as an boolean
- Return type:
(bool, Optional[bool])
- Returns:
value parsed to boolean
ok:
Trueif conversion was successful
See also
See also
See also
See also
See also
See also
- valueAsColor(self, context: QgsExpressionContext, defaultColor: QColor | Qt.GlobalColor = QColor())[source]¶
Calculates the current value of the property and interprets it as a color.
- Parameters:
context (QgsExpressionContext) –
QgsExpressionContextto evaluate the property for.defaultColor (Union[QColor, Qt.GlobalColor] = QColor()) – default color to return if the property cannot be calculated as a color
- Return type:
(QColor, Optional[bool])
- Returns:
value parsed to color
ok:
Trueif conversion was successful
See also
See also
See also
See also
See also
See also
- valueAsDateTime(self, context: QgsExpressionContext, defaultDateTime: QDateTime | datetime.datetime = QDateTime())[source]¶
Calculates the current value of the property and interprets it as a datetime.
- Parameters:
context (QgsExpressionContext) –
QgsExpressionContextto evaluate the property for.defaultDateTime (Union[QDateTime, datetime.datetime] = QDateTime()) – default datetime to return if the property cannot be calculated as a datetime
- Return type:
(QDateTime, Optional[bool])
- Returns:
value parsed to datetime
ok:
Trueif conversion was successful
See also
See also
See also
See also
See also
See also
Added in version 3.14.
- valueAsDouble(self, context: QgsExpressionContext, defaultValue: float = 0)[source]¶
Calculates the current value of the property and interprets it as a double.
- Parameters:
context (QgsExpressionContext) –
QgsExpressionContextto evaluate the property for.defaultValue (float = 0) – default double to return if the property cannot be calculated as a double
- Return type:
(float, Optional[bool])
- Returns:
value parsed to double
ok:
Trueif conversion was successful
See also
See also
See also
See also
See also
See also
- valueAsInt(self, context: QgsExpressionContext, defaultValue: int = 0)[source]¶
Calculates the current value of the property and interprets it as an integer.
- Parameters:
context (QgsExpressionContext) –
QgsExpressionContextto evaluate the property for.defaultValue (int = 0) – default integer to return if the property cannot be calculated as an integer
- Return type:
(int, Optional[bool])
- Returns:
value parsed to integer
ok:
Trueif conversion was successful
See also
See also
See also
See also
See also
See also
- valueAsString(self, context: QgsExpressionContext, defaultString: str | None = '')[source]¶
Calculates the current value of the property and interprets it as a string.
- Parameters:
context (QgsExpressionContext) –
QgsExpressionContextto evaluate the property for.defaultString (Optional[str] = '') – default string to return if the property cannot be calculated as a string
- Return type:
(str, Optional[bool])
- Returns:
value parsed to string
ok:
Trueif conversion was successful
See also
See also
See also
See also
See also
See also
- static variantMapToPropertyMap(variantMap: dict[str, Any]) dict[str, QgsProperty]¶
Convert a map of QVariant to a map of
QgsPropertyThis is useful to restore a map of properties. The properties are created using QgsProperty.loadVariantAdded in version 3.20.
- Parameters:
variantMap (dict[str, Any])
- Return type:
dict[str, QgsProperty]