QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgspropertycollection.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgspropertycollection.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 "qgspropertycollection.h"
17 #include "qgsproperty.h"
18 #include "qgsxmlutils.h"
19 
20 //
21 // QgsAbstractPropertyCollection
22 //
23 
25  : mName( name )
26 {
27 
28 }
29 
30 QDateTime QgsAbstractPropertyCollection::valueAsDateTime( int key, const QgsExpressionContext &context, const QDateTime &defaultDateTime, bool *ok ) const
31 {
32  if ( ok )
33  *ok = false;
34 
35  QgsProperty prop = property( key );
36  if ( !prop || !prop.isActive() )
37  return defaultDateTime;
38 
39  return prop.valueAsDateTime( context, defaultDateTime, ok );
40 }
41 
42 QString QgsAbstractPropertyCollection::valueAsString( int key, const QgsExpressionContext &context, const QString &defaultString, bool *ok ) const
43 {
44  if ( ok )
45  *ok = false;
46 
47  QgsProperty prop = property( key );
48  if ( !prop || !prop.isActive() )
49  return defaultString;
50 
51  return prop.valueAsString( context, defaultString, ok );
52 }
53 
54 QColor QgsAbstractPropertyCollection::valueAsColor( int key, const QgsExpressionContext &context, const QColor &defaultColor, bool *ok ) const
55 {
56  if ( ok )
57  *ok = false;
58 
59  QgsProperty prop = property( key );
60  if ( !prop || !prop.isActive() )
61  return defaultColor;
62 
63  return prop.valueAsColor( context, defaultColor, ok );
64 }
65 
66 double QgsAbstractPropertyCollection::valueAsDouble( int key, const QgsExpressionContext &context, double defaultValue, bool *ok ) const
67 {
68  if ( ok )
69  *ok = false;
70  QgsProperty prop = property( key );
71  if ( !prop || !prop.isActive() )
72  return defaultValue;
73 
74  return prop.valueAsDouble( context, defaultValue, ok );
75 }
76 
77 int QgsAbstractPropertyCollection::valueAsInt( int key, const QgsExpressionContext &context, int defaultValue, bool *ok ) const
78 {
79  if ( ok )
80  *ok = false;
81  QgsProperty prop = property( key );
82  if ( !prop || !prop.isActive() )
83  return defaultValue;
84 
85  return prop.valueAsInt( context, defaultValue, ok );
86 }
87 
88 bool QgsAbstractPropertyCollection::valueAsBool( int key, const QgsExpressionContext &context, bool defaultValue, bool *ok ) const
89 {
90  if ( ok )
91  *ok = false;
92  QgsProperty prop = property( key );
93  if ( !prop || !prop.isActive() )
94  return defaultValue;
95 
96  return prop.valueAsBool( context, defaultValue, ok );
97 }
98 
99 bool QgsAbstractPropertyCollection::writeXml( QDomElement &collectionElem, const QgsPropertiesDefinition &definitions ) const
100 {
101  QVariant collection = toVariant( definitions );
102  QDomDocument doc = collectionElem.ownerDocument();
103  QDomElement element = QgsXmlUtils::writeVariant( collection, doc );
104  collectionElem.appendChild( element );
105  return true;
106 }
107 
108 bool QgsAbstractPropertyCollection::readXml( const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions )
109 {
110  QVariant collection = QgsXmlUtils::readVariant( collectionElem.firstChild().toElement() );
111  return loadVariant( collection.toMap(), definitions );
112 }
113 
114 
115 
116 //
117 // QgsPropertyCollection
118 //
119 
122 {}
123 
126  , mProperties( other.mProperties )
127  , mDirty( other.mDirty )
128  , mHasActiveProperties( other.mHasActiveProperties )
129  , mHasDynamicProperties( other.mHasDynamicProperties )
130  , mCount( other.mCount )
131 {
132  mProperties.detach();
133 }
134 
136 {
137  QgsAbstractPropertyCollection::operator=( other );
138  mProperties = other.mProperties;
139  mProperties.detach();
140  mDirty = other.mDirty;
141  mHasActiveProperties = other.mHasActiveProperties;
142  mHasDynamicProperties = other.mHasDynamicProperties;
143  mCount = other.mCount;
144  return *this;
145 }
146 
148 {
149  if ( !mDirty )
150  return mCount;
151 
152  rescan();
153  return mCount;
154 }
155 
157 {
158  QSet<int> keys;
159  QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
160  for ( ; it != mProperties.constEnd(); ++it )
161  {
162  if ( it.value() )
163  keys.insert( it.key() );
164  }
165  return keys;
166 }
167 
169 {
170  mProperties.clear();
171  mDirty = false;
172  mHasActiveProperties = false;
173  mHasDynamicProperties = false;
174  mCount = 0;
175 }
176 
177 void QgsPropertyCollection::setProperty( int key, const QgsProperty &property )
178 {
179  if ( property )
180  mProperties.insert( key, property );
181  else
182  mProperties.remove( key );
183 
184  mDirty = true;
185 }
186 
187 void QgsPropertyCollection::setProperty( int key, const QVariant &value )
188 {
189  mProperties.insert( key, QgsProperty::fromValue( value ) );
190  mDirty = true;
191 }
192 
194 {
195  if ( mProperties.isEmpty() )
196  return false;
197 
198  auto it = mProperties.constFind( key );
199  if ( it != mProperties.constEnd() )
200  return ( *it );
201  return false;
202 }
203 
205 {
206  if ( mProperties.isEmpty() )
207  return QgsProperty();
208 
209  return mProperties.value( key );
210 }
211 
213 {
214  mDirty = true;
215  return mProperties[ key ];
216 }
217 
218 QVariant QgsPropertyCollection::value( int key, const QgsExpressionContext &context, const QVariant &defaultValue ) const
219 {
220  if ( mProperties.isEmpty() )
221  return defaultValue;
222 
223  QgsProperty prop = mProperties.value( key );
224  if ( !prop || !prop.isActive() )
225  return defaultValue;
226 
227  return prop.value( context, defaultValue );
228 }
229 
231 {
232  bool result = true;
233  QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
234  for ( ; it != mProperties.constEnd(); ++it )
235  {
236  if ( !it.value().isActive() )
237  continue;
238 
239  result = result && it.value().prepare( context );
240  }
241  return result;
242 }
243 
244 QSet< QString > QgsPropertyCollection::referencedFields( const QgsExpressionContext &context, bool ignoreContext ) const
245 {
246  QSet< QString > cols;
247  QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
248  for ( ; it != mProperties.constEnd(); ++it )
249  {
250  if ( !it.value().isActive() )
251  continue;
252 
253  cols.unite( it.value().referencedFields( context, ignoreContext ) );
254  }
255  return cols;
256 }
257 
258 bool QgsPropertyCollection::isActive( int key ) const
259 {
260  if ( mProperties.isEmpty() )
261  return false;
262 
263  auto it = mProperties.constFind( key );
264  if ( it != mProperties.constEnd() )
265  return ( *it ).isActive();
266  return false;
267 }
268 
269 void QgsPropertyCollection::rescan() const
270 {
271  mHasActiveProperties = false;
272  mHasDynamicProperties = false;
273  mCount = 0;
274  if ( !mProperties.isEmpty() )
275  {
276  QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
277  for ( ; it != mProperties.constEnd(); ++it )
278  {
279  if ( it.value() )
280  mCount++;
281  if ( it.value().isActive() )
282  {
283  mHasActiveProperties = true;
284  if ( it.value().propertyType() != QgsProperty::StaticProperty )
285  {
286  mHasDynamicProperties = true;
287  }
288  }
289  }
290  }
291  mDirty = false;
292 }
293 
295 {
296  if ( mDirty )
297  rescan();
298 
299  return mHasActiveProperties;
300 }
301 
303 {
304  if ( mDirty )
305  rescan();
306 
307  return mHasDynamicProperties;
308 }
309 
310 QVariant QgsPropertyCollection::toVariant( const QgsPropertiesDefinition &definitions ) const
311 {
312  QVariantMap collection;
313 
314  collection.insert( QStringLiteral( "name" ), name() );
315  collection.insert( QStringLiteral( "type" ), QStringLiteral( "collection" ) );
316 
317  QVariantMap properties;
318 
319  QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
320  for ( ; it != mProperties.constEnd(); ++it )
321  {
322  if ( it.value() )
323  {
324  properties.insert( definitions.value( it.key() ).name(), it.value().toVariant() );
325  }
326  }
327  collection.insert( QStringLiteral( "properties" ), properties );
328  return collection;
329 }
330 
331 bool QgsPropertyCollection::loadVariant( const QVariant &collection, const QgsPropertiesDefinition &definitions )
332 {
333  clear();
334 
335  QVariantMap collectionMap = collection.toMap();
336 
337  setName( collectionMap.value( QStringLiteral( "name" ) ).toString() );
338 
339  mCount = 0;
340  QVariantMap properties = collectionMap.value( QStringLiteral( "properties" ) ).toMap();
341  for ( auto propertyIterator = properties.constBegin(); propertyIterator != properties.constEnd(); ++propertyIterator )
342  {
343  // match name to int key
344  int key = -1;
345  QgsPropertiesDefinition::const_iterator it = definitions.constBegin();
346  for ( ; it != definitions.constEnd(); ++it )
347  {
348  if ( it->name() == propertyIterator.key() )
349  {
350  key = it.key();
351  break;
352  }
353  }
354 
355  if ( key < 0 )
356  continue;
357 
358  QgsProperty prop;
359  prop.loadVariant( propertyIterator.value() );
360  mProperties.insert( key, prop );
361 
362  mCount++;
363 
364  mHasActiveProperties = mHasActiveProperties || prop.isActive();
365  mHasDynamicProperties = mHasDynamicProperties ||
366  ( prop.isActive() &&
369  }
370  return true;
371 }
372 
373 //
374 // QgsPropertyCollectionStack
375 //
376 
378 {
379  clear();
380 }
381 
383  : QgsAbstractPropertyCollection( other ), mStack()
384 {
385  clear();
386 
387  for ( QgsPropertyCollection *collection : qgis::as_const( other.mStack ) )
388  {
389  mStack << new QgsPropertyCollection( *collection );
390  }
391 }
392 
394 {
395  setName( other.name() );
396  clear();
397 
398  for ( QgsPropertyCollection *collection : qgis::as_const( other.mStack ) )
399  {
400  mStack << new QgsPropertyCollection( *collection );
401  }
402 
403  return *this;
404 }
405 
407 {
408  return mStack.size();
409 }
410 
412 {
413  qDeleteAll( mStack );
414  mStack.clear();
415 }
416 
418 {
419  mStack.append( collection );
420 }
421 
423 {
424  return mStack.value( index );
425 }
426 
428 {
429  return mStack.value( index );
430 }
431 
433 {
434  const auto constMStack = mStack;
435  for ( QgsPropertyCollection *collection : constMStack )
436  {
437  if ( collection->name() == name )
438  return collection;
439  }
440  return nullptr;
441 }
442 
444 {
445  const auto constMStack = mStack;
446  for ( const QgsPropertyCollection *collection : constMStack )
447  {
449  return true;
450  }
451  return false;
452 }
453 
455 {
456  const auto constMStack = mStack;
457  for ( const QgsPropertyCollection *collection : constMStack )
458  {
460  return true;
461  }
462  return false;
463 }
464 
466 {
467  return static_cast< bool >( property( key ) );
468 }
469 
471 {
472  //loop through stack looking for last active matching property
473  for ( int i = mStack.size() - 1; i >= 0; --i )
474  {
475  const QgsPropertyCollection *collection = mStack.at( i );
476  QgsProperty property = collection->property( key );
477  if ( property && property.isActive() )
478  {
479  return property;
480  }
481  }
482  //not found
483  return QgsProperty();
484 }
485 
486 
487 QVariant QgsPropertyCollectionStack::value( int key, const QgsExpressionContext &context, const QVariant &defaultValue ) const
488 {
489  QgsProperty p = property( key );
490  if ( !p )
491  {
492  return defaultValue;
493  }
494  return p.value( context, defaultValue );
495 }
496 
497 QSet< QString > QgsPropertyCollectionStack::referencedFields( const QgsExpressionContext &context, bool ignoreContext ) const
498 {
499  QSet< QString > cols;
500  const auto constMStack = mStack;
501  for ( QgsPropertyCollection *collection : constMStack )
502  {
503  cols.unite( collection->referencedFields( context, ignoreContext ) );
504  }
505  return cols;
506 }
507 
509 {
510  bool result = true;
511  const auto constMStack = mStack;
512  for ( QgsPropertyCollection *collection : constMStack )
513  {
514  result = result && collection->prepare( context );
515  }
516  return result;
517 }
518 
520 {
521  QSet<int> keys;
522  const auto constMStack = mStack;
523  for ( QgsPropertyCollection *collection : constMStack )
524  {
525  keys.unite( collection->propertyKeys() );
526  }
527  return keys;
528 }
529 
531 {
532  const auto constMStack = mStack;
533  for ( QgsPropertyCollection *collection : constMStack )
534  {
535  if ( collection->hasProperty( key ) )
536  return true;
537  }
538  return false;
539 }
540 
542 {
543  QVariantMap collection;
544  collection.insert( QStringLiteral( "type" ), QStringLiteral( "stack" ) );
545  collection.insert( QStringLiteral( "name" ), name() );
546 
547  QVariantList properties;
548 
549  const auto constMStack = mStack;
550  for ( QgsPropertyCollection *child : constMStack )
551  {
552  properties.append( child->toVariant( definitions ) );
553  }
554 
555  collection.insert( QStringLiteral( "properties" ), properties );
556 
557  return collection;
558 }
559 
560 bool QgsPropertyCollectionStack::loadVariant( const QVariant &collection, const QgsPropertiesDefinition &definitions )
561 {
562  clear();
563 
564  QVariantMap collectionMap = collection.toMap();
565 
566  setName( collectionMap.value( QStringLiteral( "name" ) ).toString() );
567 
568  QVariantList properties = collectionMap.value( QStringLiteral( "properties" ) ).toList();
569 
570  const auto constProperties = properties;
571  for ( const QVariant &property : constProperties )
572  {
573  QgsPropertyCollection *propertyCollection = new QgsPropertyCollection();
574  propertyCollection->loadVariant( property.toMap(), definitions );
575  mStack.append( propertyCollection );
576  }
577 
578  return true;
579 }
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
QgsProperty::isActive
bool isActive() const
Returns whether the property is currently active.
Definition: qgsproperty.cpp:266
QgsPropertyCollection::count
int count() const
Returns the number of properties contained within the collection.
Definition: qgspropertycollection.cpp:147
QgsPropertyCollection::prepare
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
Definition: qgspropertycollection.cpp:230
QgsAbstractPropertyCollection::valueAsDouble
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double.
Definition: qgspropertycollection.cpp:66
QgsProperty
A store for object properties.
Definition: qgsproperty.h:231
QgsAbstractPropertyCollection::valueAsInt
int valueAsInt(int key, const QgsExpressionContext &context, int defaultValue=0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an integer.
Definition: qgspropertycollection.cpp:77
QgsPropertyCollectionStack::hasProperty
bool hasProperty(int key) const override
Returns true if the collection contains a property with the specified key.
Definition: qgspropertycollection.cpp:530
QgsPropertyCollection::propertyKeys
QSet< int > propertyKeys() const override
Returns a list of property keys contained within the collection.
Definition: qgspropertycollection.cpp:156
QgsProperty::FieldBasedProperty
@ FieldBasedProperty
Field based property (QgsFieldBasedProperty)
Definition: qgsproperty.h:240
QgsAbstractPropertyCollection::readXml
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
Definition: qgspropertycollection.cpp:108
QgsAbstractPropertyCollection
Abstract base class for QgsPropertyCollection like objects.
Definition: qgspropertycollection.h:41
QgsPropertyCollection::loadVariant
bool loadVariant(const QVariant &configuration, const QgsPropertiesDefinition &definitions) override
Loads this property collection from a QVariantMap, wrapped in a QVariant.
Definition: qgspropertycollection.cpp:331
QgsAbstractPropertyCollection::loadVariant
virtual bool loadVariant(const QVariant &configuration, const QgsPropertiesDefinition &definitions)=0
Loads this property collection from a QVariantMap, wrapped in a QVariant.
QgsPropertyCollectionStack::value
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const override
Returns the calculated value of the highest priority property with the specified key from within the ...
Definition: qgspropertycollection.cpp:487
QgsPropertyCollectionStack::property
QgsProperty property(int key) const override
Returns the highest priority property with a matching key from within the stack.
Definition: qgspropertycollection.cpp:470
QgsProperty::propertyType
Type propertyType() const
Returns the property type.
Definition: qgsproperty.cpp:261
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
QgsPropertyCollection::clear
void clear() override
Removes all properties from the collection.
Definition: qgspropertycollection.cpp:168
QgsAbstractPropertyCollection::setName
void setName(const QString &name)
Sets the descriptive name for the property collection.
Definition: qgspropertycollection.h:75
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
QgsPropertyCollection::property
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
Definition: qgspropertycollection.cpp:204
QgsProperty::fromValue
static QgsProperty fromValue(const QVariant &value, bool isActive=true)
Returns a new StaticProperty created from the specified value.
Definition: qgsproperty.cpp:228
QgsPropertyCollection::QgsPropertyCollection
QgsPropertyCollection(const QString &name=QString())
Constructor for QgsPropertyCollection.
Definition: qgspropertycollection.cpp:120
QgsProperty::ExpressionBasedProperty
@ ExpressionBasedProperty
Expression based property (QgsExpressionBasedProperty)
Definition: qgsproperty.h:241
QgsPropertiesDefinition
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Definition: qgspropertycollection.h:29
QgsPropertyCollectionStack::at
QgsPropertyCollection * at(int index)
Returns the collection at the corresponding index from the stack.
Definition: qgspropertycollection.cpp:422
QgsPropertyCollectionStack::clear
void clear() override
Removes all collections from the stack.
Definition: qgspropertycollection.cpp:411
QgsAbstractPropertyCollection::name
QString name() const
Returns the descriptive name of the property collection.
Definition: qgspropertycollection.h:69
QgsPropertyCollection::hasActiveProperties
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
Definition: qgspropertycollection.cpp:294
QgsXmlUtils::readVariant
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
Definition: qgsxmlutils.cpp:251
QgsAbstractPropertyCollection::property
virtual QgsProperty property(int key) const =0
Returns a matching property from the collection, if one exists.
QgsPropertyCollection::operator=
QgsPropertyCollection & operator=(const QgsPropertyCollection &other)
Definition: qgspropertycollection.cpp:135
QgsPropertyCollection::hasDynamicProperties
bool hasDynamicProperties() const override
Returns true if the collection has any active, non-static properties, or false if either all non-stat...
Definition: qgspropertycollection.cpp:302
QgsPropertyCollectionStack::propertyKeys
QSet< int > propertyKeys() const override
Returns a list of property keys contained within the collection.
Definition: qgspropertycollection.cpp:519
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
QgsPropertyCollectionStack::count
int count() const
Returns the number of collections contained within the stack.
Definition: qgspropertycollection.cpp:406
QgsPropertyCollectionStack::hasDynamicProperties
bool hasDynamicProperties() const override
Returns true if the collection has any active, non-static properties, or false if either all non-stat...
Definition: qgspropertycollection.cpp:454
QgsPropertyCollection::referencedFields
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext(), bool ignoreContext=false) const override
Returns the set of any fields referenced by the active properties from the collection.
Definition: qgspropertycollection.cpp:244
qgsxmlutils.h
QgsAbstractPropertyCollection::valueAsString
QString valueAsString(int key, const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a string.
Definition: qgspropertycollection.cpp:42
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
QgsPropertyCollectionStack::referencedFields
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext(), bool ignoreContext=false) const override
Returns the set of any fields referenced by the active properties from the stack.
Definition: qgspropertycollection.cpp:497
QgsAbstractPropertyCollection::valueAsDateTime
QDateTime valueAsDateTime(int key, const QgsExpressionContext &context, const QDateTime &defaultDateTime=QDateTime(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a datetime.
Definition: qgspropertycollection.cpp:30
QgsPropertyCollection
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Definition: qgspropertycollection.h:318
QgsAbstractPropertyCollection::toVariant
virtual QVariant toVariant(const QgsPropertiesDefinition &definitions) const =0
Saves this property collection to a QVariantMap, wrapped in a QVariant.
QgsPropertyCollectionStack::hasActiveProperties
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
Definition: qgspropertycollection.cpp:443
QgsPropertyCollectionStack::appendCollection
void appendCollection(QgsPropertyCollection *collection)
Appends a collection to the end of the stack, and transfers ownership of the collection to the stack.
Definition: qgspropertycollection.cpp:417
QgsPropertyCollection::value
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const override
Returns the calculated value of the property with the specified key from within the collection.
Definition: qgspropertycollection.cpp:218
QgsAbstractPropertyCollection::valueAsBool
bool valueAsBool(int key, const QgsExpressionContext &context, bool defaultValue=false, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an boolean.
Definition: qgspropertycollection.cpp:88
QgsPropertyCollectionStack::loadVariant
bool loadVariant(const QVariant &collection, const QgsPropertiesDefinition &definitions) override
Loads this property collection from a QVariantMap, wrapped in a QVariant.
Definition: qgspropertycollection.cpp:560
QgsPropertyCollectionStack::isActive
bool isActive(int key) const override
Returns true if the stack contains an active property with the specified key.
Definition: qgspropertycollection.cpp:465
QgsPropertyCollectionStack::collection
QgsPropertyCollection * collection(const QString &name)
Returns the first collection with a matching name from the stack.
Definition: qgspropertycollection.cpp:432
qgsproperty.h
QgsPropertyCollection::hasProperty
bool hasProperty(int key) const override
Returns true if the collection contains a property with the specified key.
Definition: qgspropertycollection.cpp:193
qgspropertycollection.h
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
QgsPropertyCollectionStack::toVariant
QVariant toVariant(const QgsPropertiesDefinition &definitions) const override
Saves this property collection to a QVariantMap, wrapped in a QVariant.
Definition: qgspropertycollection.cpp:541
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
QgsPropertyCollectionStack::QgsPropertyCollectionStack
QgsPropertyCollectionStack()=default
Constructor for QgsPropertyCollectionStack.
QgsPropertyCollection::setProperty
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
Definition: qgspropertycollection.cpp:177
QgsPropertyCollectionStack::prepare
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
Definition: qgspropertycollection.cpp:508
QgsPropertyCollectionStack::~QgsPropertyCollectionStack
~QgsPropertyCollectionStack() override
Definition: qgspropertycollection.cpp:377
QgsPropertyCollection::toVariant
QVariant toVariant(const QgsPropertiesDefinition &definitions) const override
Saves this property collection to a QVariantMap, wrapped in a QVariant.
Definition: qgspropertycollection.cpp:310
QgsPropertyCollectionStack::operator=
QgsPropertyCollectionStack & operator=(const QgsPropertyCollectionStack &other)
Definition: qgspropertycollection.cpp:393
QgsProperty::StaticProperty
@ StaticProperty
Static property (QgsStaticProperty)
Definition: qgsproperty.h:239
QgsPropertyCollection::isActive
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
Definition: qgspropertycollection.cpp:258
QgsXmlUtils::writeVariant
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
Definition: qgsxmlutils.cpp:106
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
QgsPropertyCollectionStack
An ordered stack of QgsPropertyCollection containers, where collections added later to the stack will...
Definition: qgspropertycollection.h:405
QgsAbstractPropertyCollection::writeXml
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
Definition: qgspropertycollection.cpp:99
QgsAbstractPropertyCollection::valueAsColor
QColor valueAsColor(int key, const QgsExpressionContext &context, const QColor &defaultColor=QColor(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a color.
Definition: qgspropertycollection.cpp:54
QgsAbstractPropertyCollection::QgsAbstractPropertyCollection
QgsAbstractPropertyCollection(const QString &name=QString())
Constructor for QgsAbstractPropertyCollection.
Definition: qgspropertycollection.cpp:24