23#include <QRegularExpression> 
   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>" );
 
  172      mHelpText = QObject::tr( 
"DateTime or string representation of a DateTime" );
 
 
  182  , mDescription( description )
 
  184  , mHelpText( helpText )
 
  186  , mComment( comment )
 
 
  195QString QgsPropertyDefinition::trString()
 
  198  return QObject::tr( 
"string " );
 
  207  QVariantMap variantMap;
 
  208  QMap<QString, QgsProperty>::const_iterator it = propertyMap.constBegin();
 
  209  for ( ; it != propertyMap.constEnd(); ++it )
 
  210    variantMap.insert( it.key(), it.value().toVariant() );
 
 
  216  QMap<QString, QgsProperty> propertyMap;
 
  217  QVariantMap::const_iterator it = variantMap.constBegin();
 
  218  for ( ; it != variantMap.constEnd(); ++it )
 
  222      propertyMap.insert( it.key(), property );
 
 
  229  d = 
new QgsPropertyPrivate();
 
 
  270  return d->active == other.d->active
 
  271         && d->type == other.d->type
 
  275         && ( ( !d->transformer && !other.d->transformer ) || ( d->transformer && other.d->transformer && d->transformer->toExpression( QString() ) == other.d->transformer->toExpression( QString() ) ) );
 
 
  280  return ( !( ( *
this ) == other ) );
 
 
  335  d->staticValue = 
value;
 
 
  343  return d->staticValue;
 
 
  350  d->fieldName = 
field;
 
  351  d->cachedFieldIdx = -1;
 
 
  362QgsProperty::operator bool()
 const 
 
  370  d->expressionString = expression;
 
  372  d->expressionPrepared = 
false;
 
  373  d->expressionIsInvalid = 
false;
 
  375  if ( d->expressionString.isEmpty() )
 
 
  391  return d->expressionString;
 
 
  409      exp = d->expressionString;
 
  416  return d->transformer ? d->transformer->toExpression( exp ) : exp;
 
 
  441      if ( !d->expression.prepare( &context ) )
 
  443        d->expressionReferencedCols.clear();
 
  444        d->expressionPrepared = 
false;
 
  445        d->expressionIsInvalid = 
true;
 
  449      d->expressionPrepared = 
true;
 
  450      d->expressionIsInvalid = 
false;
 
  451      d->expressionReferencedCols = d->expression.referencedColumns();
 
 
  466    return QSet<QString>();
 
  472      return QSet<QString>();
 
  476      QSet< QString > fields;
 
  477      if ( !d->fieldName.isEmpty() )
 
  478        fields.insert( d->fieldName );
 
  486        return d->expression.referencedColumns();
 
  489      if ( d->expressionIsInvalid )
 
  490        return QSet< QString >();
 
  493      if ( !d->expressionPrepared && !
prepare( context ) )
 
  495        d->expressionIsInvalid = 
true;
 
  496        return QSet< QString >();
 
  499      return d->expressionReferencedCols;
 
  503  return QSet<QString>();
 
 
  508  const thread_local QRegularExpression rx( QStringLiteral( 
"^project_color(_object|)\\('.*'\\)$" ) );
 
  510         && rx.match( d->expressionString ).hasMatch();
 
 
  513QVariant QgsProperty::propertyValue( 
const QgsExpressionContext &context, 
const QVariant &defaultValue, 
bool *ok )
 const 
  527      return d->staticValue;
 
  537      if ( d->cachedFieldIdx >= 0 )
 
  544      if ( d->cachedFieldIdx < 0 )
 
  554      if ( d->expressionIsInvalid )
 
  557      if ( !d->expressionPrepared && !
prepare( context ) )
 
  560      QVariant result = d->expression.evaluate( &context );
 
  588  QVariant val = propertyValue( context, defaultValue, &valOk );
 
  589  if ( !d->transformer && !valOk ) 
 
  592  if ( d->transformer )
 
  596    val = d->transformer->transform( context, val );
 
 
  608  const QVariant val = 
value( context, defaultDateTime, &valOk );
 
  614    return defaultDateTime;
 
  618  if ( val.userType() == QMetaType::Type::QDateTime )
 
  620    dateTime = val.value<QDateTime>();
 
  624    dateTime = val.toDateTime();
 
  627  if ( !dateTime.isValid() )
 
  628    return defaultDateTime;
 
 
  640  const QVariant val = 
value( context, defaultString, &valOk );
 
  646    return defaultString;
 
  652    return val.toString();
 
 
  662  const QVariant val = 
value( context, defaultColor, &valOk );
 
  668  if ( val.userType() == QMetaType::Type::QColor )
 
  670    color = val.value<QColor>();
 
  677  if ( !color.isValid() )
 
 
  693  const QVariant val = 
value( context, defaultValue, &valOk );
 
  698  bool convertOk = 
false;
 
  699  const double dbl = val.toDouble( &convertOk );
 
 
  716  const QVariant val = 
value( context, defaultValue, &valOk );
 
  721  bool convertOk = 
false;
 
  722  const int integer = val.toInt( &convertOk );
 
  726    const double dbl = val.toDouble( &convertOk );
 
  731      return std::round( dbl );
 
 
  752  const QVariant val = 
value( context, defaultValue, &valOk );
 
 
  764  QVariantMap propertyMap;
 
  766  propertyMap.insert( QStringLiteral( 
"active" ), d->active );
 
  767  propertyMap.insert( QStringLiteral( 
"type" ), 
static_cast< int >( d->type ) );
 
  773      propertyMap.insert( QStringLiteral( 
"val" ), d->staticValue.toString() );
 
  777      propertyMap.insert( QStringLiteral( 
"field" ), d->fieldName );
 
  781      propertyMap.insert( QStringLiteral( 
"expression" ), d->expressionString );
 
  788  if ( d->transformer )
 
  791    transformer.insert( QStringLiteral( 
"t" ), d->transformer->transformerType() );
 
  792    transformer.insert( QStringLiteral( 
"d" ), d->transformer->toVariant() );
 
  794    propertyMap.insert( QStringLiteral( 
"transformer" ), 
transformer );
 
 
  802  const QVariantMap propertyMap = 
property.toMap();
 
  805  d->active = propertyMap.value( QStringLiteral( 
"active" ) ).toBool();
 
  811      d->staticValue = propertyMap.value( QStringLiteral( 
"val" ) );
 
  816      d->fieldName = propertyMap.value( QStringLiteral( 
"field" ) ).toString();
 
  817      if ( d->fieldName.isEmpty() )
 
  822      d->expressionString = propertyMap.value( QStringLiteral( 
"expression" ) ).toString();
 
  823      if ( d->expressionString.isEmpty() )
 
  827      d->expressionPrepared = 
false;
 
  828      d->expressionIsInvalid = 
false;
 
  829      d->expressionReferencedCols.clear();
 
  838  delete d->transformer;
 
  839  d->transformer = 
nullptr;
 
  842  const QVariant transform = propertyMap.value( QStringLiteral( 
"transformer" ) );
 
  844  if ( transform.isValid() )
 
  846    const QVariantMap transformerMap = transform.toMap();
 
 
  870  return d->transformer;
 
 
  878  if ( d->transformer )
 
  881  QString baseExpression;
 
  889  if ( !fieldName.isEmpty() )
 
 
PropertyType
Property types.
@ Invalid
Invalid (not set) property.
@ Field
Field based property.
@ Expression
Expression based property.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
QgsFields fields() const
Convenience function for retrieving the fields for the context, if set.
bool hasCachedStaticValue() const
Returns true if the node can be replaced by a static cached value.
QVariant cachedStaticValue() const
Returns the node's static cached value.
Handles parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
const QgsExpressionNode * rootNode() const
Returns the root node of the expression.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool isValid() const
Returns the validity of this feature.
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Container of fields for a vector layer.
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
StandardPropertyTemplate
Predefined standard property templates.
@ HorizontalAnchor
Horizontal anchor point.
@ Double
Double value (including negative values)
@ VerticalAnchor
Vertical anchor point.
@ Double0To1
Double value between 0-1 (inclusive)
@ FillStyle
Fill style (eg solid, lines)
@ StrokeWidth
Line stroke width.
@ LineStyle
Line style (eg solid/dashed)
@ Integer
Integer value (including negative values)
@ String
Any string value.
@ DateTime
DateTime value.
@ RenderUnits
Render units (eg mm/pixels/map units)
@ PenJoinStyle
Pen join style.
@ SvgPath
Path to an SVG file.
@ IntegerPositiveGreaterZero
Non-zero positive integer values.
@ IntegerPositive
Positive integer values (including 0)
@ CapStyle
Line cap style (eg round)
@ ColorNoAlpha
Color with no alpha channel.
@ Rotation
Rotation (value between 0-360 degrees)
@ Custom
Custom property types.
@ Size
1D size (eg marker radius, or square marker height/width)
@ ColorWithAlpha
Color with alpha channel.
@ DoublePositive
Positive double value (including 0)
@ Size2D
2D size (width/height different)
bool supportsAssistant() const
Returns true if the property is of a type which is compatible with property override assistants.
QgsPropertyDefinition()=default
Constructs an empty property.
DataType
Valid data types required by property.
@ DataTypeString
Property requires a string value.
@ DataTypeBoolean
Property requires a boolean value.
@ DataTypeNumeric
Property requires a numeric value.
A store for object properties.
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.
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 isProjectColor() const
Returns true if the property is set to a linked project color.
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.
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
bool operator==(const QgsProperty &other) const
static QVariantMap propertyMapToVariantMap(const QMap< QString, QgsProperty > &propertyMap)
Convert a map of QgsProperty to a map of QVariant This is useful to save a map of properties.
QString expressionString() const
Returns the expression used for the property value.
bool convertToTransformer()
Attempts to convert an existing expression based property to a base expression with corresponding tra...
void setTransformer(QgsPropertyTransformer *transformer)
Sets an optional transformer to use for manipulating the calculated values for the property.
void setStaticValue(const QVariant &value)
Sets the static value for the property.
Qgis::PropertyType propertyType() const
Returns the property type.
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.
QString field() const
Returns the current field name the property references.
const QgsPropertyTransformer * transformer() const
Returns the existing transformer used for manipulating the calculated values for the property,...
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...
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
QVariant toVariant() const
Saves this property to a QVariantMap, wrapped in a QVariant.
bool isActive() const
Returns whether the property is currently active.
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.
static QMap< QString, QgsProperty > variantMapToPropertyMap(const QVariantMap &variantMap)
Convert a map of QVariant to a map of QgsProperty This is useful to restore a map of properties.
void setField(const QString &field)
Sets the field name the property references.
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.
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.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const
Prepares the property against a specified expression context.
bool loadVariant(const QVariant &property)
Loads this property from a QVariantMap, wrapped in a QVariant.
QVariant staticValue() const
Returns the current static value for the property.
bool operator!=(const QgsProperty &other) const
bool isStaticValueInContext(const QgsExpressionContext &context, QVariant &staticValue) const
Returns true if the property is effectively a static value in the specified context.
void setExpressionString(const QString &expression)
Sets the expression to use for the property value.
QgsProperty & operator=(const QgsProperty &other)
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
QgsProperty()
Constructor for a QgsProperty.
static QgsProperty fromValue(const QVariant &value, bool isActive=true)
Returns a new StaticProperty created from the specified value.
void setActive(bool active)
Sets whether the property is currently active.
static QColor decodeColor(const QString &str)
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.