QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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( "string of doubles '<b>width,height</b>' or array of doubles <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( "string of doubles '<b>x,y</b>' or array of doubles <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  d->expressionIsInvalid = false;
313 }
314 
316 {
317  if ( d->type != ExpressionBasedProperty )
318  return QString();
319 
320  return d->expressionString;
321 }
322 
323 
325 {
326  QString exp;
327  switch ( d->type )
328  {
329  case StaticProperty:
330  exp = QgsExpression::quotedValue( d->staticValue );
331  break;
332 
333  case FieldBasedProperty:
334  exp = QgsExpression::quotedColumnRef( d->fieldName );
335  break;
336 
338  exp = d->expressionString;
339  break;
340 
341  case InvalidProperty:
342  exp = QString();
343  break;
344  }
345  return d->transformer ? d->transformer->toExpression( exp ) : exp;
346 }
347 
348 bool QgsProperty::prepare( const QgsExpressionContext &context ) const
349 {
350  if ( !d->active )
351  return true;
352 
353  switch ( d->type )
354  {
355  case StaticProperty:
356  return true;
357 
358  case FieldBasedProperty:
359  {
360  d.detach();
361  // cache field index to avoid subsequent lookups
362  QgsFields f = context.fields();
363  d->cachedFieldIdx = f.lookupField( d->fieldName );
364  return true;
365  }
366 
368  {
369  d.detach();
370  if ( !d->expression.prepare( &context ) )
371  {
372  d->expressionReferencedCols.clear();
373  d->expressionPrepared = false;
374  d->expressionIsInvalid = true;
375  return false;
376  }
377 
378  d->expressionPrepared = true;
379  d->expressionIsInvalid = false;
380  d->expressionReferencedCols = d->expression.referencedColumns();
381  return true;
382  }
383 
384  case InvalidProperty:
385  return true;
386 
387  }
388 
389  return false;
390 }
391 
392 QSet<QString> QgsProperty::referencedFields( const QgsExpressionContext &context ) const
393 {
394  if ( !d->active )
395  return QSet<QString>();
396 
397  switch ( d->type )
398  {
399  case StaticProperty:
400  case InvalidProperty:
401  return QSet<QString>();
402 
403  case FieldBasedProperty:
404  {
405  QSet< QString > fields;
406  if ( !d->fieldName.isEmpty() )
407  fields.insert( d->fieldName );
408  return fields;
409  }
410 
412  {
413  if ( d->expressionIsInvalid )
414  return QSet< QString >();
415 
416  d.detach();
417  if ( !d->expressionPrepared && !prepare( context ) )
418  {
419  d->expressionIsInvalid = true;
420  return QSet< QString >();
421  }
422 
423  return d->expressionReferencedCols;
424  }
425 
426  }
427  return QSet<QString>();
428 }
429 
431 {
432  QRegularExpression rx( QStringLiteral( "^project_color\\('.*'\\)$" ) );
433  return d->type == QgsProperty::ExpressionBasedProperty && !d->expressionString.isEmpty()
434  && rx.match( d->expressionString ).hasMatch();
435 }
436 
437 QVariant QgsProperty::propertyValue( const QgsExpressionContext &context, const QVariant &defaultValue, bool *ok ) const
438 {
439  if ( ok )
440  *ok = false;
441 
442  if ( !d->active )
443  return defaultValue;
444 
445  switch ( d->type )
446  {
447  case StaticProperty:
448  {
449  if ( ok )
450  *ok = true;
451  return d->staticValue;
452  }
453 
454  case FieldBasedProperty:
455  {
456  QgsFeature f = context.feature();
457  if ( !f.isValid() )
458  return defaultValue;
459 
460  //shortcut the field lookup
461  if ( d->cachedFieldIdx >= 0 )
462  {
463  if ( ok )
464  *ok = true;
465  return f.attribute( d->cachedFieldIdx );
466  }
467  prepare( context );
468  if ( d->cachedFieldIdx < 0 )
469  return defaultValue;
470 
471  if ( ok )
472  *ok = true;
473  return f.attribute( d->cachedFieldIdx );
474  }
475 
477  {
478  if ( d->expressionIsInvalid )
479  return defaultValue;
480 
481  if ( !d->expressionPrepared && !prepare( context ) )
482  return defaultValue;
483 
484  QVariant result = d->expression.evaluate( &context );
485  if ( result.isValid() )
486  {
487  if ( ok )
488  *ok = true;
489  return result;
490  }
491  else
492  {
493  return defaultValue;
494  }
495  }
496 
497  case InvalidProperty:
498  return defaultValue;
499 
500  };
501 
502  return QVariant();
503 }
504 
505 
506 QVariant QgsProperty::value( const QgsExpressionContext &context, const QVariant &defaultValue, bool *ok ) const
507 {
508  if ( ok )
509  *ok = false;
510 
511  bool valOk = false;
512  QVariant val = propertyValue( context, defaultValue, &valOk );
513  if ( !d->transformer && !valOk ) // if transformer present, let it handle null values
514  return defaultValue;
515 
516  if ( d->transformer )
517  {
518  if ( !valOk )
519  val = QVariant();
520  val = d->transformer->transform( context, val );
521  }
522 
523  if ( ok )
524  *ok = true;
525 
526  return val;
527 }
528 
529 QString QgsProperty::valueAsString( const QgsExpressionContext &context, const QString &defaultString, bool *ok ) const
530 {
531  bool valOk = false;
532  QVariant val = value( context, defaultString, &valOk );
533 
534  if ( !valOk || !val.isValid() )
535  {
536  if ( ok )
537  *ok = false;
538  return defaultString;
539  }
540  else
541  {
542  if ( ok )
543  *ok = true;
544  return val.toString();
545  }
546 }
547 
548 QColor QgsProperty::valueAsColor( const QgsExpressionContext &context, const QColor &defaultColor, bool *ok ) const
549 {
550  if ( ok )
551  *ok = false;
552 
553  bool valOk = false;
554  QVariant val = value( context, defaultColor, &valOk );
555 
556  if ( !valOk || !val.isValid() )
557  return defaultColor;
558 
559  QColor color;
560  if ( val.type() == QVariant::Color )
561  {
562  color = val.value<QColor>();
563  }
564  else
565  {
566  color = QgsSymbolLayerUtils::decodeColor( val.toString() );
567  }
568 
569  if ( !color.isValid() )
570  return defaultColor;
571  else
572  {
573  if ( ok )
574  *ok = true;
575  return color;
576  }
577 }
578 
579 double QgsProperty::valueAsDouble( const QgsExpressionContext &context, double defaultValue, bool *ok ) const
580 {
581  if ( ok )
582  *ok = false;
583 
584  bool valOk = false;
585  QVariant val = value( context, defaultValue, &valOk );
586 
587  if ( !valOk || !val.isValid() )
588  return defaultValue;
589 
590  bool convertOk = false;
591  double dbl = val.toDouble( &convertOk );
592  if ( !convertOk )
593  return defaultValue;
594  else
595  {
596  if ( ok )
597  *ok = true;
598  return dbl;
599  }
600 }
601 
602 int QgsProperty::valueAsInt( const QgsExpressionContext &context, int defaultValue, bool *ok ) const
603 {
604  if ( ok )
605  *ok = false;
606 
607  bool valOk = false;
608  QVariant val = value( context, defaultValue, &valOk );
609 
610  if ( !valOk || !val.isValid() )
611  return defaultValue;
612 
613  bool convertOk = false;
614  int integer = val.toInt( &convertOk );
615  if ( !convertOk )
616  {
617  //one more option to try
618  double dbl = val.toDouble( &convertOk );
619  if ( convertOk )
620  {
621  if ( ok )
622  *ok = true;
623  return std::round( dbl );
624  }
625  else
626  {
627  return defaultValue;
628  }
629  }
630  else
631  {
632  if ( ok )
633  *ok = true;
634  return integer;
635  }
636 }
637 
638 bool QgsProperty::valueAsBool( const QgsExpressionContext &context, bool defaultValue, bool *ok ) const
639 {
640  if ( ok )
641  *ok = false;
642 
643  bool valOk = false;
644  QVariant val = value( context, defaultValue, &valOk );
645 
646  if ( !valOk || !val.isValid() || val.isNull() )
647  return defaultValue;
648 
649  if ( ok )
650  *ok = true;
651  return val.toBool();
652 }
653 
654 QVariant QgsProperty::toVariant() const
655 {
656  QVariantMap propertyMap;
657 
658  propertyMap.insert( QStringLiteral( "active" ), d->active );
659  propertyMap.insert( QStringLiteral( "type" ), d->type );
660 
661  switch ( d->type )
662  {
663  case StaticProperty:
664  // propertyMap.insert( QStringLiteral( "valType" ), d->staticValue.typeName() );
665  propertyMap.insert( QStringLiteral( "val" ), d->staticValue.toString() );
666  break;
667 
668  case FieldBasedProperty:
669  propertyMap.insert( QStringLiteral( "field" ), d->fieldName );
670  break;
671 
673  propertyMap.insert( QStringLiteral( "expression" ), d->expressionString );
674  break;
675 
676  case InvalidProperty:
677  break;
678  }
679 
680  if ( d->transformer )
681  {
682  QVariantMap transformer;
683  transformer.insert( QStringLiteral( "t" ), d->transformer->transformerType() );
684  transformer.insert( QStringLiteral( "d" ), d->transformer->toVariant() );
685 
686  propertyMap.insert( QStringLiteral( "transformer" ), transformer );
687  }
688 
689  return propertyMap;
690 }
691 
692 bool QgsProperty::loadVariant( const QVariant &property )
693 {
694  QVariantMap propertyMap = property.toMap();
695 
696  d.detach();
697  d->active = propertyMap.value( QStringLiteral( "active" ) ).toBool();
698  d->type = static_cast< Type >( propertyMap.value( QStringLiteral( "type" ), InvalidProperty ).toInt() );
699 
700  switch ( d->type )
701  {
702  case StaticProperty:
703  d->staticValue = propertyMap.value( QStringLiteral( "val" ) );
704  // d->staticValue.convert( QVariant::nameToType( propertyElem.attribute( "valType", "QString" ).toLocal8Bit().constData() ) );
705  break;
706 
707  case FieldBasedProperty:
708  d->fieldName = propertyMap.value( QStringLiteral( "field" ) ).toString();
709  if ( d->fieldName.isEmpty() )
710  d->active = false;
711  break;
712 
714  d->expressionString = propertyMap.value( QStringLiteral( "expression" ) ).toString();
715  if ( d->expressionString.isEmpty() )
716  d->active = false;
717 
718  d->expression = QgsExpression( d->expressionString );
719  d->expressionPrepared = false;
720  d->expressionIsInvalid = false;
721  d->expressionReferencedCols.clear();
722  break;
723 
724  case InvalidProperty:
725  break;
726 
727  }
728 
729  //restore transformer if present
730  delete d->transformer;
731  d->transformer = nullptr;
732 
733 
734  QVariant transform = propertyMap.value( QStringLiteral( "transformer" ) );
735 
736  if ( transform.isValid() )
737  {
738  QVariantMap transformerMap = transform.toMap();
739 
740  QgsPropertyTransformer::Type type = static_cast< QgsPropertyTransformer::Type >( transformerMap.value( QStringLiteral( "t" ), QgsPropertyTransformer::GenericNumericTransformer ).toInt() );
741  std::unique_ptr< QgsPropertyTransformer > transformer( QgsPropertyTransformer::create( type ) );
742 
743  if ( transformer )
744  {
745  if ( transformer->loadVariant( transformerMap.value( QStringLiteral( "d" ) ) ) )
746  d->transformer = transformer.release();
747  }
748  }
749 
750  return true;
751 }
752 
753 
755 {
756  d.detach();
757  d->transformer = transformer;
758 }
759 
761 {
762  return d->transformer;
763 }
764 
766 {
767  if ( d->type != ExpressionBasedProperty )
768  return false;
769 
770  if ( d->transformer )
771  return false; // already a transformer
772 
773  QString baseExpression;
774  QString fieldName;
775  std::unique_ptr< QgsPropertyTransformer > transformer( QgsPropertyTransformer::fromExpression( d->expressionString, baseExpression, fieldName ) );
776  if ( !transformer )
777  return false;
778 
779  d.detach();
780  d->transformer = transformer.release();
781  if ( !fieldName.isEmpty() )
782  setField( fieldName );
783  else
784  setExpressionString( baseExpression );
785  return true;
786 }
787 
788 
789 
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)
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.