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>RRGGBBAA</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>();
421 QVariant QgsProperty::propertyValue(
const QgsExpressionContext &context,
const QVariant &defaultValue,
bool *ok )
const 435 return d->staticValue;
445 if ( d->cachedFieldIdx >= 0 )
452 if ( d->cachedFieldIdx < 0 )
463 if ( !d->expressionPrepared && !
prepare( context ) )
466 QVariant result = d->expression.evaluate( &context );
467 if ( result.isValid() )
494 QVariant val = propertyValue( context, defaultValue, &valOk );
495 if ( !d->transformer && !valOk )
498 if ( d->transformer )
502 val = d->transformer->transform( context, val );
514 QVariant val =
value( context, defaultString, &valOk );
516 if ( !valOk || !val.isValid() )
520 return defaultString;
526 return val.toString();
536 QVariant val =
value( context, defaultColor, &valOk );
538 if ( !valOk || !val.isValid() )
542 if ( val.type() == QVariant::Color )
544 color = val.value<QColor>();
551 if ( !color.isValid() )
567 QVariant val =
value( context, defaultValue, &valOk );
569 if ( !valOk || !val.isValid() )
572 bool convertOk =
false;
573 double dbl = val.toDouble( &convertOk );
590 QVariant val =
value( context, defaultValue, &valOk );
592 if ( !valOk || !val.isValid() )
595 bool convertOk =
false;
596 int integer = val.toInt( &convertOk );
600 double dbl = val.toDouble( &convertOk );
605 return std::round( dbl );
626 QVariant val =
value( context, defaultValue, &valOk );
628 if ( !valOk || !val.isValid() || val.isNull() )
638 QVariantMap propertyMap;
640 propertyMap.insert( QStringLiteral(
"active" ), d->active );
641 propertyMap.insert( QStringLiteral(
"type" ), d->type );
647 propertyMap.insert( QStringLiteral(
"val" ), d->staticValue.toString() );
651 propertyMap.insert( QStringLiteral(
"field" ), d->fieldName );
655 propertyMap.insert( QStringLiteral(
"expression" ), d->expressionString );
662 if ( d->transformer )
665 transformer.insert( QStringLiteral(
"t" ), d->transformer->transformerType() );
666 transformer.insert( QStringLiteral(
"d" ), d->transformer->toVariant() );
668 propertyMap.insert( QStringLiteral(
"transformer" ), transformer );
676 QVariantMap propertyMap =
property.toMap();
679 d->active = propertyMap.value( QStringLiteral(
"active" ) ).toBool();
680 d->type =
static_cast< Type >( propertyMap.value( QStringLiteral(
"type" ),
InvalidProperty ).toInt() );
685 d->staticValue = propertyMap.value( QStringLiteral(
"val" ) );
690 d->fieldName = propertyMap.value( QStringLiteral(
"field" ) ).toString();
691 if ( d->fieldName.isEmpty() )
696 d->expressionString = propertyMap.value( QStringLiteral(
"expression" ) ).toString();
697 if ( d->expressionString.isEmpty() )
701 d->expressionPrepared =
false;
702 d->expressionReferencedCols.clear();
711 if ( d->transformer )
712 delete d->transformer;
713 d->transformer =
nullptr;
716 QVariant transform = propertyMap.value( QStringLiteral(
"transformer" ) );
718 if ( transform.isValid() )
720 QVariantMap transformerMap = transform.toMap();
727 if ( transformer->loadVariant( transformerMap.value( QStringLiteral(
"d" ) ) ) )
728 d->transformer = transformer.release();
744 return d->transformer;
752 if ( d->transformer )
755 QString baseExpression;
762 d->transformer = transformer.release();
763 if ( !fieldName.isEmpty() )
int lookupField(const QString &fieldName) const
Look 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.
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.