QGIS API Documentation 3.41.0-Master (af5edcb665c)
|
A store for object properties. More...
#include <qgsproperty.h>
Public Member Functions | |
QgsProperty () | |
Constructor for a QgsProperty. | |
QgsProperty (const QgsProperty &other) | |
~QgsProperty () | |
QString | asExpression () const |
Returns an expression string representing the state of the property, or an empty string if the property could not be converted to an expression. | |
bool | convertToTransformer () |
Attempts to convert an existing expression based property to a base expression with corresponding transformer. | |
QString | expressionString () const |
Returns the expression used for the property value. | |
QString | field () const |
Returns the current field name the property references. | |
bool | isActive () const |
Returns whether the property is currently active. | |
bool | isProjectColor () const |
Returns true if the property is set to a linked project color. | |
bool | isStaticValueInContext (const QgsExpressionContext &context, QVariant &staticValue) const |
Returns true if the property is effectively a static value in the specified context. | |
bool | loadVariant (const QVariant &property) |
Loads this property from a QVariantMap, wrapped in a QVariant. | |
operator bool () const | |
Returns true if the property is not an invalid type. | |
operator QVariant () const | |
Allows direct construction of QVariants from properties. | |
bool | operator!= (const QgsProperty &other) const |
QgsProperty & | operator= (const QgsProperty &other) |
bool | operator== (const QgsProperty &other) const |
bool | prepare (const QgsExpressionContext &context=QgsExpressionContext()) const |
Prepares the property against a specified expression context. | |
Qgis::PropertyType | propertyType () const |
Returns the property type. | |
QSet< QString > | referencedFields (const QgsExpressionContext &context=QgsExpressionContext(), bool ignoreContext=false) const |
Returns the set of any fields referenced by the property for a specified expression context. | |
void | setActive (bool active) |
Sets whether the property is currently active. | |
void | setExpressionString (const QString &expression) |
Sets the expression to use for the property value. | |
void | setField (const QString &field) |
Sets the field name the property references. | |
void | setStaticValue (const QVariant &value) |
Sets the static value for the property. | |
void | setTransformer (QgsPropertyTransformer *transformer) |
Sets an optional transformer to use for manipulating the calculated values for the property. | |
QVariant | staticValue () const |
Returns the current static value for the property. | |
QVariant | toVariant () const |
Saves this property to a QVariantMap, wrapped in a QVariant. | |
const QgsPropertyTransformer * | transformer () const |
Returns the existing transformer used for manipulating the calculated values for the property, if set. | |
QVariant | value (const QgsExpressionContext &context, const QVariant &defaultValue=QVariant(), bool *ok=nullptr) const |
Calculates the current value of the property, including any transforms which are set for the property. | |
bool | valueAsBool (const QgsExpressionContext &context, bool defaultValue=false, bool *ok=nullptr) const |
Calculates the current value of the property and interprets it as an boolean. | |
QColor | valueAsColor (const QgsExpressionContext &context, const QColor &defaultColor=QColor(), bool *ok=nullptr) const |
Calculates the current value of the property and interprets it as a color. | |
QDateTime | valueAsDateTime (const QgsExpressionContext &context, const QDateTime &defaultDateTime=QDateTime(), bool *ok=nullptr) const |
Calculates the current value of the property and interprets it as a datetime. | |
double | valueAsDouble (const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const |
Calculates the current value of the property and interprets it as a double. | |
int | valueAsInt (const QgsExpressionContext &context, int defaultValue=0, bool *ok=nullptr) const |
Calculates the current value of the property and interprets it as an integer. | |
QString | valueAsString (const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const |
Calculates the current value of the property and interprets it as a string. | |
Static Public Member Functions | |
static QgsProperty | fromExpression (const QString &expression, bool isActive=true) |
Returns a new ExpressionBasedProperty created from the specified expression. | |
static QgsProperty | fromField (const QString &fieldName, bool isActive=true) |
Returns a new FieldBasedProperty created from the specified field name. | |
static QgsProperty | fromValue (const QVariant &value, bool isActive=true) |
Returns a new StaticProperty created from the specified value. | |
static QVariantMap | propertyMapToVariantMap (const QMap< QString, QgsProperty > &propertyMap) |
Convert a map of QgsProperty to a map of QVariant This is useful to save a map of properties. | |
static QMap< QString, QgsProperty > | variantMapToPropertyMap (const QVariantMap &variantMap) |
Convert a map of QVariant to a map of QgsProperty This is useful to restore a map of properties. | |
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.
Definition at line 227 of file qgsproperty.h.
QgsProperty::QgsProperty | ( | ) |
Constructor for a QgsProperty.
The property will be set to an InvalidProperty type.
Definition at line 227 of file qgsproperty.cpp.
|
default |
QgsProperty::QgsProperty | ( | const QgsProperty & | other | ) |
Definition at line 258 of file qgsproperty.cpp.
QString QgsProperty::asExpression | ( | ) | const |
Returns an expression string representing the state of the property, or an empty string if the property could not be converted to an expression.
Definition at line 395 of file qgsproperty.cpp.
bool QgsProperty::convertToTransformer | ( | ) |
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.
Definition at line 873 of file qgsproperty.cpp.
QString QgsProperty::expressionString | ( | ) | const |
Returns the expression used for the property value.
If the property is not a ExpressionBasedProperty this will return an empty string.
Definition at line 386 of file qgsproperty.cpp.
QString QgsProperty::field | ( | ) | const |
Returns the current field name the property references.
If the property is not a FieldBasedProperty this will return an empty string.
Definition at line 354 of file qgsproperty.cpp.
|
static |
Returns a new ExpressionBasedProperty created from the specified expression.
Definition at line 234 of file qgsproperty.cpp.
|
static |
Returns a new FieldBasedProperty created from the specified field name.
Definition at line 242 of file qgsproperty.cpp.
|
static |
Returns a new StaticProperty created from the specified value.
Definition at line 250 of file qgsproperty.cpp.
bool QgsProperty::isActive | ( | ) | const |
Returns whether the property is currently active.
Definition at line 288 of file qgsproperty.cpp.
bool QgsProperty::isProjectColor | ( | ) | const |
Returns true
if the property is set to a linked project color.
Definition at line 506 of file qgsproperty.cpp.
bool QgsProperty::isStaticValueInContext | ( | const QgsExpressionContext & | context, |
QVariant & | staticValue | ||
) | const |
Returns true
if the property is effectively a static value in the specified context.
I.e. if the property type is QgsProperty::ExpressionBasedProperty with a fixed value expression ('some static value'), this method will return true
.
context | expression context |
staticValue | will be set to evaluated static value if property is effectively a static value |
true
if property is a static valueDefinition at line 293 of file qgsproperty.cpp.
bool QgsProperty::loadVariant | ( | const QVariant & | property | ) |
Loads this property from a QVariantMap, wrapped in a QVariant.
You can use QgsXmlUtils::readVariant to load it from an XML document.
Definition at line 800 of file qgsproperty.cpp.
|
explicit |
Returns true
if the property is not an invalid type.
Definition at line 362 of file qgsproperty.cpp.
|
inline |
Allows direct construction of QVariants from properties.
Definition at line 529 of file qgsproperty.h.
bool QgsProperty::operator!= | ( | const QgsProperty & | other | ) | const |
Definition at line 278 of file qgsproperty.cpp.
QgsProperty & QgsProperty::operator= | ( | const QgsProperty & | other | ) |
Definition at line 262 of file qgsproperty.cpp.
bool QgsProperty::operator== | ( | const QgsProperty & | other | ) | const |
Definition at line 268 of file qgsproperty.cpp.
bool QgsProperty::prepare | ( | const QgsExpressionContext & | context = QgsExpressionContext() | ) | const |
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.
Definition at line 419 of file qgsproperty.cpp.
|
static |
Convert a map of QgsProperty to a map of QVariant This is useful to save a map of properties.
Definition at line 205 of file qgsproperty.cpp.
Qgis::PropertyType QgsProperty::propertyType | ( | ) | const |
Returns the property type.
Definition at line 283 of file qgsproperty.cpp.
QSet< QString > QgsProperty::referencedFields | ( | const QgsExpressionContext & | context = QgsExpressionContext() , |
bool | ignoreContext = false |
||
) | const |
Returns the set of any fields referenced by the property for a specified expression context.
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. Definition at line 463 of file qgsproperty.cpp.
void QgsProperty::setActive | ( | bool | active | ) |
Sets whether the property is currently active.
Definition at line 325 of file qgsproperty.cpp.
void QgsProperty::setExpressionString | ( | const QString & | expression | ) |
Sets the expression to use for the property value.
Calling this will transform the property into an ExpressionBasedProperty.
Definition at line 367 of file qgsproperty.cpp.
void QgsProperty::setField | ( | const QString & | field | ) |
Sets the field name the property references.
Calling this will transform the property into an FieldBasedProperty.
Definition at line 346 of file qgsproperty.cpp.
void QgsProperty::setStaticValue | ( | const QVariant & | value | ) |
Sets the static value for the property.
Calling this will transform the property into an StaticProperty.
Definition at line 331 of file qgsproperty.cpp.
void QgsProperty::setTransformer | ( | QgsPropertyTransformer * | transformer | ) |
Sets an optional transformer to use for manipulating the calculated values for the property.
transformer | transformer to install. Ownership is transferred to the property, and any existing transformer will be deleted. Set to nullptr to remove an existing transformer. |
Definition at line 862 of file qgsproperty.cpp.
QVariant QgsProperty::staticValue | ( | ) | const |
Returns the current static value for the property.
If the property is not a StaticProperty this will return an invalid variant.
Definition at line 338 of file qgsproperty.cpp.
QVariant QgsProperty::toVariant | ( | ) | const |
Saves this property to a QVariantMap, wrapped in a QVariant.
You can use QgsXmlUtils::writeVariant to save it to an XML document.
Definition at line 762 of file qgsproperty.cpp.
const QgsPropertyTransformer * QgsProperty::transformer | ( | ) | const |
Returns the existing transformer used for manipulating the calculated values for the property, if set.
Definition at line 868 of file qgsproperty.cpp.
QVariant QgsProperty::value | ( | const QgsExpressionContext & | context, |
const QVariant & | defaultValue = QVariant() , |
||
bool * | ok = nullptr |
||
) | const |
Calculates the current value of the property, including any transforms which are set for the property.
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 |
ok | if specified, will be set to true if conversion was successful |
Definition at line 582 of file qgsproperty.cpp.
bool QgsProperty::valueAsBool | ( | const QgsExpressionContext & | context, |
bool | defaultValue = false , |
||
bool * | ok = nullptr |
||
) | const |
Calculates the current value of the property and interprets it as an boolean.
context | QgsExpressionContext to evaluate the property for. |
defaultValue | default boolean to return if the property cannot be calculated as an boolean |
ok | if specified, will be set to true if conversion was successful |
Definition at line 746 of file qgsproperty.cpp.
QColor QgsProperty::valueAsColor | ( | const QgsExpressionContext & | context, |
const QColor & | defaultColor = QColor() , |
||
bool * | ok = nullptr |
||
) | const |
Calculates the current value of the property and interprets it as a color.
context | QgsExpressionContext to evaluate the property for. |
defaultColor | default color to return if the property cannot be calculated as a color |
ok | if specified, will be set to true if conversion was successful |
Definition at line 656 of file qgsproperty.cpp.
QDateTime QgsProperty::valueAsDateTime | ( | const QgsExpressionContext & | context, |
const QDateTime & | defaultDateTime = QDateTime() , |
||
bool * | ok = nullptr |
||
) | const |
Calculates the current value of the property and interprets it as a datetime.
context | QgsExpressionContext to evaluate the property for. |
defaultDateTime | default datetime to return if the property cannot be calculated as a datetime |
ok | if specified, will be set to true if conversion was successful |
Definition at line 605 of file qgsproperty.cpp.
double QgsProperty::valueAsDouble | ( | const QgsExpressionContext & | context, |
double | defaultValue = 0.0 , |
||
bool * | ok = nullptr |
||
) | const |
Calculates the current value of the property and interprets it as a double.
context | QgsExpressionContext to evaluate the property for. |
defaultValue | default double to return if the property cannot be calculated as a double |
ok | if specified, will be set to true if conversion was successful |
Definition at line 687 of file qgsproperty.cpp.
int QgsProperty::valueAsInt | ( | const QgsExpressionContext & | context, |
int | defaultValue = 0 , |
||
bool * | ok = nullptr |
||
) | const |
Calculates the current value of the property and interprets it as an integer.
context | QgsExpressionContext to evaluate the property for. |
defaultValue | default integer to return if the property cannot be calculated as an integer |
ok | if specified, will be set to true if conversion was successful |
Definition at line 710 of file qgsproperty.cpp.
QString QgsProperty::valueAsString | ( | const QgsExpressionContext & | context, |
const QString & | defaultString = QString() , |
||
bool * | ok = nullptr |
||
) | const |
Calculates the current value of the property and interprets it as a string.
context | QgsExpressionContext to evaluate the property for. |
defaultString | default string to return if the property cannot be calculated as a string |
ok | if specified, will be set to true if conversion was successful |
Definition at line 637 of file qgsproperty.cpp.
|
static |
Convert a map of QVariant to a map of QgsProperty This is useful to restore a map of properties.
The properties are created using QgsProperty::loadVariant
Definition at line 214 of file qgsproperty.cpp.