Class: QgsProperty¶
-
class
qgis.core.
QgsProperty
¶ Bases:
sip.wrapper
Constructor for a
QgsAbstractProperty
. The property will be set to an InvalidProperty type.QgsProperty(other: QgsProperty) Copy constructor
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.
New in version 3.0: Enums
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 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.
Returns whether the property is currently active.
Returns true if the property is set to a linked project color.
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 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.
Signals
Attributes
-
ExpressionBasedProperty
= 3¶
-
FieldBasedProperty
= 2¶
-
InvalidProperty
= 0¶
-
StaticProperty
= 1¶
-
class
Type
¶ Bases:
int
-
asExpression
(self) → str¶ Returns an expression string representing the state of the property, or an empty string if the property could not be converted to an expression
-
convertToTransformer
(self) → bool¶ Attempts to convert an existing expression based property to a base expression with corresponding transformer. Returns true if conversion was successful. Note that calling this method requires multiple parsing of expressions, so it should only be called in non-performance critical code.
-
expressionString
(self) → str¶ Returns the expression used for the property value. If the property is not a ExpressionBasedProperty this will return an empty string.
See also
-
field
(self) → str¶ Returns the current field name the property references. If the property is not a FieldBasedProperty this will return an empty string.
See also
-
fromExpression
(expression: str, isActive: bool = True) → QgsProperty¶ Returns a new ExpressionBasedProperty created from the specified expression.
-
fromField
(fieldName: str, isActive: bool = True) → QgsProperty¶ Returns a new FieldBasedProperty created from the specified field name.
-
fromValue
(value: Any, isActive: bool = True) → QgsProperty¶ Returns a new StaticProperty created from the specified value.
-
isActive
(self) → bool¶ Returns whether the property is currently active.
See also
-
isProjectColor
(self) → bool¶ Returns true if the property is set to a linked project color.
New in version 3.6.
-
loadVariant
(self, property: Any) → bool¶ Loads this property from a QVariantMap, wrapped in a QVariant. You can use QgsXmlUtils.readVariant to load it from an XML document.
See also
-
prepare
(self, context: QgsExpressionContext = QgsExpressionContext()) → bool¶ 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 true if preparation was successful.
-
propertyType
(self) → QgsProperty.Type¶ Returns the property type.
-
referencedFields
(self, context: QgsExpressionContext = QgsExpressionContext()) → Set[str]¶ Returns the set of any fields referenced by the property for a specified expression context.
-
setActive
(self, active: bool)¶ Sets whether the property is currently active.
See also
-
setExpressionString
(self, expression: str)¶ Sets the expression to use for the property value. Calling this will transform the property into an ExpressionBasedProperty.
See also
-
setField
(self, field: str)¶ Sets the field name the property references. Calling this will transform the property into an FieldBasedProperty.
See also
-
setStaticValue
(self, value: Any)¶ Sets the static value for the property. Calling this will transform the property into an StaticProperty.
See also
-
setTransformer
(self, transformer: QgsPropertyTransformer)¶ Sets an optional transformer to use for manipulating the calculated values for the property.
- Parameters
transformer – transformer to install. Ownership is transferred to the property, and any existing transformer will be deleted. Set to null to remove an existing transformer.
See also
-
staticValue
(self) → Any¶ Returns the current static value for the property. If the property is not a StaticProperty this will return an invalid variant.
See also
-
toVariant
(self) → Any¶ Saves this property to a QVariantMap, wrapped in a QVariant. You can use QgsXmlUtils.writeVariant to save it to an XML document.
See also
-
transformer
(self) → QgsPropertyTransformer¶ Returns the existing transformer used for manipulating the calculated values for the property, if set.
See also
-
value
(self, context: QgsExpressionContext, defaultValue: Any = None) → Tuple[Any, bool]¶ Calculates the current value of the property, including any transforms which are set for the property
- Parameters
context – QgsExpressionContext to 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 – default value to return if the property is not active or cannot be calculated
- Returns
calculated value for property
ok: will be set to true if conversion was successful
See also
See also
See also
See also
See also
-
valueAsBool
(self, context: QgsExpressionContext, defaultValue: bool = False) → Tuple[bool, bool]¶ Calculates the current value of the property and interprets it as an boolean.
- Parameters
context – QgsExpressionContext to evaluate the property for.
defaultValue – default boolean to return if the property cannot be calculated as an boolean
- Returns
value parsed to boolean
ok: will be set to true if conversion was successful
See also
See also
See also
See also
See also
-
valueAsColor
(self, context: QgsExpressionContext, defaultColor: Union[QColor, Qt.GlobalColor, QGradient] = QColor()) → Tuple[QColor, bool]¶ Calculates the current value of the property and interprets it as a color.
- Parameters
context – QgsExpressionContext to evaluate the property for.
defaultColor – default color to return if the property cannot be calculated as a color
- Returns
value parsed to color
ok: will be set to true if conversion was successful
See also
See also
See also
See also
See also
-
valueAsDouble
(self, context: QgsExpressionContext, defaultValue: float = 0) → Tuple[float, bool]¶ Calculates the current value of the property and interprets it as a double.
- Parameters
context – QgsExpressionContext to evaluate the property for.
defaultValue – default double to return if the property cannot be calculated as a double
- Returns
value parsed to double
ok: will be set to true if conversion was successful
See also
See also
See also
See also
See also
-
valueAsInt
(self, context: QgsExpressionContext, defaultValue: int = 0) → Tuple[int, bool]¶ Calculates the current value of the property and interprets it as an integer.
- Parameters
context – QgsExpressionContext to evaluate the property for.
defaultValue – default integer to return if the property cannot be calculated as an integer
- Returns
value parsed to integer
ok: will be set to true if conversion was successful
See also
See also
See also
See also
See also
-
valueAsString
(self, context: QgsExpressionContext, defaultString: str = '') → Tuple[str, bool]¶ Calculates the current value of the property and interprets it as a string.
- Parameters
context – QgsExpressionContext to evaluate the property for.
defaultString – default string to return if the property cannot be calculated as a string
- Returns
value parsed to string
ok: will be set to true if conversion was successful
See also
See also
See also
See also
See also
-