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