QGIS API Documentation  3.0.2-Girona (307d082)
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>RRGGBBAA</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 
421 QVariant QgsProperty::propertyValue( const QgsExpressionContext &context, const QVariant &defaultValue, bool *ok ) const
422 {
423  if ( ok )
424  *ok = false;
425 
426  if ( !d->active )
427  return defaultValue;
428 
429  switch ( d->type )
430  {
431  case StaticProperty:
432  {
433  if ( ok )
434  *ok = true;
435  return d->staticValue;
436  }
437 
438  case FieldBasedProperty:
439  {
440  QgsFeature f = context.feature();
441  if ( !f.isValid() )
442  return defaultValue;
443 
444  //shortcut the field lookup
445  if ( d->cachedFieldIdx >= 0 )
446  {
447  if ( ok )
448  *ok = true;
449  return f.attribute( d->cachedFieldIdx );
450  }
451  prepare( context );
452  if ( d->cachedFieldIdx < 0 )
453  return defaultValue;
454 
455  if ( ok )
456  *ok = true;
457  return f.attribute( d->cachedFieldIdx );
458  }
459 
461  {
462  d.detach();
463  if ( !d->expressionPrepared && !prepare( context ) )
464  return defaultValue;
465 
466  QVariant result = d->expression.evaluate( &context );
467  if ( result.isValid() )
468  {
469  if ( ok )
470  *ok = true;
471  return result;
472  }
473  else
474  {
475  return defaultValue;
476  }
477  }
478 
479  case InvalidProperty:
480  return defaultValue;
481 
482  };
483 
484  return QVariant();
485 }
486 
487 
488 QVariant QgsProperty::value( const QgsExpressionContext &context, const QVariant &defaultValue, bool *ok ) const
489 {
490  if ( ok )
491  *ok = false;
492 
493  bool valOk = false;
494  QVariant val = propertyValue( context, defaultValue, &valOk );
495  if ( !d->transformer && !valOk ) // if transformer present, let it handle null values
496  return defaultValue;
497 
498  if ( d->transformer )
499  {
500  if ( !valOk )
501  val = QVariant();
502  val = d->transformer->transform( context, val );
503  }
504 
505  if ( ok )
506  *ok = true;
507 
508  return val;
509 }
510 
511 QString QgsProperty::valueAsString( const QgsExpressionContext &context, const QString &defaultString, bool *ok ) const
512 {
513  bool valOk = false;
514  QVariant val = value( context, defaultString, &valOk );
515 
516  if ( !valOk || !val.isValid() )
517  {
518  if ( ok )
519  *ok = false;
520  return defaultString;
521  }
522  else
523  {
524  if ( ok )
525  *ok = true;
526  return val.toString();
527  }
528 }
529 
530 QColor QgsProperty::valueAsColor( const QgsExpressionContext &context, const QColor &defaultColor, bool *ok ) const
531 {
532  if ( ok )
533  *ok = false;
534 
535  bool valOk = false;
536  QVariant val = value( context, defaultColor, &valOk );
537 
538  if ( !valOk || !val.isValid() )
539  return defaultColor;
540 
541  QColor color;
542  if ( val.type() == QVariant::Color )
543  {
544  color = val.value<QColor>();
545  }
546  else
547  {
548  color = QgsSymbolLayerUtils::decodeColor( val.toString() );
549  }
550 
551  if ( !color.isValid() )
552  return defaultColor;
553  else
554  {
555  if ( ok )
556  *ok = true;
557  return color;
558  }
559 }
560 
561 double QgsProperty::valueAsDouble( const QgsExpressionContext &context, double defaultValue, bool *ok ) const
562 {
563  if ( ok )
564  *ok = false;
565 
566  bool valOk = false;
567  QVariant val = value( context, defaultValue, &valOk );
568 
569  if ( !valOk || !val.isValid() )
570  return defaultValue;
571 
572  bool convertOk = false;
573  double dbl = val.toDouble( &convertOk );
574  if ( !convertOk )
575  return defaultValue;
576  else
577  {
578  if ( ok )
579  *ok = true;
580  return dbl;
581  }
582 }
583 
584 int QgsProperty::valueAsInt( const QgsExpressionContext &context, int defaultValue, bool *ok ) const
585 {
586  if ( ok )
587  *ok = false;
588 
589  bool valOk = false;
590  QVariant val = value( context, defaultValue, &valOk );
591 
592  if ( !valOk || !val.isValid() )
593  return defaultValue;
594 
595  bool convertOk = false;
596  int integer = val.toInt( &convertOk );
597  if ( !convertOk )
598  {
599  //one more option to try
600  double dbl = val.toDouble( &convertOk );
601  if ( convertOk )
602  {
603  if ( ok )
604  *ok = true;
605  return std::round( dbl );
606  }
607  else
608  {
609  return defaultValue;
610  }
611  }
612  else
613  {
614  if ( ok )
615  *ok = true;
616  return integer;
617  }
618 }
619 
620 bool QgsProperty::valueAsBool( const QgsExpressionContext &context, bool defaultValue, bool *ok ) const
621 {
622  if ( ok )
623  *ok = false;
624 
625  bool valOk = false;
626  QVariant val = value( context, defaultValue, &valOk );
627 
628  if ( !valOk || !val.isValid() || val.isNull() )
629  return defaultValue;
630 
631  if ( ok )
632  *ok = true;
633  return val.toBool();
634 }
635 
636 QVariant QgsProperty::toVariant() const
637 {
638  QVariantMap propertyMap;
639 
640  propertyMap.insert( QStringLiteral( "active" ), d->active );
641  propertyMap.insert( QStringLiteral( "type" ), d->type );
642 
643  switch ( d->type )
644  {
645  case StaticProperty:
646  // propertyMap.insert( QStringLiteral( "valType" ), d->staticValue.typeName() );
647  propertyMap.insert( QStringLiteral( "val" ), d->staticValue.toString() );
648  break;
649 
650  case FieldBasedProperty:
651  propertyMap.insert( QStringLiteral( "field" ), d->fieldName );
652  break;
653 
655  propertyMap.insert( QStringLiteral( "expression" ), d->expressionString );
656  break;
657 
658  case InvalidProperty:
659  break;
660  }
661 
662  if ( d->transformer )
663  {
664  QVariantMap transformer;
665  transformer.insert( QStringLiteral( "t" ), d->transformer->transformerType() );
666  transformer.insert( QStringLiteral( "d" ), d->transformer->toVariant() );
667 
668  propertyMap.insert( QStringLiteral( "transformer" ), transformer );
669  }
670 
671  return propertyMap;
672 }
673 
674 bool QgsProperty::loadVariant( const QVariant &property )
675 {
676  QVariantMap propertyMap = property.toMap();
677 
678  d.detach();
679  d->active = propertyMap.value( QStringLiteral( "active" ) ).toBool();
680  d->type = static_cast< Type >( propertyMap.value( QStringLiteral( "type" ), InvalidProperty ).toInt() );
681 
682  switch ( d->type )
683  {
684  case StaticProperty:
685  d->staticValue = propertyMap.value( QStringLiteral( "val" ) );
686  // d->staticValue.convert( QVariant::nameToType( propertyElem.attribute( "valType", "QString" ).toLocal8Bit().constData() ) );
687  break;
688 
689  case FieldBasedProperty:
690  d->fieldName = propertyMap.value( QStringLiteral( "field" ) ).toString();
691  if ( d->fieldName.isEmpty() )
692  d->active = false;
693  break;
694 
696  d->expressionString = propertyMap.value( QStringLiteral( "expression" ) ).toString();
697  if ( d->expressionString.isEmpty() )
698  d->active = false;
699 
700  d->expression = QgsExpression( d->expressionString );
701  d->expressionPrepared = false;
702  d->expressionReferencedCols.clear();
703  break;
704 
705  case InvalidProperty:
706  break;
707 
708  }
709 
710  //restore transformer if present
711  if ( d->transformer )
712  delete d->transformer;
713  d->transformer = nullptr;
714 
715 
716  QVariant transform = propertyMap.value( QStringLiteral( "transformer" ) );
717 
718  if ( transform.isValid() )
719  {
720  QVariantMap transformerMap = transform.toMap();
721 
722  QgsPropertyTransformer::Type type = static_cast< QgsPropertyTransformer::Type >( transformerMap.value( QStringLiteral( "t" ), QgsPropertyTransformer::GenericNumericTransformer ).toInt() );
723  std::unique_ptr< QgsPropertyTransformer > transformer( QgsPropertyTransformer::create( type ) );
724 
725  if ( transformer )
726  {
727  if ( transformer->loadVariant( transformerMap.value( QStringLiteral( "d" ) ) ) )
728  d->transformer = transformer.release();
729  }
730  }
731 
732  return true;
733 }
734 
735 
737 {
738  d.detach();
739  d->transformer = transformer;
740 }
741 
743 {
744  return d->transformer;
745 }
746 
748 {
749  if ( d->type != ExpressionBasedProperty )
750  return false;
751 
752  if ( d->transformer )
753  return false; // already a transformer
754 
755  QString baseExpression;
756  QString fieldName;
757  std::unique_ptr< QgsPropertyTransformer > transformer( QgsPropertyTransformer::fromExpression( d->expressionString, baseExpression, fieldName ) );
758  if ( !transformer )
759  return false;
760 
761  d.detach();
762  d->transformer = transformer.release();
763  if ( !fieldName.isEmpty() )
764  setField( fieldName );
765  else
766  setExpressionString( baseExpression );
767  return true;
768 }
769 
770 
771 
int lookupField(const QString &fieldName) const
Look up field&#39;s index from the field name.
Definition: qgsfields.cpp:299
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:176
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.
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:62
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.
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
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:255
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.