QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 [≤ 0 ≥]" );
42  break;
43 
44  case IntegerPositive:
45  mTypes = DataTypeNumeric;
46  mHelpText = QObject::tr( "int [≥ 0]" );
47  break;
48 
50  mTypes = DataTypeNumeric;
51  mHelpText = QObject::tr( "int [≥ 1]" );
52  break;
53 
54  case Double:
55  mTypes = DataTypeNumeric;
56  mHelpText = QObject::tr( "double [≤ 0.0 ≥]" );
57  break;
58 
59  case DoublePositive:
60  mTypes = DataTypeNumeric;
61  mHelpText = QObject::tr( "double [≥ 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>RRGGBBAA</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 [≥ 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 [≥ 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 DateTime:
171  mTypes = DataTypeString;
172  mHelpText = QObject::tr( "DateTime or string representation of a DateTime" );
173  break;
174 
175  case Custom:
176  mTypes = DataTypeString;
177  }
178 }
179 
180 QgsPropertyDefinition::QgsPropertyDefinition( const QString &name, DataType dataType, const QString &description, const QString &helpText, const QString &origin, const QString &comment )
181  : mName( name )
182  , mDescription( description )
183  , mTypes( dataType )
184  , mHelpText( helpText )
185  , mOrigin( origin )
186  , mComment( comment )
187 {}
188 
190 {
191  return mTypes == DataTypeNumeric || mStandardType == Size || mStandardType == StrokeWidth || mStandardType == ColorNoAlpha || mStandardType == ColorWithAlpha
192  || mStandardType == Rotation;
193 }
194 
195 QString QgsPropertyDefinition::trString()
196 {
197  // just something to reduce translation redundancy
198  return QObject::tr( "string " );
199 }
200 
201 //
202 // QgsProperty
203 //
204 
206 {
207  d = new QgsPropertyPrivate();
208 }
209 
210 QgsProperty::~QgsProperty() = default;
211 
212 QgsProperty QgsProperty::fromExpression( const QString &expression, bool isActive )
213 {
214  QgsProperty p;
215  p.setExpressionString( expression );
216  p.setActive( isActive );
217  return p;
218 }
219 
220 QgsProperty QgsProperty::fromField( const QString &fieldName, bool isActive )
221 {
222  QgsProperty p;
223  p.setField( fieldName );
224  p.setActive( isActive );
225  return p;
226 }
227 
228 QgsProperty QgsProperty::fromValue( const QVariant &value, bool isActive )
229 {
230  QgsProperty p;
231  p.setStaticValue( value );
232  p.setActive( isActive );
233  return p;
234 }
235 
236 QgsProperty::QgsProperty( const QgsProperty &other ) //NOLINT
237  : d( other.d )
238 {}
239 
241 {
242  d = other.d;
243  return *this;
244 }
245 
246 bool QgsProperty::operator==( const QgsProperty &other ) const
247 {
248  return d->active == other.d->active
249  && d->type == other.d->type
250  && ( d->type != StaticProperty || d->staticValue == other.d->staticValue )
251  && ( d->type != FieldBasedProperty || d->fieldName == other.d->fieldName )
252  && ( d->type != ExpressionBasedProperty || d->expressionString == other.d->expressionString )
253  && ( ( !d->transformer && !other.d->transformer ) || ( d->transformer && other.d->transformer && d->transformer->toExpression( QString() ) == other.d->transformer->toExpression( QString() ) ) );
254 }
255 
256 bool QgsProperty::operator!=( const QgsProperty &other ) const
257 {
258  return ( !( ( *this ) == other ) );
259 }
260 
262 {
263  return static_cast< Type >( d->type );
264 }
265 
267 {
268  return d->type != InvalidProperty && d->active;
269 }
270 
271 void QgsProperty::setActive( bool active )
272 {
273  d.detach();
274  d->active = active;
275 }
276 
277 void QgsProperty::setStaticValue( const QVariant &value )
278 {
279  d.detach();
280  d->type = StaticProperty;
281  d->staticValue = value;
282 }
283 
284 QVariant QgsProperty::staticValue() const
285 {
286  if ( d->type != StaticProperty )
287  return QVariant();
288 
289  return d->staticValue;
290 }
291 
292 void QgsProperty::setField( const QString &field )
293 {
294  d.detach();
295  d->type = FieldBasedProperty;
296  d->fieldName = field;
297  d->cachedFieldIdx = -1;
298 }
299 
300 QString QgsProperty::field() const
301 {
302  if ( d->type != FieldBasedProperty )
303  return QString();
304 
305  return d->fieldName;
306 }
307 
308 QgsProperty::operator bool() const
309 {
310  return d->type != InvalidProperty;
311 }
312 
313 void QgsProperty::setExpressionString( const QString &expression )
314 {
315  d.detach();
316  d->type = ExpressionBasedProperty;
317  d->expressionString = expression;
318  d->expression = QgsExpression( expression );
319  d->expressionPrepared = false;
320  d->expressionIsInvalid = false;
321 }
322 
324 {
325  if ( d->type != ExpressionBasedProperty )
326  return QString();
327 
328  return d->expressionString;
329 }
330 
331 
333 {
334  QString exp;
335  switch ( d->type )
336  {
337  case StaticProperty:
338  exp = QgsExpression::quotedValue( d->staticValue );
339  break;
340 
341  case FieldBasedProperty:
342  exp = QgsExpression::quotedColumnRef( d->fieldName );
343  break;
344 
346  exp = d->expressionString;
347  break;
348 
349  case InvalidProperty:
350  exp = QString();
351  break;
352  }
353  return d->transformer ? d->transformer->toExpression( exp ) : exp;
354 }
355 
356 bool QgsProperty::prepare( const QgsExpressionContext &context ) const
357 {
358  if ( !d->active )
359  return true;
360 
361  switch ( d->type )
362  {
363  case StaticProperty:
364  return true;
365 
366  case FieldBasedProperty:
367  {
368  d.detach();
369  // cache field index to avoid subsequent lookups
370  QgsFields f = context.fields();
371  d->cachedFieldIdx = f.lookupField( d->fieldName );
372  return true;
373  }
374 
376  {
377  d.detach();
378  if ( !d->expression.prepare( &context ) )
379  {
380  d->expressionReferencedCols.clear();
381  d->expressionPrepared = false;
382  d->expressionIsInvalid = true;
383  return false;
384  }
385 
386  d->expressionPrepared = true;
387  d->expressionIsInvalid = false;
388  d->expressionReferencedCols = d->expression.referencedColumns();
389  return true;
390  }
391 
392  case InvalidProperty:
393  return true;
394 
395  }
396 
397  return false;
398 }
399 
400 QSet<QString> QgsProperty::referencedFields( const QgsExpressionContext &context, bool ignoreContext ) const
401 {
402  if ( !d->active )
403  return QSet<QString>();
404 
405  switch ( d->type )
406  {
407  case StaticProperty:
408  case InvalidProperty:
409  return QSet<QString>();
410 
411  case FieldBasedProperty:
412  {
413  QSet< QString > fields;
414  if ( !d->fieldName.isEmpty() )
415  fields.insert( d->fieldName );
416  return fields;
417  }
418 
420  {
421  if ( ignoreContext )
422  {
423  return d->expression.referencedColumns();
424  }
425 
426  if ( d->expressionIsInvalid )
427  return QSet< QString >();
428 
429  d.detach();
430  if ( !d->expressionPrepared && !prepare( context ) )
431  {
432  d->expressionIsInvalid = true;
433  return QSet< QString >();
434  }
435 
436  return d->expressionReferencedCols;
437  }
438 
439  }
440  return QSet<QString>();
441 }
442 
444 {
445  QRegularExpression rx( QStringLiteral( "^project_color\\('.*'\\)$" ) );
446  return d->type == QgsProperty::ExpressionBasedProperty && !d->expressionString.isEmpty()
447  && rx.match( d->expressionString ).hasMatch();
448 }
449 
450 QVariant QgsProperty::propertyValue( const QgsExpressionContext &context, const QVariant &defaultValue, bool *ok ) const
451 {
452  if ( ok )
453  *ok = false;
454 
455  if ( !d->active )
456  return defaultValue;
457 
458  switch ( d->type )
459  {
460  case StaticProperty:
461  {
462  if ( ok )
463  *ok = true;
464  return d->staticValue;
465  }
466 
467  case FieldBasedProperty:
468  {
469  QgsFeature f = context.feature();
470  if ( !f.isValid() )
471  return defaultValue;
472 
473  //shortcut the field lookup
474  if ( d->cachedFieldIdx >= 0 )
475  {
476  if ( ok )
477  *ok = true;
478  return f.attribute( d->cachedFieldIdx );
479  }
480  prepare( context );
481  if ( d->cachedFieldIdx < 0 )
482  return defaultValue;
483 
484  if ( ok )
485  *ok = true;
486  return f.attribute( d->cachedFieldIdx );
487  }
488 
490  {
491  if ( d->expressionIsInvalid )
492  return defaultValue;
493 
494  if ( !d->expressionPrepared && !prepare( context ) )
495  return defaultValue;
496 
497  QVariant result = d->expression.evaluate( &context );
498  if ( result.isValid() )
499  {
500  if ( ok )
501  *ok = true;
502  return result;
503  }
504  else
505  {
506  return defaultValue;
507  }
508  }
509 
510  case InvalidProperty:
511  return defaultValue;
512 
513  }
514 
515  return QVariant();
516 }
517 
518 
519 QVariant QgsProperty::value( const QgsExpressionContext &context, const QVariant &defaultValue, bool *ok ) const
520 {
521  if ( ok )
522  *ok = false;
523 
524  bool valOk = false;
525  QVariant val = propertyValue( context, defaultValue, &valOk );
526  if ( !d->transformer && !valOk ) // if transformer present, let it handle null values
527  return defaultValue;
528 
529  if ( d->transformer )
530  {
531  if ( !valOk )
532  val = QVariant();
533  val = d->transformer->transform( context, val );
534  }
535 
536  if ( ok )
537  *ok = true;
538 
539  return val;
540 }
541 
542 QDateTime QgsProperty::valueAsDateTime( const QgsExpressionContext &context, const QDateTime &defaultDateTime, bool *ok ) const
543 {
544  bool valOk = false;
545  QVariant val = value( context, defaultDateTime, &valOk );
546 
547  if ( !valOk || !val.isValid() )
548  return defaultDateTime;
549 
550  QDateTime dateTime;
551  if ( val.type() == QVariant::DateTime )
552  {
553  dateTime = val.value<QDateTime>();
554  }
555  else
556  {
557  dateTime = val.toDateTime();
558  }
559 
560  if ( !dateTime.isValid() )
561  return defaultDateTime;
562  else
563  {
564  if ( ok )
565  *ok = true;
566  return dateTime;
567  }
568 }
569 
570 QString QgsProperty::valueAsString( const QgsExpressionContext &context, const QString &defaultString, bool *ok ) const
571 {
572  bool valOk = false;
573  QVariant val = value( context, defaultString, &valOk );
574 
575  if ( !valOk || !val.isValid() )
576  {
577  if ( ok )
578  *ok = false;
579  return defaultString;
580  }
581  else
582  {
583  if ( ok )
584  *ok = true;
585  return val.toString();
586  }
587 }
588 
589 QColor QgsProperty::valueAsColor( const QgsExpressionContext &context, const QColor &defaultColor, bool *ok ) const
590 {
591  if ( ok )
592  *ok = false;
593 
594  bool valOk = false;
595  QVariant val = value( context, defaultColor, &valOk );
596 
597  if ( !valOk || !val.isValid() )
598  return defaultColor;
599 
600  QColor color;
601  if ( val.type() == QVariant::Color )
602  {
603  color = val.value<QColor>();
604  }
605  else
606  {
607  color = QgsSymbolLayerUtils::decodeColor( val.toString() );
608  }
609 
610  if ( !color.isValid() )
611  return defaultColor;
612  else
613  {
614  if ( ok )
615  *ok = true;
616  return color;
617  }
618 }
619 
620 double QgsProperty::valueAsDouble( const QgsExpressionContext &context, double 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() )
629  return defaultValue;
630 
631  bool convertOk = false;
632  double dbl = val.toDouble( &convertOk );
633  if ( !convertOk )
634  return defaultValue;
635  else
636  {
637  if ( ok )
638  *ok = true;
639  return dbl;
640  }
641 }
642 
643 int QgsProperty::valueAsInt( const QgsExpressionContext &context, int defaultValue, bool *ok ) const
644 {
645  if ( ok )
646  *ok = false;
647 
648  bool valOk = false;
649  QVariant val = value( context, defaultValue, &valOk );
650 
651  if ( !valOk || !val.isValid() )
652  return defaultValue;
653 
654  bool convertOk = false;
655  int integer = val.toInt( &convertOk );
656  if ( !convertOk )
657  {
658  //one more option to try
659  double dbl = val.toDouble( &convertOk );
660  if ( convertOk )
661  {
662  if ( ok )
663  *ok = true;
664  return std::round( dbl );
665  }
666  else
667  {
668  return defaultValue;
669  }
670  }
671  else
672  {
673  if ( ok )
674  *ok = true;
675  return integer;
676  }
677 }
678 
679 bool QgsProperty::valueAsBool( const QgsExpressionContext &context, bool defaultValue, bool *ok ) const
680 {
681  if ( ok )
682  *ok = false;
683 
684  bool valOk = false;
685  QVariant val = value( context, defaultValue, &valOk );
686 
687  if ( !valOk || !val.isValid() || val.isNull() )
688  return defaultValue;
689 
690  if ( ok )
691  *ok = true;
692  return val.toBool();
693 }
694 
695 QVariant QgsProperty::toVariant() const
696 {
697  QVariantMap propertyMap;
698 
699  propertyMap.insert( QStringLiteral( "active" ), d->active );
700  propertyMap.insert( QStringLiteral( "type" ), d->type );
701 
702  switch ( d->type )
703  {
704  case StaticProperty:
705  // propertyMap.insert( QStringLiteral( "valType" ), d->staticValue.typeName() );
706  propertyMap.insert( QStringLiteral( "val" ), d->staticValue.toString() );
707  break;
708 
709  case FieldBasedProperty:
710  propertyMap.insert( QStringLiteral( "field" ), d->fieldName );
711  break;
712 
714  propertyMap.insert( QStringLiteral( "expression" ), d->expressionString );
715  break;
716 
717  case InvalidProperty:
718  break;
719  }
720 
721  if ( d->transformer )
722  {
723  QVariantMap transformer;
724  transformer.insert( QStringLiteral( "t" ), d->transformer->transformerType() );
725  transformer.insert( QStringLiteral( "d" ), d->transformer->toVariant() );
726 
727  propertyMap.insert( QStringLiteral( "transformer" ), transformer );
728  }
729 
730  return propertyMap;
731 }
732 
733 bool QgsProperty::loadVariant( const QVariant &property )
734 {
735  QVariantMap propertyMap = property.toMap();
736 
737  d.detach();
738  d->active = propertyMap.value( QStringLiteral( "active" ) ).toBool();
739  d->type = static_cast< Type >( propertyMap.value( QStringLiteral( "type" ), InvalidProperty ).toInt() );
740 
741  switch ( d->type )
742  {
743  case StaticProperty:
744  d->staticValue = propertyMap.value( QStringLiteral( "val" ) );
745  // d->staticValue.convert( QVariant::nameToType( propertyElem.attribute( "valType", "QString" ).toLocal8Bit().constData() ) );
746  break;
747 
748  case FieldBasedProperty:
749  d->fieldName = propertyMap.value( QStringLiteral( "field" ) ).toString();
750  if ( d->fieldName.isEmpty() )
751  d->active = false;
752  break;
753 
755  d->expressionString = propertyMap.value( QStringLiteral( "expression" ) ).toString();
756  if ( d->expressionString.isEmpty() )
757  d->active = false;
758 
759  d->expression = QgsExpression( d->expressionString );
760  d->expressionPrepared = false;
761  d->expressionIsInvalid = false;
762  d->expressionReferencedCols.clear();
763  break;
764 
765  case InvalidProperty:
766  break;
767 
768  }
769 
770  //restore transformer if present
771  delete d->transformer;
772  d->transformer = nullptr;
773 
774 
775  QVariant transform = propertyMap.value( QStringLiteral( "transformer" ) );
776 
777  if ( transform.isValid() )
778  {
779  QVariantMap transformerMap = transform.toMap();
780 
781  QgsPropertyTransformer::Type type = static_cast< QgsPropertyTransformer::Type >( transformerMap.value( QStringLiteral( "t" ), QgsPropertyTransformer::GenericNumericTransformer ).toInt() );
782  std::unique_ptr< QgsPropertyTransformer > transformer( QgsPropertyTransformer::create( type ) );
783 
784  if ( transformer )
785  {
786  if ( transformer->loadVariant( transformerMap.value( QStringLiteral( "d" ) ) ) )
787  d->transformer = transformer.release();
788  }
789  }
790 
791  return true;
792 }
793 
794 
796 {
797  d.detach();
798  d->transformer = transformer;
799 }
800 
802 {
803  return d->transformer;
804 }
805 
807 {
808  if ( d->type != ExpressionBasedProperty )
809  return false;
810 
811  if ( d->transformer )
812  return false; // already a transformer
813 
814  QString baseExpression;
815  QString fieldName;
816  std::unique_ptr< QgsPropertyTransformer > transformer( QgsPropertyTransformer::fromExpression( d->expressionString, baseExpression, fieldName ) );
817  if ( !transformer )
818  return false;
819 
820  d.detach();
821  d->transformer = transformer.release();
822  if ( !fieldName.isEmpty() )
823  setField( fieldName );
824  else
825  setExpressionString( baseExpression );
826  return true;
827 }
828 
829 
830 
QgsPropertyDefinition::RenderUnits
@ RenderUnits
Render units (eg mm/pixels/map units)
Definition: qgsproperty.h:64
QgsProperty::setTransformer
void setTransformer(QgsPropertyTransformer *transformer)
Sets an optional transformer to use for manipulating the calculated values for the property.
Definition: qgsproperty.cpp:795
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
QgsProperty::isActive
bool isActive() const
Returns whether the property is currently active.
Definition: qgsproperty.cpp:266
QgsProperty::fromField
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
Definition: qgsproperty.cpp:220
QgsPropertyDefinition::Offset
@ Offset
2D offset
Definition: qgsproperty.h:79
QgsProperty::operator==
bool operator==(const QgsProperty &other) const
Definition: qgsproperty.cpp:246
QgsPropertyDefinition::StandardPropertyTemplate
StandardPropertyTemplate
Predefined standard property templates.
Definition: qgsproperty.h:53
QgsProperty
A store for object properties.
Definition: qgsproperty.h:232
QgsPropertyDefinition::HorizontalAnchor
@ HorizontalAnchor
Horizontal anchor point.
Definition: qgsproperty.h:76
QgsPropertyDefinition::BlendMode
@ BlendMode
Blend mode.
Definition: qgsproperty.h:68
QgsPropertyTransformer
Abstract base class for objects which transform the calculated value of a property.
Definition: qgspropertytransformer.h:171
qgsexpression.h
QgsProperty::operator=
QgsProperty & operator=(const QgsProperty &other)
Definition: qgsproperty.cpp:240
QgsPropertyDefinition::DataTypeString
@ DataTypeString
Property requires a string value.
Definition: qgsproperty.h:93
QgsProperty::FieldBasedProperty
@ FieldBasedProperty
Field based property (QgsFieldBasedProperty)
Definition: qgsproperty.h:240
qgssymbollayerutils.h
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:45
QgsProperty::Type
Type
Property types.
Definition: qgsproperty.h:237
qgsfeature.h
QgsProperty::asExpression
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
Definition: qgsproperty.cpp:332
QgsPropertyDefinition::IntegerPositiveGreaterZero
@ IntegerPositiveGreaterZero
Non-zero positive integer values.
Definition: qgsproperty.h:57
QgsPropertyDefinition::DataTypeBoolean
@ DataTypeBoolean
Property requires a boolean value.
Definition: qgsproperty.h:107
QgsPropertyDefinition::FillStyle
@ FillStyle
Fill style (eg solid, lines)
Definition: qgsproperty.h:74
QgsPropertyDefinition::DataTypeNumeric
@ DataTypeNumeric
Property requires a numeric value.
Definition: qgsproperty.h:100
QgsPropertyDefinition::Double
@ Double
Double value (including negative values)
Definition: qgsproperty.h:58
QgsPropertyDefinition::PenJoinStyle
@ PenJoinStyle
Pen join style.
Definition: qgsproperty.h:67
QgsPropertyDefinition::Point
@ Point
2D point
Definition: qgsproperty.h:69
QgsProperty::isProjectColor
bool isProjectColor() const
Returns true if the property is set to a linked project color.
Definition: qgsproperty.cpp:443
QgsProperty::fromExpression
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
Definition: qgsproperty.cpp:212
field
const QgsField & field
Definition: qgsfield.h:456
QgsProperty::propertyType
Type propertyType() const
Returns the property type.
Definition: qgsproperty.cpp:261
QgsProperty::QgsProperty
QgsProperty()
Constructor for a QgsAbstractProperty.
Definition: qgsproperty.cpp:205
QgsProperty::valueAsColor
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.
Definition: qgsproperty.cpp:589
QgsProperty::loadVariant
bool loadVariant(const QVariant &property)
Loads this property from a QVariantMap, wrapped in a QVariant.
Definition: qgsproperty.cpp:733
QgsPropertyDefinition::DateTime
@ DateTime
DateTime value.
Definition: qgsproperty.h:80
QgsProperty::transformer
const QgsPropertyTransformer * transformer() const
Returns the existing transformer used for manipulating the calculated values for the property,...
Definition: qgsproperty.cpp:801
QgsSymbolLayerUtils::decodeColor
static QColor decodeColor(const QString &str)
Definition: qgssymbollayerutils.cpp:57
QgsProperty::value
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...
Definition: qgsproperty.cpp:519
QgsExpressionContext::fields
QgsFields fields() const
Convenience function for retrieving the fields for the context, if set.
Definition: qgsexpressioncontext.cpp:561
QgsProperty::referencedFields
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext(), bool ignoreContext=false) const
Returns the set of any fields referenced by the property for a specified expression context.
Definition: qgsproperty.cpp:400
QgsProperty::setActive
void setActive(bool active)
Sets whether the property is currently active.
Definition: qgsproperty.cpp:271
QgsPropertyDefinition::String
@ String
Any string value.
Definition: qgsproperty.h:62
QgsProperty::expressionString
QString expressionString() const
Returns the expression used for the property value.
Definition: qgsproperty.cpp:323
QgsExpression::quotedValue
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required.
Definition: qgsexpression.cpp:79
QgsPropertyDefinition::Rotation
@ Rotation
Rotation (value between 0-360 degrees)
Definition: qgsproperty.h:61
QgsProperty::fromValue
static QgsProperty fromValue(const QVariant &value, bool isActive=true)
Returns a new StaticProperty created from the specified value.
Definition: qgsproperty.cpp:228
QgsProperty::convertToTransformer
bool convertToTransformer()
Attempts to convert an existing expression based property to a base expression with corresponding tra...
Definition: qgsproperty.cpp:806
QgsProperty::ExpressionBasedProperty
@ ExpressionBasedProperty
Expression based property (QgsExpressionBasedProperty)
Definition: qgsproperty.h:241
QgsPropertyDefinition::DataType
DataType
Valid data types required by property.
Definition: qgsproperty.h:86
QgsProperty::toVariant
QVariant toVariant() const
Saves this property to a QVariantMap, wrapped in a QVariant.
Definition: qgsproperty.cpp:695
QgsProperty::setField
void setField(const QString &field)
Sets the field name the property references.
Definition: qgsproperty.cpp:292
QgsFeature::isValid
bool isValid() const
Returns the validity of this feature.
Definition: qgsfeature.cpp:185
QgsPropertyDefinition::VerticalAnchor
@ VerticalAnchor
Vertical anchor point.
Definition: qgsproperty.h:77
qgscolorramp.h
QgsPropertyDefinition::ColorWithAlpha
@ ColorWithAlpha
Color with alpha channel.
Definition: qgsproperty.h:65
QgsPropertyDefinition::CapStyle
@ CapStyle
Line cap style (eg round)
Definition: qgsproperty.h:75
QgsProperty::setExpressionString
void setExpressionString(const QString &expression)
Sets the expression to use for the property value.
Definition: qgsproperty.cpp:313
QgsProperty::~QgsProperty
virtual ~QgsProperty()
QgsFeature::attribute
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Definition: qgsfeature.cpp:264
QgsProperty::valueAsString
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.
Definition: qgsproperty.cpp:570
QgsPropertyDefinition::Double0To1
@ Double0To1
Double value between 0-1 (inclusive)
Definition: qgsproperty.h:60
QgsProperty::valueAsBool
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.
Definition: qgsproperty.cpp:679
QgsPropertyDefinition::IntegerPositive
@ IntegerPositive
Positive integer values (including 0)
Definition: qgsproperty.h:56
QgsPropertyDefinition::Size
@ Size
1D size (eg marker radius, or square marker height/width)
Definition: qgsproperty.h:70
qgsproperty_p.h
QgsProperty::operator!=
bool operator!=(const QgsProperty &other) const
Definition: qgsproperty.cpp:256
QgsPropertyTransformer::GenericNumericTransformer
@ GenericNumericTransformer
Generic transformer for numeric values (QgsGenericNumericTransformer)
Definition: qgspropertytransformer.h:191
QgsPropertyDefinition::Boolean
@ Boolean
Boolean value.
Definition: qgsproperty.h:54
QgsPropertyDefinition::LineStyle
@ LineStyle
Line style (eg solid/dashed)
Definition: qgsproperty.h:72
QgsPropertyDefinition::Size2D
@ Size2D
2D size (width/height different)
Definition: qgsproperty.h:71
QgsExpressionContext::feature
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
Definition: qgsexpressioncontext.cpp:540
QgsProperty::field
QString field() const
Returns the current field name the property references.
Definition: qgsproperty.cpp:300
QgsPropertyDefinition::Integer
@ Integer
Integer value (including negative values)
Definition: qgsproperty.h:55
QgsPropertyTransformer::fromExpression
static QgsPropertyTransformer * fromExpression(const QString &expression, QString &baseExpression, QString &fieldName)
Attempts to parse an expression into a corresponding property transformer.
Definition: qgspropertytransformer.cpp:102
qgsproperty.h
QgsProperty::setStaticValue
void setStaticValue(const QVariant &value)
Sets the static value for the property.
Definition: qgsproperty.cpp:277
QgsPropertyTransformer::Type
Type
Transformer types.
Definition: qgspropertytransformer.h:190
QgsExpression::quotedColumnRef
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes)
Definition: qgsexpression.cpp:65
QgsProperty::valueAsDouble
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.
Definition: qgsproperty.cpp:620
QgsPropertyTransformer::loadVariant
virtual bool loadVariant(const QVariant &transformer)
Loads this transformer from a QVariantMap, wrapped in a QVariant.
Definition: qgspropertytransformer.cpp:69
QgsPropertyTransformer::create
static QgsPropertyTransformer * create(Type type)
Factory method for creating a new property transformer of the specified type.
Definition: qgspropertytransformer.cpp:30
QgsProperty::valueAsDateTime
QDateTime valueAsDateTime(const QgsExpressionContext &context, const QDateTime &defaultDateTime=QDateTime(), bool *ok=nullptr) const
Calculates the current value of the property and interprets it as a datetime.
Definition: qgsproperty.cpp:542
QgsPropertyDefinition::supportsAssistant
bool supportsAssistant() const
Returns true if the property is of a type which is compatible with property override assistants.
Definition: qgsproperty.cpp:189
QgsPropertyDefinition::SvgPath
@ SvgPath
Path to an SVG file.
Definition: qgsproperty.h:78
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsProperty::staticValue
QVariant staticValue() const
Returns the current static value for the property.
Definition: qgsproperty.cpp:284
QgsProperty::prepare
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const
Prepares the property against a specified expression context.
Definition: qgsproperty.cpp:356
QgsPropertyDefinition::Opacity
@ Opacity
Opacity (0-100)
Definition: qgsproperty.h:63
qgslogger.h
QgsPropertyDefinition::QgsPropertyDefinition
QgsPropertyDefinition()=default
Constructs an empty property.
QgsFields::lookupField
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Definition: qgsfields.cpp:344
QgsExpression
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:105
QgsProperty::StaticProperty
@ StaticProperty
Static property (QgsStaticProperty)
Definition: qgsproperty.h:239
QgsProperty::valueAsInt
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.
Definition: qgsproperty.cpp:643
QgsPropertyDefinition::StrokeWidth
@ StrokeWidth
Line stroke width.
Definition: qgsproperty.h:73
QgsPropertyDefinition::ColorNoAlpha
@ ColorNoAlpha
Color with no alpha channel.
Definition: qgsproperty.h:66
QgsProperty::InvalidProperty
@ InvalidProperty
Invalid (not set) property.
Definition: qgsproperty.h:238
QgsPropertyDefinition::Custom
@ Custom
Custom property types.
Definition: qgsproperty.h:81
QgsPropertyDefinition::DoublePositive
@ DoublePositive
Positive double value (including 0)
Definition: qgsproperty.h:59