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(
"string of doubles '<b>width,height</b>' or array of doubles <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(
"string of doubles '<b>x,y</b>' or array of doubles <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;
312 d->expressionIsInvalid =
false;
320 return d->expressionString;
338 exp = d->expressionString;
345 return d->transformer ? d->transformer->toExpression( exp ) : exp;
370 if ( !d->expression.prepare( &context ) )
372 d->expressionReferencedCols.clear();
373 d->expressionPrepared =
false;
374 d->expressionIsInvalid =
true;
378 d->expressionPrepared =
true;
379 d->expressionIsInvalid =
false;
380 d->expressionReferencedCols = d->expression.referencedColumns();
395 return QSet<QString>();
401 return QSet<QString>();
405 QSet< QString > fields;
406 if ( !d->fieldName.isEmpty() )
407 fields.insert( d->fieldName );
413 if ( d->expressionIsInvalid )
414 return QSet< QString >();
417 if ( !d->expressionPrepared && !
prepare( context ) )
419 d->expressionIsInvalid =
true;
420 return QSet< QString >();
423 return d->expressionReferencedCols;
427 return QSet<QString>();
432 QRegularExpression rx( QStringLiteral(
"^project_color\\('.*'\\)$" ) );
434 && rx.match( d->expressionString ).hasMatch();
437 QVariant QgsProperty::propertyValue(
const QgsExpressionContext &context,
const QVariant &defaultValue,
bool *ok )
const 451 return d->staticValue;
461 if ( d->cachedFieldIdx >= 0 )
468 if ( d->cachedFieldIdx < 0 )
478 if ( d->expressionIsInvalid )
481 if ( !d->expressionPrepared && !
prepare( context ) )
484 QVariant result = d->expression.evaluate( &context );
485 if ( result.isValid() )
512 QVariant val = propertyValue( context, defaultValue, &valOk );
513 if ( !d->transformer && !valOk )
516 if ( d->transformer )
520 val = d->transformer->transform( context, val );
532 QVariant val =
value( context, defaultString, &valOk );
534 if ( !valOk || !val.isValid() )
538 return defaultString;
544 return val.toString();
554 QVariant val =
value( context, defaultColor, &valOk );
556 if ( !valOk || !val.isValid() )
560 if ( val.type() == QVariant::Color )
562 color = val.value<QColor>();
569 if ( !color.isValid() )
585 QVariant val =
value( context, defaultValue, &valOk );
587 if ( !valOk || !val.isValid() )
590 bool convertOk =
false;
591 double dbl = val.toDouble( &convertOk );
608 QVariant val =
value( context, defaultValue, &valOk );
610 if ( !valOk || !val.isValid() )
613 bool convertOk =
false;
614 int integer = val.toInt( &convertOk );
618 double dbl = val.toDouble( &convertOk );
623 return std::round( dbl );
644 QVariant val =
value( context, defaultValue, &valOk );
646 if ( !valOk || !val.isValid() || val.isNull() )
656 QVariantMap propertyMap;
658 propertyMap.insert( QStringLiteral(
"active" ), d->active );
659 propertyMap.insert( QStringLiteral(
"type" ), d->type );
665 propertyMap.insert( QStringLiteral(
"val" ), d->staticValue.toString() );
669 propertyMap.insert( QStringLiteral(
"field" ), d->fieldName );
673 propertyMap.insert( QStringLiteral(
"expression" ), d->expressionString );
680 if ( d->transformer )
683 transformer.insert( QStringLiteral(
"t" ), d->transformer->transformerType() );
684 transformer.insert( QStringLiteral(
"d" ), d->transformer->toVariant() );
686 propertyMap.insert( QStringLiteral(
"transformer" ), transformer );
694 QVariantMap propertyMap =
property.toMap();
697 d->active = propertyMap.value( QStringLiteral(
"active" ) ).toBool();
698 d->type =
static_cast< Type >( propertyMap.value( QStringLiteral(
"type" ),
InvalidProperty ).toInt() );
703 d->staticValue = propertyMap.value( QStringLiteral(
"val" ) );
708 d->fieldName = propertyMap.value( QStringLiteral(
"field" ) ).toString();
709 if ( d->fieldName.isEmpty() )
714 d->expressionString = propertyMap.value( QStringLiteral(
"expression" ) ).toString();
715 if ( d->expressionString.isEmpty() )
719 d->expressionPrepared =
false;
720 d->expressionIsInvalid =
false;
721 d->expressionReferencedCols.clear();
730 delete d->transformer;
731 d->transformer =
nullptr;
734 QVariant transform = propertyMap.value( QStringLiteral(
"transformer" ) );
736 if ( transform.isValid() )
738 QVariantMap transformerMap = transform.toMap();
745 if ( transformer->loadVariant( transformerMap.value( QStringLiteral(
"d" ) ) ) )
746 d->transformer = transformer.release();
762 return d->transformer;
770 if ( d->transformer )
773 QString baseExpression;
780 d->transformer = transformer.release();
781 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)
Invalid (not set) property.
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.
Static property (QgsStaticProperty)
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.