QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
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>RRGGBBAA</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>" );
172 mHelpText = QObject::tr(
"DateTime or string representation of a DateTime" );
182 , mDescription( description )
184 , mHelpText( helpText )
186 , mComment( comment )
195 QString QgsPropertyDefinition::trString()
198 return QObject::tr(
"string " );
207 d =
new QgsPropertyPrivate();
248 return d->active == other.d->active
249 && d->type == other.d->type
250 && ( d->type !=
StaticProperty || d->staticValue == other.d->staticValue )
253 && ( ( !d->transformer && !other.d->transformer ) || ( d->transformer && other.d->transformer && d->transformer->toExpression( QString() ) == other.d->transformer->toExpression( QString() ) ) );
258 return ( !( ( *
this ) == other ) );
263 return static_cast< Type >( d->type );
281 d->staticValue =
value;
289 return d->staticValue;
296 d->fieldName =
field;
297 d->cachedFieldIdx = -1;
308 QgsProperty::operator bool()
const
310 return d->type != InvalidProperty;
317 d->expressionString = expression;
319 d->expressionPrepared =
false;
320 d->expressionIsInvalid =
false;
328 return d->expressionString;
346 exp = d->expressionString;
353 return d->transformer ? d->transformer->toExpression( exp ) : exp;
378 if ( !d->expression.prepare( &context ) )
380 d->expressionReferencedCols.clear();
381 d->expressionPrepared =
false;
382 d->expressionIsInvalid =
true;
386 d->expressionPrepared =
true;
387 d->expressionIsInvalid =
false;
388 d->expressionReferencedCols = d->expression.referencedColumns();
403 return QSet<QString>();
409 return QSet<QString>();
413 QSet< QString > fields;
414 if ( !d->fieldName.isEmpty() )
415 fields.insert( d->fieldName );
423 return d->expression.referencedColumns();
426 if ( d->expressionIsInvalid )
427 return QSet< QString >();
430 if ( !d->expressionPrepared && !
prepare( context ) )
432 d->expressionIsInvalid =
true;
433 return QSet< QString >();
436 return d->expressionReferencedCols;
440 return QSet<QString>();
445 QRegularExpression rx( QStringLiteral(
"^project_color\\('.*'\\)$" ) );
447 && rx.match( d->expressionString ).hasMatch();
450 QVariant QgsProperty::propertyValue(
const QgsExpressionContext &context,
const QVariant &defaultValue,
bool *ok )
const
464 return d->staticValue;
474 if ( d->cachedFieldIdx >= 0 )
481 if ( d->cachedFieldIdx < 0 )
491 if ( d->expressionIsInvalid )
494 if ( !d->expressionPrepared && !
prepare( context ) )
497 QVariant result = d->expression.evaluate( &context );
498 if ( result.isValid() )
525 QVariant val = propertyValue( context, defaultValue, &valOk );
526 if ( !d->transformer && !valOk )
529 if ( d->transformer )
533 val = d->transformer->transform( context, val );
545 QVariant val =
value( context, defaultDateTime, &valOk );
547 if ( !valOk || !val.isValid() )
548 return defaultDateTime;
551 if ( val.type() == QVariant::DateTime )
553 dateTime = val.value<QDateTime>();
557 dateTime = val.toDateTime();
560 if ( !dateTime.isValid() )
561 return defaultDateTime;
573 QVariant val =
value( context, defaultString, &valOk );
575 if ( !valOk || !val.isValid() )
579 return defaultString;
585 return val.toString();
595 QVariant val =
value( context, defaultColor, &valOk );
597 if ( !valOk || !val.isValid() )
601 if ( val.type() == QVariant::Color )
603 color = val.value<QColor>();
610 if ( !color.isValid() )
626 QVariant val =
value( context, defaultValue, &valOk );
628 if ( !valOk || !val.isValid() )
631 bool convertOk =
false;
632 double dbl = val.toDouble( &convertOk );
649 QVariant val =
value( context, defaultValue, &valOk );
651 if ( !valOk || !val.isValid() )
654 bool convertOk =
false;
655 int integer = val.toInt( &convertOk );
659 double dbl = val.toDouble( &convertOk );
664 return std::round( dbl );
685 QVariant val =
value( context, defaultValue, &valOk );
687 if ( !valOk || !val.isValid() || val.isNull() )
697 QVariantMap propertyMap;
699 propertyMap.insert( QStringLiteral(
"active" ), d->active );
700 propertyMap.insert( QStringLiteral(
"type" ), d->type );
706 propertyMap.insert( QStringLiteral(
"val" ), d->staticValue.toString() );
710 propertyMap.insert( QStringLiteral(
"field" ), d->fieldName );
714 propertyMap.insert( QStringLiteral(
"expression" ), d->expressionString );
721 if ( d->transformer )
724 transformer.insert( QStringLiteral(
"t" ), d->transformer->transformerType() );
725 transformer.insert( QStringLiteral(
"d" ), d->transformer->toVariant() );
727 propertyMap.insert( QStringLiteral(
"transformer" ),
transformer );
735 QVariantMap propertyMap =
property.toMap();
738 d->active = propertyMap.value( QStringLiteral(
"active" ) ).toBool();
739 d->type =
static_cast< Type >( propertyMap.value( QStringLiteral(
"type" ),
InvalidProperty ).toInt() );
744 d->staticValue = propertyMap.value( QStringLiteral(
"val" ) );
749 d->fieldName = propertyMap.value( QStringLiteral(
"field" ) ).toString();
750 if ( d->fieldName.isEmpty() )
755 d->expressionString = propertyMap.value( QStringLiteral(
"expression" ) ).toString();
756 if ( d->expressionString.isEmpty() )
760 d->expressionPrepared =
false;
761 d->expressionIsInvalid =
false;
762 d->expressionReferencedCols.clear();
771 delete d->transformer;
772 d->transformer =
nullptr;
775 QVariant transform = propertyMap.value( QStringLiteral(
"transformer" ) );
777 if ( transform.isValid() )
779 QVariantMap transformerMap = transform.toMap();
803 return d->transformer;
811 if ( d->transformer )
814 QString baseExpression;
822 if ( !fieldName.isEmpty() )
@ RenderUnits
Render units (eg mm/pixels/map units)
void setTransformer(QgsPropertyTransformer *transformer)
Sets an optional transformer to use for manipulating the calculated values for the property.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool isActive() const
Returns whether the property is currently active.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
bool operator==(const QgsProperty &other) const
StandardPropertyTemplate
Predefined standard property templates.
A store for object properties.
@ HorizontalAnchor
Horizontal anchor point.
QgsProperty & operator=(const QgsProperty &other)
@ DataTypeString
Property requires a string value.
@ FieldBasedProperty
Field based property (QgsFieldBasedProperty)
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
@ IntegerPositiveGreaterZero
Non-zero positive integer values.
@ DataTypeBoolean
Property requires a boolean value.
@ FillStyle
Fill style (eg solid, lines)
@ DataTypeNumeric
Property requires a numeric value.
@ Double
Double value (including negative values)
@ PenJoinStyle
Pen join style.
bool isProjectColor() const
Returns true if the property is set to a linked project color.
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
Type propertyType() const
Returns the property type.
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.
bool loadVariant(const QVariant &property)
Loads this property from a QVariantMap, wrapped in a QVariant.
@ DateTime
DateTime value.
const QgsPropertyTransformer * transformer() const
Returns the existing transformer used for manipulating the calculated values for the property,...
static QColor decodeColor(const QString &str)
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...
QgsFields fields() const
Convenience function for retrieving the fields for the context, if set.
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.
@ String
Any string value.
QString expressionString() const
Returns the expression used for the property value.
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required.
@ Rotation
Rotation (value between 0-360 degrees)
static QgsProperty fromValue(const QVariant &value, bool isActive=true)
Returns a new StaticProperty created from the specified value.
bool convertToTransformer()
Attempts to convert an existing expression based property to a base expression with corresponding tra...
@ ExpressionBasedProperty
Expression based property (QgsExpressionBasedProperty)
DataType
Valid data types required by property.
QVariant toVariant() const
Saves this property to a QVariantMap, wrapped in a QVariant.
void setField(const QString &field)
Sets the field name the property references.
bool isValid() const
Returns the validity of this feature.
@ VerticalAnchor
Vertical anchor point.
@ ColorWithAlpha
Color with alpha channel.
@ CapStyle
Line cap style (eg round)
void setExpressionString(const QString &expression)
Sets the expression to use for the property value.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
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.
@ Double0To1
Double value between 0-1 (inclusive)
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.
@ IntegerPositive
Positive integer values (including 0)
@ Size
1D size (eg marker radius, or square marker height/width)
bool operator!=(const QgsProperty &other) const
@ LineStyle
Line style (eg solid/dashed)
@ Size2D
2D size (width/height different)
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
QString field() const
Returns the current field name the property references.
@ Integer
Integer value (including negative values)
void setStaticValue(const QVariant &value)
Sets the static value for the property.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
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.
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.
bool supportsAssistant() const
Returns true if the property is of a type which is compatible with property override assistants.
@ SvgPath
Path to an SVG file.
QVariant staticValue() const
Returns the current static value for the property.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const
Prepares the property against a specified expression context.
QgsPropertyDefinition()=default
Constructs an empty property.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
@ StaticProperty
Static property (QgsStaticProperty)
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.
@ StrokeWidth
Line stroke width.
@ ColorNoAlpha
Color with no alpha channel.
@ InvalidProperty
Invalid (not set) property.
@ Custom
Custom property types.
@ DoublePositive
Positive double value (including 0)