QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
qgsproperty.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsproperty.cpp
3  ---------------
4  Date : January 2017
5  Copyright : (C) 2017 by Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsproperty.h"
17 #include "qgsproperty_p.h"
18 
19 #include "qgslogger.h"
20 #include "qgsexpression.h"
21 #include "qgsfeature.h"
22 #include "qgssymbollayerutils.h"
23 #include "qgscolorramp.h"
24 
25 QgsPropertyDefinition::QgsPropertyDefinition( const QString &name, const QString &description, QgsPropertyDefinition::StandardPropertyTemplate type, const QString &origin, const QString &comment )
26  : mName( name )
27  , mDescription( description )
28  , mStandardType( type )
29  , mOrigin( origin )
30  , mComment( comment )
31 {
32  switch ( mStandardType )
33  {
34  case Boolean:
35  mTypes = DataTypeBoolean;
36  mHelpText = QObject::tr( "bool [<b>1</b>=True|<b>0</b>=False]" );
37  break;
38 
39  case Integer:
40  mTypes = DataTypeNumeric;
41  mHelpText = QObject::tr( "int [&lt;= 0 =&gt;]" );
42  break;
43 
44  case IntegerPositive:
45  mTypes = DataTypeNumeric;
46  mHelpText = QObject::tr( "int [&gt;= 0]" );
47  break;
48 
50  mTypes = DataTypeNumeric;
51  mHelpText = QObject::tr( "int [&gt;= 1]" );
52  break;
53 
54  case Double:
55  mTypes = DataTypeNumeric;
56  mHelpText = QObject::tr( "double [&lt;= 0.0 =&gt;]" );
57  break;
58 
59  case DoublePositive:
60  mTypes = DataTypeNumeric;
61  mHelpText = QObject::tr( "double [&gt;= 0.0]" );
62  break;
63 
64  case Double0To1:
65  mTypes = DataTypeNumeric;
66  mHelpText = QObject::tr( "double [0.0-1.0]" );
67  break;
68 
69  case Rotation:
70  mTypes = DataTypeNumeric;
71  mHelpText = QObject::tr( "double [0.0-360.0]" );
72  break;
73 
74  case String:
75  mTypes = DataTypeString;
76  mHelpText = QObject::tr( "string of variable length" );
77  break;
78 
79  case Opacity:
80  mTypes = DataTypeNumeric;
81  mHelpText = QObject::tr( "int [0-100]" );
82  break;
83 
84  case RenderUnits:
85  mTypes = DataTypeString;
86  mHelpText = trString() + QStringLiteral( "[<b>MM</b>|<b>MapUnit</b>|<b>Pixel</b>|<b>Point</b>]" );
87  break;
88 
89  case ColorWithAlpha:
90  mTypes = DataTypeString;
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" );
92  break;
93 
94  case ColorNoAlpha:
95  mTypes = DataTypeString;
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" );
97  break;
98 
99  case PenJoinStyle:
100  mTypes = DataTypeString;
101  mHelpText = trString() + QStringLiteral( "[<b>bevel</b>|<b>miter</b>|<b>round</b>]" );
102  break;
103 
104  case BlendMode:
105  mTypes = DataTypeString;
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>]" );
109  break;
110 
111  case Point:
112  mTypes = DataTypeString;
113  mHelpText = QObject::tr( "double coord [<b>X,Y</b>]" );
114  break;
115 
116  case Size:
117  mTypes = DataTypeNumeric;
118  mHelpText = QObject::tr( "double [&gt;= 0.0]" );
119  break;
120 
121  case Size2D:
122  mTypes = DataTypeString;
123  mHelpText = QObject::tr( "string of doubles '<b>width,height</b>' or array of doubles <b>[width, height]</b>" );
124  break;
125 
126  case LineStyle:
127  mTypes = DataTypeString;
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>]" );
129  break;
130 
131  case StrokeWidth:
132  mTypes = DataTypeNumeric;
133  mHelpText = QObject::tr( "double [&gt;= 0.0]" );
134  break;
135 
136  case FillStyle:
137  mTypes = DataTypeString;
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]" );
141  break;
142 
143  case CapStyle:
144  mTypes = DataTypeString;
145  mHelpText = trString() + QStringLiteral( "[<b>square</b>|<b>flat</b>|<b>round</b>]" );
146  break;
147 
148  case HorizontalAnchor:
149  mTypes = DataTypeString;
150  mHelpText = trString() + QStringLiteral( "[<b>left</b>|<b>center</b>|<b>right</b>]" );
151  break;
152 
153  case VerticalAnchor:
154  mTypes = DataTypeString;
155  mHelpText = trString() + QStringLiteral( "[<b>top</b>|<b>center</b>|<b>bottom</b>]" );
156  break;
157 
158  case SvgPath:
159  mTypes = DataTypeString;
160  mHelpText = trString() + QStringLiteral( "[<b>filepath</b>] as<br>"
161  "<b>''</b>=empty|absolute|search-paths-relative|<br>"
162  "project-relative|URL" );
163  break;
164 
165  case Offset:
166  mTypes = DataTypeString;
167  mHelpText = QObject::tr( "string of doubles '<b>x,y</b>' or array of doubles <b>[x, y]</b>" );
168  break;
169 
170  case Custom:
171  mTypes = DataTypeString;
172  }
173 }
174 
175 QgsPropertyDefinition::QgsPropertyDefinition( const QString &name, DataType dataType, const QString &description, const QString &helpText, const QString &origin, const QString &comment )
176  : mName( name )
177  , mDescription( description )
178  , mTypes( dataType )
179  , mHelpText( helpText )
180  , mOrigin( origin )
181  , mComment( comment )
182 {}
183 
185 {
186  return mTypes == DataTypeNumeric || mStandardType == Size || mStandardType == StrokeWidth || mStandardType == ColorNoAlpha || mStandardType == ColorWithAlpha
187  || mStandardType == Rotation;
188 }
189 
190 QString QgsPropertyDefinition::trString()
191 {
192  // just something to reduce translation redundancy
193  return QObject::tr( "string " );
194 }
195 
196 //
197 // QgsProperty
198 //
199 
201 {
202  d = new QgsPropertyPrivate();
203 }
204 
205 QgsProperty::~QgsProperty() = default;
206 
207 QgsProperty QgsProperty::fromExpression( const QString &expression, bool isActive )
208 {
209  QgsProperty p;
210  p.setExpressionString( expression );
211  p.setActive( isActive );
212  return p;
213 }
214 
215 QgsProperty QgsProperty::fromField( const QString &fieldName, bool isActive )
216 {
217  QgsProperty p;
218  p.setField( fieldName );
219  p.setActive( isActive );
220  return p;
221 }
222 
223 QgsProperty QgsProperty::fromValue( const QVariant &value, bool isActive )
224 {
225  QgsProperty p;
226  p.setStaticValue( value );
227  p.setActive( isActive );
228  return p;
229 }
230 
231 QgsProperty::QgsProperty( const QgsProperty &other ) //NOLINT
232  : d( other.d )
233 {}
234 
236 {
237  d = other.d;
238  return *this;
239 }
240 
241 bool QgsProperty::operator==( const QgsProperty &other ) const
242 {
243  return d->active == other.d->active
244  && d->type == other.d->type
245  && ( d->type != StaticProperty || d->staticValue == other.d->staticValue )
246  && ( d->type != FieldBasedProperty || d->fieldName == other.d->fieldName )
247  && ( d->type != ExpressionBasedProperty || d->expressionString == other.d->expressionString )
248  && ( ( !d->transformer && !other.d->transformer ) || ( d->transformer && other.d->transformer && d->transformer->toExpression( QString() ) == other.d->transformer->toExpression( QString() ) ) );
249 }
250 
251 bool QgsProperty::operator!=( const QgsProperty &other ) const
252 {
253  return ( !( ( *this ) == other ) );
254 }
255 
257 {
258  return static_cast< Type >( d->type );
259 }
260 
262 {
263  return d->type != InvalidProperty && d->active;
264 }
265 
266 void QgsProperty::setActive( bool active )
267 {
268  d.detach();
269  d->active = active;
270 }
271 
272 void QgsProperty::setStaticValue( const QVariant &value )
273 {
274  d.detach();
275  d->type = StaticProperty;
276  d->staticValue = value;
277 }
278 
279 QVariant QgsProperty::staticValue() const
280 {
281  if ( d->type != StaticProperty )
282  return QVariant();
283 
284  return d->staticValue;
285 }
286 
287 void QgsProperty::setField( const QString &field )
288 {
289  d.detach();
290  d->type = FieldBasedProperty;
291  d->fieldName = field;
292  d->cachedFieldIdx = -1;
293 }
294 
295 QString QgsProperty::field() const
296 {
297  if ( d->type != FieldBasedProperty )
298  return QString();
299 
300  return d->fieldName;
301 }
302 
303 QgsProperty::operator bool() const
304 {
305  return d->type != InvalidProperty;
306 }
307 
308 void QgsProperty::setExpressionString( const QString &expression )
309 {
310  d.detach();
311  d->type = ExpressionBasedProperty;
312  d->expressionString = expression;
313  d->expression = QgsExpression( expression );
314  d->expressionPrepared = false;
315  d->expressionIsInvalid = false;
316 }
317 
319 {
320  if ( d->type != ExpressionBasedProperty )
321  return QString();
322 
323  return d->expressionString;
324 }
325 
326 
328 {
329  QString exp;
330  switch ( d->type )
331  {
332  case StaticProperty:
333  exp = QgsExpression::quotedValue( d->staticValue );
334  break;
335 
336  case FieldBasedProperty:
337  exp = QgsExpression::quotedColumnRef( d->fieldName );
338  break;
339 
341  exp = d->expressionString;
342  break;
343 
344  case InvalidProperty:
345  exp = QString();
346  break;
347  }
348  return d->transformer ? d->transformer->toExpression( exp ) : exp;
349 }
350 
351 bool QgsProperty::prepare( const QgsExpressionContext &context ) const
352 {
353  if ( !d->active )
354  return true;
355 
356  switch ( d->type )
357  {
358  case StaticProperty:
359  return true;
360 
361  case FieldBasedProperty:
362  {
363  d.detach();
364  // cache field index to avoid subsequent lookups
365  QgsFields f = context.fields();
366  d->cachedFieldIdx = f.lookupField( d->fieldName );
367  return true;
368  }
369 
371  {
372  d.detach();
373  if ( !d->expression.prepare( &context ) )
374  {
375  d->expressionReferencedCols.clear();
376  d->expressionPrepared = false;
377  d->expressionIsInvalid = true;
378  return false;
379  }
380 
381  d->expressionPrepared = true;
382  d->expressionIsInvalid = false;
383  d->expressionReferencedCols = d->expression.referencedColumns();
384  return true;
385  }
386 
387  case InvalidProperty:
388  return true;
389 
390  }
391 
392  return false;
393 }
394 
395 QSet<QString> QgsProperty::referencedFields( const QgsExpressionContext &context ) const
396 {
397  if ( !d->active )
398  return QSet<QString>();
399 
400  switch ( d->type )
401  {
402  case StaticProperty:
403  case InvalidProperty:
404  return QSet<QString>();
405 
406  case FieldBasedProperty:
407  {
408  QSet< QString > fields;
409  if ( !d->fieldName.isEmpty() )
410  fields.insert( d->fieldName );
411  return fields;
412  }
413 
415  {
416  if ( d->expressionIsInvalid )
417  return QSet< QString >();
418 
419  d.detach();
420  if ( !d->expressionPrepared && !prepare( context ) )
421  {
422  d->expressionIsInvalid = true;
423  return QSet< QString >();
424  }
425 
426  return d->expressionReferencedCols;
427  }
428 
429  }
430  return QSet<QString>();
431 }
432 
434 {
435  QRegularExpression rx( QStringLiteral( "^project_color\\('.*'\\)$" ) );
436  return d->type == QgsProperty::ExpressionBasedProperty && !d->expressionString.isEmpty()
437  && rx.match( d->expressionString ).hasMatch();
438 }
439 
440 QVariant QgsProperty::propertyValue( const QgsExpressionContext &context, const QVariant &defaultValue, bool *ok ) const
441 {
442  if ( ok )
443  *ok = false;
444 
445  if ( !d->active )
446  return defaultValue;
447 
448  switch ( d->type )
449  {
450  case StaticProperty:
451  {
452  if ( ok )
453  *ok = true;
454  return d->staticValue;
455  }
456 
457  case FieldBasedProperty:
458  {
459  QgsFeature f = context.feature();
460  if ( !f.isValid() )
461  return defaultValue;
462 
463  //shortcut the field lookup
464  if ( d->cachedFieldIdx >= 0 )
465  {
466  if ( ok )
467  *ok = true;
468  return f.attribute( d->cachedFieldIdx );
469  }
470  prepare( context );
471  if ( d->cachedFieldIdx < 0 )
472  return defaultValue;
473 
474  if ( ok )
475  *ok = true;
476  return f.attribute( d->cachedFieldIdx );
477  }
478 
480  {
481  if ( d->expressionIsInvalid )
482  return defaultValue;
483 
484  if ( !d->expressionPrepared && !prepare( context ) )
485  return defaultValue;
486 
487  QVariant result = d->expression.evaluate( &context );
488  if ( result.isValid() )
489  {
490  if ( ok )
491  *ok = true;
492  return result;
493  }
494  else
495  {
496  return defaultValue;
497  }
498  }
499 
500  case InvalidProperty:
501  return defaultValue;
502 
503  }
504 
505  return QVariant();
506 }
507 
508 
509 QVariant QgsProperty::value( const QgsExpressionContext &context, const QVariant &defaultValue, bool *ok ) const
510 {
511  if ( ok )
512  *ok = false;
513 
514  bool valOk = false;
515  QVariant val = propertyValue( context, defaultValue, &valOk );
516  if ( !d->transformer && !valOk ) // if transformer present, let it handle null values
517  return defaultValue;
518 
519  if ( d->transformer )
520  {
521  if ( !valOk )
522  val = QVariant();
523  val = d->transformer->transform( context, val );
524  }
525 
526  if ( ok )
527  *ok = true;
528 
529  return val;
530 }
531 
532 QString QgsProperty::valueAsString( const QgsExpressionContext &context, const QString &defaultString, bool *ok ) const
533 {
534  bool valOk = false;
535  QVariant val = value( context, defaultString, &valOk );
536 
537  if ( !valOk || !val.isValid() )
538  {
539  if ( ok )
540  *ok = false;
541  return defaultString;
542  }
543  else
544  {
545  if ( ok )
546  *ok = true;
547  return val.toString();
548  }
549 }
550 
551 QColor QgsProperty::valueAsColor( const QgsExpressionContext &context, const QColor &defaultColor, bool *ok ) const
552 {
553  if ( ok )
554  *ok = false;
555 
556  bool valOk = false;
557  QVariant val = value( context, defaultColor, &valOk );
558 
559  if ( !valOk || !val.isValid() )
560  return defaultColor;
561 
562  QColor color;
563  if ( val.type() == QVariant::Color )
564  {
565  color = val.value<QColor>();
566  }
567  else
568  {
569  color = QgsSymbolLayerUtils::decodeColor( val.toString() );
570  }
571 
572  if ( !color.isValid() )
573  return defaultColor;
574  else
575  {
576  if ( ok )
577  *ok = true;
578  return color;
579  }
580 }
581 
582 double QgsProperty::valueAsDouble( const QgsExpressionContext &context, double defaultValue, bool *ok ) const
583 {
584  if ( ok )
585  *ok = false;
586 
587  bool valOk = false;
588  QVariant val = value( context, defaultValue, &valOk );
589 
590  if ( !valOk || !val.isValid() )
591  return defaultValue;
592 
593  bool convertOk = false;
594  double dbl = val.toDouble( &convertOk );
595  if ( !convertOk )
596  return defaultValue;
597  else
598  {
599  if ( ok )
600  *ok = true;
601  return dbl;
602  }
603 }
604 
605 int QgsProperty::valueAsInt( const QgsExpressionContext &context, int defaultValue, bool *ok ) const
606 {
607  if ( ok )
608  *ok = false;
609 
610  bool valOk = false;
611  QVariant val = value( context, defaultValue, &valOk );
612 
613  if ( !valOk || !val.isValid() )
614  return defaultValue;
615 
616  bool convertOk = false;
617  int integer = val.toInt( &convertOk );
618  if ( !convertOk )
619  {
620  //one more option to try
621  double dbl = val.toDouble( &convertOk );
622  if ( convertOk )
623  {
624  if ( ok )
625  *ok = true;
626  return std::round( dbl );
627  }
628  else
629  {
630  return defaultValue;
631  }
632  }
633  else
634  {
635  if ( ok )
636  *ok = true;
637  return integer;
638  }
639 }
640 
641 bool QgsProperty::valueAsBool( const QgsExpressionContext &context, bool defaultValue, bool *ok ) const
642 {
643  if ( ok )
644  *ok = false;
645 
646  bool valOk = false;
647  QVariant val = value( context, defaultValue, &valOk );
648 
649  if ( !valOk || !val.isValid() || val.isNull() )
650  return defaultValue;
651 
652  if ( ok )
653  *ok = true;
654  return val.toBool();
655 }
656 
657 QVariant QgsProperty::toVariant() const
658 {
659  QVariantMap propertyMap;
660 
661  propertyMap.insert( QStringLiteral( "active" ), d->active );
662  propertyMap.insert( QStringLiteral( "type" ), d->type );
663 
664  switch ( d->type )
665  {
666  case StaticProperty:
667  // propertyMap.insert( QStringLiteral( "valType" ), d->staticValue.typeName() );
668  propertyMap.insert( QStringLiteral( "val" ), d->staticValue.toString() );
669  break;
670 
671  case FieldBasedProperty:
672  propertyMap.insert( QStringLiteral( "field" ), d->fieldName );
673  break;
674 
676  propertyMap.insert( QStringLiteral( "expression" ), d->expressionString );
677  break;
678 
679  case InvalidProperty:
680  break;
681  }
682 
683  if ( d->transformer )
684  {
685  QVariantMap transformer;
686  transformer.insert( QStringLiteral( "t" ), d->transformer->transformerType() );
687  transformer.insert( QStringLiteral( "d" ), d->transformer->toVariant() );
688 
689  propertyMap.insert( QStringLiteral( "transformer" ), transformer );
690  }
691 
692  return propertyMap;
693 }
694 
695 bool QgsProperty::loadVariant( const QVariant &property )
696 {
697  QVariantMap propertyMap = property.toMap();
698 
699  d.detach();
700  d->active = propertyMap.value( QStringLiteral( "active" ) ).toBool();
701  d->type = static_cast< Type >( propertyMap.value( QStringLiteral( "type" ), InvalidProperty ).toInt() );
702 
703  switch ( d->type )
704  {
705  case StaticProperty:
706  d->staticValue = propertyMap.value( QStringLiteral( "val" ) );
707  // d->staticValue.convert( QVariant::nameToType( propertyElem.attribute( "valType", "QString" ).toLocal8Bit().constData() ) );
708  break;
709 
710  case FieldBasedProperty:
711  d->fieldName = propertyMap.value( QStringLiteral( "field" ) ).toString();
712  if ( d->fieldName.isEmpty() )
713  d->active = false;
714  break;
715 
717  d->expressionString = propertyMap.value( QStringLiteral( "expression" ) ).toString();
718  if ( d->expressionString.isEmpty() )
719  d->active = false;
720 
721  d->expression = QgsExpression( d->expressionString );
722  d->expressionPrepared = false;
723  d->expressionIsInvalid = false;
724  d->expressionReferencedCols.clear();
725  break;
726 
727  case InvalidProperty:
728  break;
729 
730  }
731 
732  //restore transformer if present
733  delete d->transformer;
734  d->transformer = nullptr;
735 
736 
737  QVariant transform = propertyMap.value( QStringLiteral( "transformer" ) );
738 
739  if ( transform.isValid() )
740  {
741  QVariantMap transformerMap = transform.toMap();
742 
743  QgsPropertyTransformer::Type type = static_cast< QgsPropertyTransformer::Type >( transformerMap.value( QStringLiteral( "t" ), QgsPropertyTransformer::GenericNumericTransformer ).toInt() );
744  std::unique_ptr< QgsPropertyTransformer > transformer( QgsPropertyTransformer::create( type ) );
745 
746  if ( transformer )
747  {
748  if ( transformer->loadVariant( transformerMap.value( QStringLiteral( "d" ) ) ) )
749  d->transformer = transformer.release();
750  }
751  }
752 
753  return true;
754 }
755 
756 
758 {
759  d.detach();
760  d->transformer = transformer;
761 }
762 
764 {
765  return d->transformer;
766 }
767 
769 {
770  if ( d->type != ExpressionBasedProperty )
771  return false;
772 
773  if ( d->transformer )
774  return false; // already a transformer
775 
776  QString baseExpression;
777  QString fieldName;
778  std::unique_ptr< QgsPropertyTransformer > transformer( QgsPropertyTransformer::fromExpression( d->expressionString, baseExpression, fieldName ) );
779  if ( !transformer )
780  return false;
781 
782  d.detach();
783  d->transformer = transformer.release();
784  if ( !fieldName.isEmpty() )
785  setField( fieldName );
786  else
787  setExpressionString( baseExpression );
788  return true;
789 }
790 
791 
792 
int lookupField(const QString &fieldName) const
Looks up field&#39;s index from the field name.
Definition: qgsfields.cpp:324
bool operator==(const QgsProperty &other) const
Render units (eg mm/pixels/map units)
Definition: qgsproperty.h:63
bool isValid() const
Returns the validity of this feature.
Definition: qgsfeature.cpp:183
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)
Definition: qgsproperty.h:238
Positive integer values (including 0)
Definition: qgsproperty.h:55
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)
Definition: qgsproperty.h:69
Invalid (not set) property.
Definition: qgsproperty.h:236
Expression based property (QgsExpressionBasedProperty)
Definition: qgsproperty.h:239
Abstract base class for objects which transform the calculated value of a property.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
Non-zero positive integer values.
Definition: qgsproperty.h:56
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.
Definition: qgsfields.h:42
Color with alpha channel.
Definition: qgsproperty.h:64
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...
static QgsPropertyTransformer * create(Type type)
Factory method for creating a new property transformer of the specified type.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
Positive double value (including 0)
Definition: qgsproperty.h:58
Rotation (value between 0-360 degrees)
Definition: qgsproperty.h:60
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.
static QgsPropertyTransformer * fromExpression(const QString &expression, QString &baseExpression, QString &fieldName)
Attempts to parse an expression into a corresponding property transformer.
Any string value.
Definition: qgsproperty.h:61
const QgsPropertyTransformer * transformer() const
Returns the existing transformer used for manipulating the calculated values for the property...
Type
Property types.
Definition: qgsproperty.h:234
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.
Definition: qgsproperty.h:187
Integer value (including negative values)
Definition: qgsproperty.h:54
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.
Definition: qgsproperty.h:105
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.
Definition: qgsproperty.h:162
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.
Definition: qgsproperty.h:98
bool operator!=(const QgsProperty &other) const
A store for object properties.
Definition: qgsproperty.h:229
Fill style (eg solid, lines)
Definition: qgsproperty.h:73
Double value (including negative values)
Definition: qgsproperty.h:57
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...
Definition: qgsproperty.h:177
DataType
Valid data types required by property.
Definition: qgsproperty.h:83
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.
Definition: qgsproperty.h:167
Generic transformer for numeric values (QgsGenericNumericTransformer)
virtual ~QgsProperty()
Property requires a string value.
Definition: qgsproperty.h:91
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)
Definition: qgsproperty.h:71
QVariant staticValue() const
Returns the current static value for the property.
Horizontal anchor point.
Definition: qgsproperty.h:75
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
StandardPropertyTemplate
Predefined standard property templates.
Definition: qgsproperty.h:51
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required...
Path to an SVG file.
Definition: qgsproperty.h:77
Line cap style (eg round)
Definition: qgsproperty.h:74
QString name() const
Returns the name of the property.
Definition: qgsproperty.h:138
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Definition: qgsfeature.cpp:262
Static property (QgsStaticProperty)
Definition: qgsproperty.h:237
void setStaticValue(const QVariant &value)
Sets the static value for the property.
QString origin() const
Returns the origin of the property.
Definition: qgsproperty.h:150
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)
Definition: qgsproperty.h:70
static QColor decodeColor(const QString &str)
Custom property types.
Definition: qgsproperty.h:79
Color with no alpha channel.
Definition: qgsproperty.h:65
Double value between 0-1 (inclusive)
Definition: qgsproperty.h:59
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const
Prepares the property against a specified expression context.