73 return prop.
valueAsInt( context, defaultValue, ok );
84 return prop.
valueAsBool( context, defaultValue, ok );
89 QVariant collection =
toVariant( definitions );
90 QDomDocument doc = collectionElem.ownerDocument();
92 collectionElem.appendChild( element );
99 return loadVariant( collection.toMap(), definitions );
114 , mProperties( other.mProperties )
115 , mDirty( other.mDirty )
116 , mHasActiveProperties( other.mHasActiveProperties )
117 , mHasDynamicProperties( other.mHasDynamicProperties )
118 , mCount( other.mCount )
120 mProperties.detach();
125 QgsAbstractPropertyCollection::operator=( other );
126 mProperties = other.mProperties;
127 mProperties.detach();
128 mDirty = other.mDirty;
129 mHasActiveProperties = other.mHasActiveProperties;
130 mHasDynamicProperties = other.mHasDynamicProperties;
131 mCount = other.mCount;
147 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
148 for ( ; it != mProperties.constEnd(); ++it )
151 keys.insert( it.key() );
160 mHasActiveProperties =
false;
161 mHasDynamicProperties =
false;
168 mProperties.insert( key, property );
170 mProperties.remove( key );
183 if ( mProperties.isEmpty() )
186 auto it = mProperties.constFind( key );
187 if ( it != mProperties.constEnd() )
194 if ( mProperties.isEmpty() )
197 return mProperties.value( key );
203 return mProperties[ key ];
208 if ( mProperties.isEmpty() )
215 return prop.
value( context, defaultValue );
221 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
222 for ( ; it != mProperties.constEnd(); ++it )
224 if ( !it.value().isActive() )
227 result = result && it.value().prepare( context );
234 QSet< QString > cols;
235 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
236 for ( ; it != mProperties.constEnd(); ++it )
238 if ( !it.value().isActive() )
241 cols.unite( it.value().referencedFields( context ) );
248 if ( mProperties.isEmpty() )
251 auto it = mProperties.constFind( key );
252 if ( it != mProperties.constEnd() )
253 return ( *it ).isActive();
257 void QgsPropertyCollection::rescan()
const 259 mHasActiveProperties =
false;
260 mHasDynamicProperties =
false;
262 if ( !mProperties.isEmpty() )
264 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
265 for ( ; it != mProperties.constEnd(); ++it )
269 if ( it.value().isActive() )
271 mHasActiveProperties =
true;
274 mHasDynamicProperties =
true;
287 return mHasActiveProperties;
295 return mHasDynamicProperties;
300 QVariantMap collection;
302 collection.insert( QStringLiteral(
"name" ),
name() );
303 collection.insert( QStringLiteral(
"type" ), QStringLiteral(
"collection" ) );
305 QVariantMap properties;
307 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
308 for ( ; it != mProperties.constEnd(); ++it )
312 properties.insert( definitions.value( it.key() ).
name(), it.value().toVariant() );
315 collection.insert( QStringLiteral(
"properties" ), properties );
323 QVariantMap collectionMap = collection.toMap();
325 setName( collectionMap.value( QStringLiteral(
"name" ) ).toString() );
328 QVariantMap properties = collectionMap.value( QStringLiteral(
"properties" ) ).toMap();
329 for (
auto propertyIterator = properties.constBegin(); propertyIterator != properties.constEnd(); ++propertyIterator )
333 QgsPropertiesDefinition::const_iterator it = definitions.constBegin();
334 for ( ; it != definitions.constEnd(); ++it )
336 if ( it->name() == propertyIterator.key() )
348 mProperties.insert( key, prop );
352 mHasActiveProperties = mHasActiveProperties || prop.
isActive();
353 mHasDynamicProperties = mHasDynamicProperties ||
396 return mStack.size();
401 qDeleteAll( mStack );
407 mStack.append( collection );
412 return mStack.value( index );
417 return mStack.value( index );
422 const auto constMStack = mStack;
433 const auto constMStack = mStack;
444 const auto constMStack = mStack;
455 return static_cast< bool >(
property( key ) );
461 for (
int i = mStack.size() - 1; i >= 0; --i )
482 return p.
value( context, defaultValue );
487 QSet< QString > cols;
488 const auto constMStack = mStack;
499 const auto constMStack = mStack;
510 const auto constMStack = mStack;
520 const auto constMStack = mStack;
532 collection.insert( QStringLiteral(
"type" ), QStringLiteral(
"stack" ) );
533 collection.insert( QStringLiteral(
"name" ),
name() );
535 QVariantList properties;
537 const auto constMStack = mStack;
540 properties.append( child->toVariant( definitions ) );
543 collection.insert( QStringLiteral(
"properties" ), properties );
552 QVariantMap collectionMap = collection.toMap();
554 setName( collectionMap.value( QStringLiteral(
"name" ) ).toString() );
556 QVariantList properties = collectionMap.value( QStringLiteral(
"properties" ) ).toList();
558 const auto constProperties = properties;
559 for (
const QVariant &
property : constProperties )
563 mStack.append( propertyCollection );
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
~QgsPropertyCollectionStack() override
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...
bool hasDynamicProperties() const override
Returns true if the collection has any active, non-static properties, or false if either all non-stat...
QgsAbstractPropertyCollection(const QString &name=QString())
Constructor for QgsAbstractPropertyCollection.
void appendCollection(QgsPropertyCollection *collection)
Appends a collection to the end of the stack, and transfers ownership of the collection to the stack...
Field based property (QgsFieldBasedProperty)
QgsPropertyCollection * at(int index)
Returns the collection at the corresponding index from the stack.
bool loadVariant(const QVariant &collection, const QgsPropertiesDefinition &definitions) override
Loads this property collection from a QVariantMap, wrapped in a QVariant.
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...
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
Expression based property (QgsExpressionBasedProperty)
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 ...
bool hasProperty(int key) const override
Returns true if the collection contains a property with the specified key.
virtual bool loadVariant(const QVariant &configuration, const QgsPropertiesDefinition &definitions)=0
Loads this property collection from a QVariantMap, wrapped in a QVariant.
QgsPropertyCollection * collection(const QString &name)
Returns the first collection with a matching name from the stack.
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
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...
QgsPropertyCollectionStack()=default
Constructor for QgsPropertyCollectionStack.
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.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
void setName(const QString &name)
Sets the descriptive name for the property collection.
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...
An ordered stack of QgsPropertyCollection containers, where collections added later to the stack will...
QgsPropertyCollection(const QString &name=QString())
Constructor for QgsPropertyCollection.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
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.
static QgsProperty fromValue(const QVariant &value, bool isActive=true)
Returns a new StaticProperty created from the specified value.
Type propertyType() const
Returns the property type.
bool loadVariant(const QVariant &property)
Loads this property from a QVariantMap, wrapped in a QVariant.
QgsPropertyCollection & operator=(const QgsPropertyCollection &other)
int count() const
Returns the number of properties contained within the collection.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool loadVariant(const QVariant &configuration, const QgsPropertiesDefinition &definitions) override
Loads this property collection from a QVariantMap, wrapped in a QVariant.
Abstract base class for QgsPropertyCollection like objects.
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.
virtual QgsProperty property(int key) const =0
Returns a matching property from the collection, if one exists.
void clear() override
Removes all properties from the collection.
bool isActive(int key) const override
Returns true if the stack contains an active property with the specified key.
A store for object properties.
QString name() const
Returns the descriptive name of the property collection.
bool hasProperty(int key) const override
Returns true if the collection contains a property with the specified key.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const override
Returns the set of any fields referenced by the active properties from the stack. ...
int count() const
Returns the number of collections contained within the stack.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
QSet< int > propertyKeys() const override
Returns a list of property keys contained within the collection.
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.
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...
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const override
Returns the set of any fields referenced by the active properties from the collection.
void clear() override
Removes all collections from the stack.
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...
QVariant toVariant(const QgsPropertiesDefinition &definitions) const override
Saves this property collection to a QVariantMap, wrapped in a QVariant.
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.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
QSet< int > propertyKeys() const override
Returns a list of property keys contained within the collection.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
QgsPropertyCollectionStack & operator=(const QgsPropertyCollectionStack &other)
virtual QVariant toVariant(const QgsPropertiesDefinition &definitions) const =0
Saves this property collection to a QVariantMap, wrapped in a QVariant.
bool hasDynamicProperties() const override
Returns true if the collection has any active, non-static properties, or false if either all non-stat...
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
QVariant toVariant(const QgsPropertiesDefinition &definitions) const override
Saves this property collection to a QVariantMap, wrapped in a QVariant.
QgsProperty property(int key) const override
Returns the highest priority property with a matching key from within the stack.
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
Static property (QgsStaticProperty)
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...
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
bool isActive() const
Returns whether the property is currently active.
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.