27 , mDescription( description )
28 , mStandardType( type )
32 switch ( mStandardType )
36 mHelpText = QObject::tr(
"bool [<b>1</b>=True|<b>0</b>=False]" );
41 mHelpText = QObject::tr(
"int [<= 0 =>]" );
46 mHelpText = QObject::tr(
"int [>= 0]" );
51 mHelpText = QObject::tr(
"int [>= 1]" );
56 mHelpText = QObject::tr(
"double [<= 0.0 =>]" );
61 mHelpText = QObject::tr(
"double [>= 0.0]" );
66 mHelpText = QObject::tr(
"double [0.0-1.0]" );
71 mHelpText = QObject::tr(
"double [0.0-360.0]" );
76 mHelpText = QObject::tr(
"string of variable length" );
81 mHelpText = QObject::tr(
"int [0-100]" );
86 mHelpText = trString() + QStringLiteral(
"[<b>MM</b>|<b>MapUnit</b>|<b>Pixel</b>|<b>Point</b>]" );
91 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" );
96 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" );
101 mHelpText = trString() + QStringLiteral(
"[<b>bevel</b>|<b>miter</b>|<b>round</b>]" );
106 mHelpText = trString() + QStringLiteral(
"[<b>Normal</b>|<b>Lighten</b>|<b>Screen</b>|<b>Dodge</b>|<br>" 107 "<b>Addition</b>|<b>Darken</b>|<b>Multiply</b>|<b>Burn</b>|<b>Overlay</b>|<br>" 108 "<b>SoftLight</b>|<b>HardLight</b>|<b>Difference</b>|<b>Subtract</b>]" );
113 mHelpText = QObject::tr(
"double coord [<b>X,Y</b>]" );
118 mHelpText = QObject::tr(
"double [>= 0.0]" );
123 mHelpText = QObject::tr(
"string of doubles '<b>width,height</b>' or array of doubles <b>[width, height]</b>" );
128 mHelpText = trString() + QStringLiteral(
"[<b>no</b>|<b>solid</b>|<b>dash</b>|<b>dot</b>|<b>dash dot</b>|<b>dash dot dot</b>]" );
133 mHelpText = QObject::tr(
"double [>= 0.0]" );
138 mHelpText = trString() + QStringLiteral(
"[<b>solid</b>|<b>horizontal</b>|<b>vertical</b>|<b>cross</b>|<b>b_diagonal</b>|<b>f_diagonal" 139 "</b>|<b>diagonal_x</b>|<b>dense1</b>|<b>dense2</b>|<b>dense3</b>|<b>dense4</b>|<b>dense5" 140 "</b>|<b>dense6</b>|<b>dense7</b>|<b>no]" );
145 mHelpText = trString() + QStringLiteral(
"[<b>square</b>|<b>flat</b>|<b>round</b>]" );
150 mHelpText = trString() + QStringLiteral(
"[<b>left</b>|<b>center</b>|<b>right</b>]" );
155 mHelpText = trString() + QStringLiteral(
"[<b>top</b>|<b>center</b>|<b>bottom</b>]" );
160 mHelpText = trString() + QStringLiteral(
"[<b>filepath</b>] as<br>" 161 "<b>''</b>=empty|absolute|search-paths-relative|<br>" 162 "project-relative|URL" );
167 mHelpText = QObject::tr(
"string of doubles '<b>x,y</b>' or array of doubles <b>[x, y]</b>" );
177 , mDescription( description )
179 , mHelpText( helpText )
181 , mComment( comment )
190 QString QgsPropertyDefinition::trString()
193 return QObject::tr(
"string " );
202 d =
new QgsPropertyPrivate();
243 return d->active == other.d->active
244 && d->type == other.d->type
245 && ( d->type !=
StaticProperty || d->staticValue == other.d->staticValue )
248 && ( ( !d->transformer && !other.d->transformer ) || ( d->transformer && other.d->transformer && d->transformer->toExpression( QString() ) == other.d->transformer->toExpression( QString() ) ) );
253 return ( !( ( *
this ) == other ) );
258 return static_cast< Type >( d->type );
276 d->staticValue =
value;
284 return d->staticValue;
291 d->fieldName =
field;
292 d->cachedFieldIdx = -1;
303 QgsProperty::operator bool()
const 312 d->expressionString = expression;
314 d->expressionPrepared =
false;
315 d->expressionIsInvalid =
false;
323 return d->expressionString;
341 exp = d->expressionString;
348 return d->transformer ? d->transformer->toExpression( exp ) : exp;
373 if ( !d->expression.prepare( &context ) )
375 d->expressionReferencedCols.clear();
376 d->expressionPrepared =
false;
377 d->expressionIsInvalid =
true;
381 d->expressionPrepared =
true;
382 d->expressionIsInvalid =
false;
383 d->expressionReferencedCols = d->expression.referencedColumns();
398 return QSet<QString>();
404 return QSet<QString>();
408 QSet< QString > fields;
409 if ( !d->fieldName.isEmpty() )
410 fields.insert( d->fieldName );
416 if ( d->expressionIsInvalid )
417 return QSet< QString >();
420 if ( !d->expressionPrepared && !
prepare( context ) )
422 d->expressionIsInvalid =
true;
423 return QSet< QString >();
426 return d->expressionReferencedCols;
430 return QSet<QString>();
435 QRegularExpression rx( QStringLiteral(
"^project_color\\('.*'\\)$" ) );
437 && rx.match( d->expressionString ).hasMatch();
440 QVariant QgsProperty::propertyValue(
const QgsExpressionContext &context,
const QVariant &defaultValue,
bool *ok )
const 454 return d->staticValue;
464 if ( d->cachedFieldIdx >= 0 )
471 if ( d->cachedFieldIdx < 0 )
481 if ( d->expressionIsInvalid )
484 if ( !d->expressionPrepared && !
prepare( context ) )
487 QVariant result = d->expression.evaluate( &context );
488 if ( result.isValid() )
515 QVariant val = propertyValue( context, defaultValue, &valOk );
516 if ( !d->transformer && !valOk )
519 if ( d->transformer )
523 val = d->transformer->transform( context, val );
535 QVariant val =
value( context, defaultString, &valOk );
537 if ( !valOk || !val.isValid() )
541 return defaultString;
547 return val.toString();
557 QVariant val =
value( context, defaultColor, &valOk );
559 if ( !valOk || !val.isValid() )
563 if ( val.type() == QVariant::Color )
565 color = val.value<QColor>();
572 if ( !color.isValid() )
588 QVariant val =
value( context, defaultValue, &valOk );
590 if ( !valOk || !val.isValid() )
593 bool convertOk =
false;
594 double dbl = val.toDouble( &convertOk );
611 QVariant val =
value( context, defaultValue, &valOk );
613 if ( !valOk || !val.isValid() )
616 bool convertOk =
false;
617 int integer = val.toInt( &convertOk );
621 double dbl = val.toDouble( &convertOk );
626 return std::round( dbl );
647 QVariant val =
value( context, defaultValue, &valOk );
649 if ( !valOk || !val.isValid() || val.isNull() )
659 QVariantMap propertyMap;
661 propertyMap.insert( QStringLiteral(
"active" ), d->active );
662 propertyMap.insert( QStringLiteral(
"type" ), d->type );
668 propertyMap.insert( QStringLiteral(
"val" ), d->staticValue.toString() );
672 propertyMap.insert( QStringLiteral(
"field" ), d->fieldName );
676 propertyMap.insert( QStringLiteral(
"expression" ), d->expressionString );
683 if ( d->transformer )
686 transformer.insert( QStringLiteral(
"t" ), d->transformer->transformerType() );
687 transformer.insert( QStringLiteral(
"d" ), d->transformer->toVariant() );
689 propertyMap.insert( QStringLiteral(
"transformer" ), transformer );
697 QVariantMap propertyMap =
property.toMap();
700 d->active = propertyMap.value( QStringLiteral(
"active" ) ).toBool();
701 d->type =
static_cast< Type >( propertyMap.value( QStringLiteral(
"type" ),
InvalidProperty ).toInt() );
706 d->staticValue = propertyMap.value( QStringLiteral(
"val" ) );
711 d->fieldName = propertyMap.value( QStringLiteral(
"field" ) ).toString();
712 if ( d->fieldName.isEmpty() )
717 d->expressionString = propertyMap.value( QStringLiteral(
"expression" ) ).toString();
718 if ( d->expressionString.isEmpty() )
722 d->expressionPrepared =
false;
723 d->expressionIsInvalid =
false;
724 d->expressionReferencedCols.clear();
733 delete d->transformer;
734 d->transformer =
nullptr;
737 QVariant transform = propertyMap.value( QStringLiteral(
"transformer" ) );
739 if ( transform.isValid() )
741 QVariantMap transformerMap = transform.toMap();
748 if ( transformer->loadVariant( transformerMap.value( QStringLiteral(
"d" ) ) ) )
749 d->transformer = transformer.release();
765 return d->transformer;
773 if ( d->transformer )
776 QString baseExpression;
783 d->transformer = transformer.release();
784 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.