26 , mDescription( description )
27 , mStandardType( type )
31 switch ( mStandardType )
35 mHelpText = QObject::tr(
"bool [<b>1</b>=True|<b>0</b>=False]" );
40 mHelpText = QObject::tr(
"int [<= 0 =>]" );
45 mHelpText = QObject::tr(
"int [>= 0]" );
50 mHelpText = QObject::tr(
"int [>= 1]" );
55 mHelpText = QObject::tr(
"double [<= 0.0 =>]" );
60 mHelpText = QObject::tr(
"double [>= 0.0]" );
65 mHelpText = QObject::tr(
"double [0.0-1.0]" );
70 mHelpText = QObject::tr(
"double [0.0-360.0]" );
75 mHelpText = QObject::tr(
"string of variable length" );
80 mHelpText = QObject::tr(
"int [0-100]" );
85 mHelpText = trString() + QStringLiteral(
"[<b>MM</b>|<b>MapUnit</b>|<b>Pixel</b>|<b>Point</b>]" );
90 mHelpText = QObject::tr(
"string [<b>r,g,b,a</b>] as int 0-255 or #<b>AARRGGBB</b> as hex or <b>color</b> as color's name" );
95 mHelpText = QObject::tr(
"string [<b>r,g,b</b>] as int 0-255 or #<b>RRGGBB</b> as hex or <b>color</b> as color's name" );
100 mHelpText = trString() + QStringLiteral(
"[<b>bevel</b>|<b>miter</b>|<b>round</b>]" );
105 mHelpText = trString() + QStringLiteral(
"[<b>Normal</b>|<b>Lighten</b>|<b>Screen</b>|<b>Dodge</b>|<br>" 106 "<b>Addition</b>|<b>Darken</b>|<b>Multiply</b>|<b>Burn</b>|<b>Overlay</b>|<br>" 107 "<b>SoftLight</b>|<b>HardLight</b>|<b>Difference</b>|<b>Subtract</b>]" );
112 mHelpText = QObject::tr(
"double coord [<b>X,Y</b>]" );
117 mHelpText = QObject::tr(
"double [>= 0.0]" );
122 mHelpText = QObject::tr(
"double size [<b>width,height</b>]" );
127 mHelpText = trString() + QStringLiteral(
"[<b>no</b>|<b>solid</b>|<b>dash</b>|<b>dot</b>|<b>dash dot</b>|<b>dash dot dot</b>]" );
132 mHelpText = QObject::tr(
"double [>= 0.0]" );
137 mHelpText = trString() + QStringLiteral(
"[<b>solid</b>|<b>horizontal</b>|<b>vertical</b>|<b>cross</b>|<b>b_diagonal</b>|<b>f_diagonal" 138 "</b>|<b>diagonal_x</b>|<b>dense1</b>|<b>dense2</b>|<b>dense3</b>|<b>dense4</b>|<b>dense5" 139 "</b>|<b>dense6</b>|<b>dense7</b>|<b>no]" );
144 mHelpText = trString() + QStringLiteral(
"[<b>square</b>|<b>flat</b>|<b>round</b>]" );
149 mHelpText = trString() + QStringLiteral(
"[<b>left</b>|<b>center</b>|<b>right</b>]" );
154 mHelpText = trString() + QStringLiteral(
"[<b>top</b>|<b>center</b>|<b>bottom</b>]" );
159 mHelpText = trString() + QStringLiteral(
"[<b>filepath</b>] as<br>" 160 "<b>''</b>=empty|absolute|search-paths-relative|<br>" 161 "project-relative|URL" );
166 mHelpText = QObject::tr(
"double offset [<b>x,y</b>]" );
176 , mDescription( description )
178 , mHelpText( helpText )
180 , mComment( comment )
189 QString QgsPropertyDefinition::trString()
192 return QObject::tr(
"string " );
201 d =
new QgsPropertyPrivate();
240 return d->active == other.d->active
241 && d->type == other.d->type
242 && ( d->type !=
StaticProperty || d->staticValue == other.d->staticValue )
245 && ( ( !d->transformer && !other.d->transformer ) || ( d->transformer && other.d->transformer && d->transformer->toExpression( QString() ) == other.d->transformer->toExpression( QString() ) ) );
250 return ( !( ( *
this ) == other ) );
255 return static_cast< Type >( d->type );
273 d->staticValue =
value;
281 return d->staticValue;
288 d->fieldName =
field;
289 d->cachedFieldIdx = -1;
300 QgsProperty::operator bool()
const 309 d->expressionString = expression;
311 d->expressionPrepared =
false;
319 return d->expressionString;
337 exp = d->expressionString;
344 return d->transformer ? d->transformer->toExpression( exp ) : exp;
369 if ( !d->expression.prepare( &context ) )
371 d->expressionReferencedCols.clear();
372 d->expressionPrepared =
false;
376 d->expressionPrepared =
true;
377 d->expressionReferencedCols = d->expression.referencedColumns();
392 return QSet<QString>();
398 return QSet<QString>();
402 QSet< QString > fields;
403 if ( !d->fieldName.isEmpty() )
404 fields.insert( d->fieldName );
411 if ( !d->expressionPrepared && !
prepare( context ) )
412 return QSet< QString >();
414 return d->expressionReferencedCols;
418 return QSet<QString>();
423 QRegularExpression rx( QStringLiteral(
"^project_color\\('.*'\\)$" ) );
425 && rx.match( d->expressionString ).hasMatch();
428 QVariant QgsProperty::propertyValue(
const QgsExpressionContext &context,
const QVariant &defaultValue,
bool *ok )
const 442 return d->staticValue;
452 if ( d->cachedFieldIdx >= 0 )
459 if ( d->cachedFieldIdx < 0 )
470 if ( !d->expressionPrepared && !
prepare( context ) )
473 QVariant result = d->expression.evaluate( &context );
474 if ( result.isValid() )
501 QVariant val = propertyValue( context, defaultValue, &valOk );
502 if ( !d->transformer && !valOk )
505 if ( d->transformer )
509 val = d->transformer->transform( context, val );
521 QVariant val =
value( context, defaultString, &valOk );
523 if ( !valOk || !val.isValid() )
527 return defaultString;
533 return val.toString();
543 QVariant val =
value( context, defaultColor, &valOk );
545 if ( !valOk || !val.isValid() )
549 if ( val.type() == QVariant::Color )
551 color = val.value<QColor>();
558 if ( !color.isValid() )
574 QVariant val =
value( context, defaultValue, &valOk );
576 if ( !valOk || !val.isValid() )
579 bool convertOk =
false;
580 double dbl = val.toDouble( &convertOk );
597 QVariant val =
value( context, defaultValue, &valOk );
599 if ( !valOk || !val.isValid() )
602 bool convertOk =
false;
603 int integer = val.toInt( &convertOk );
607 double dbl = val.toDouble( &convertOk );
612 return std::round( dbl );
633 QVariant val =
value( context, defaultValue, &valOk );
635 if ( !valOk || !val.isValid() || val.isNull() )
645 QVariantMap propertyMap;
647 propertyMap.insert( QStringLiteral(
"active" ), d->active );
648 propertyMap.insert( QStringLiteral(
"type" ), d->type );
654 propertyMap.insert( QStringLiteral(
"val" ), d->staticValue.toString() );
658 propertyMap.insert( QStringLiteral(
"field" ), d->fieldName );
662 propertyMap.insert( QStringLiteral(
"expression" ), d->expressionString );
669 if ( d->transformer )
672 transformer.insert( QStringLiteral(
"t" ), d->transformer->transformerType() );
673 transformer.insert( QStringLiteral(
"d" ), d->transformer->toVariant() );
675 propertyMap.insert( QStringLiteral(
"transformer" ), transformer );
683 QVariantMap propertyMap =
property.toMap();
686 d->active = propertyMap.value( QStringLiteral(
"active" ) ).toBool();
687 d->type =
static_cast< Type >( propertyMap.value( QStringLiteral(
"type" ),
InvalidProperty ).toInt() );
692 d->staticValue = propertyMap.value( QStringLiteral(
"val" ) );
697 d->fieldName = propertyMap.value( QStringLiteral(
"field" ) ).toString();
698 if ( d->fieldName.isEmpty() )
703 d->expressionString = propertyMap.value( QStringLiteral(
"expression" ) ).toString();
704 if ( d->expressionString.isEmpty() )
708 d->expressionPrepared =
false;
709 d->expressionReferencedCols.clear();
718 delete d->transformer;
719 d->transformer =
nullptr;
722 QVariant transform = propertyMap.value( QStringLiteral(
"transformer" ) );
724 if ( transform.isValid() )
726 QVariantMap transformerMap = transform.toMap();
733 if ( transformer->loadVariant( transformerMap.value( QStringLiteral(
"d" ) ) ) )
734 d->transformer = transformer.release();
750 return d->transformer;
758 if ( d->transformer )
761 QString baseExpression;
768 d->transformer = transformer.release();
769 if ( !fieldName.isEmpty() )
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
bool operator==(const QgsProperty &other) const
Render units (eg mm/pixels/map units)
bool isValid() const
Returns the validity of this feature.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool supportsAssistant() const
Returns true if the property is of a type which is compatible with property override assistants...
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
Field based property (QgsFieldBasedProperty)
Positive integer values (including 0)
QgsProperty & operator=(const QgsProperty &other)
QgsPropertyDefinition()=default
Constructs an empty property.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
1D size (eg marker radius, or square marker height/width)
Expression based property (QgsExpressionBasedProperty)
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
Non-zero positive integer values.
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
Container of fields for a vector layer.
Color with alpha channel.
QgsFields fields() const
Convenience function for retrieving the fields for the context, 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...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Positive double value (including 0)
Rotation (value between 0-360 degrees)
QgsProperty()
Constructor for a QgsAbstractProperty.
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.
const QgsPropertyTransformer * transformer() const
Returns the existing transformer used for manipulating the calculated values for the property...
QVariant toVariant() const
Saves this property to a QVariantMap, wrapped in a QVariant.
QString expressionString() const
Returns the expression used for the property value.
void setField(const QString &field)
Sets the field name the property references.
bool isProjectColor() const
Returns true if the property is set to a linked project color.
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.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const
Returns the set of any fields referenced by the property for a specified expression context...
static QgsProperty fromValue(const QVariant &value, bool isActive=true)
Returns a new StaticProperty created from the specified value.
DataType dataType() const
Returns the allowable field/value data type for the property.
Integer value (including negative values)
Type propertyType() const
Returns the property type.
bool loadVariant(const QVariant &property)
Loads this property from a QVariantMap, wrapped in a QVariant.
Property requires a boolean value.
bool convertToTransformer()
Attempts to convert an existing expression based property to a base expression with corresponding tra...
QString description() const
Descriptive name of the property.
void setActive(bool active)
Sets whether the property is currently active.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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.
Property requires a numeric value.
bool operator!=(const QgsProperty &other) const
A store for object properties.
Fill style (eg solid, lines)
Double value (including negative values)
void setExpressionString(const QString &expression)
Sets the expression to use for the property value.
QString field() const
Returns the current field name the property references.
QString helpText() const
Helper text for using the property, including a description of the valid values for the property...
DataType
Valid data types required by property.
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.
QString comment() const
Returns the comment of the property.
Property requires a string value.
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.
Line style (eg solid/dashed)
QVariant staticValue() const
Returns the current static value for the property.
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
StandardPropertyTemplate
Predefined standard property templates.
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required...
Line cap style (eg round)
QString name() const
Returns the name of the property.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Invalid (not set) property.
void setStaticValue(const QVariant &value)
Sets the static value for the property.
QString origin() const
Returns the origin of the property.
void setTransformer(QgsPropertyTransformer *transformer)
Sets an optional transformer to use for manipulating the calculated values for the property...
bool isActive() const
Returns whether the property is currently active.
2D size (width/height different)
static QColor decodeColor(const QString &str)
Color with no alpha channel.
Double value between 0-1 (inclusive)
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const
Prepares the property against a specified expression context.