23using namespace Qt::StringLiterals;
42 return defaultDateTime;
90 return prop.
valueAsInt( context, defaultValue, ok );
101 return prop.
valueAsBool( context, defaultValue, ok );
106 QVariant collection =
toVariant( definitions );
107 QDomDocument doc = collectionElem.ownerDocument();
109 collectionElem.appendChild( element );
116 return loadVariant( collection.toMap(), definitions );
131 , mProperties( other.mProperties )
132 , mDirty( other.mDirty )
133 , mHasActiveProperties( other.mHasActiveProperties )
134 , mHasDynamicProperties( other.mHasDynamicProperties )
135 , mCount( other.mCount )
137 mProperties.detach();
142 if ( &other ==
this )
145 QgsAbstractPropertyCollection::operator=( other );
146 mProperties = other.mProperties;
147 mProperties.detach();
148 mDirty = other.mDirty;
149 mHasActiveProperties = other.mHasActiveProperties;
150 mHasDynamicProperties = other.mHasDynamicProperties;
151 mCount = other.mCount;
157 return mProperties == other.mProperties;
162 return !( *
this == other );
177 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
178 for ( ; it != mProperties.constEnd(); ++it )
181 keys.insert( it.key() );
190 mHasActiveProperties =
false;
191 mHasDynamicProperties =
false;
198 mProperties.insert( key,
property );
200 mProperties.remove( key );
213 if ( mProperties.isEmpty() )
216 auto it = mProperties.constFind( key );
217 if ( it != mProperties.constEnd() )
218 return static_cast< bool >( *it );
224 if ( mProperties.isEmpty() )
227 return mProperties.value( key );
233 return mProperties[ key ];
238 if ( mProperties.isEmpty() )
245 return prop.
value( context, defaultValue );
251 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
252 for ( ; it != mProperties.constEnd(); ++it )
254 if ( !it.value().isActive() )
257 result = result && it.value().prepare( context );
264 QSet< QString > cols;
265 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
266 for ( ; it != mProperties.constEnd(); ++it )
268 if ( !it.value().isActive() )
271 cols.unite( it.value().referencedFields( context, ignoreContext ) );
278 if ( mProperties.isEmpty() )
281 auto it = mProperties.constFind( key );
282 if ( it != mProperties.constEnd() )
283 return ( *it ).isActive();
287void QgsPropertyCollection::rescan()
const
289 mHasActiveProperties =
false;
290 mHasDynamicProperties =
false;
292 if ( !mProperties.isEmpty() )
294 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
295 for ( ; it != mProperties.constEnd(); ++it )
299 if ( it.value().isActive() )
301 mHasActiveProperties =
true;
304 mHasDynamicProperties =
true;
317 return mHasActiveProperties;
325 return mHasDynamicProperties;
330 QVariantMap collection;
332 collection.insert( u
"name"_s,
name() );
333 collection.insert( u
"type"_s, u
"collection"_s );
335 QVariantMap properties;
337 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
338 for ( ; it != mProperties.constEnd(); ++it )
342 properties.insert( definitions.value( it.key() ).name(), it.value().toVariant() );
345 collection.insert( u
"properties"_s, properties );
353 QVariantMap collectionMap = collection.toMap();
355 setName( collectionMap.value( u
"name"_s ).toString() );
358 QVariantMap properties = collectionMap.value( u
"properties"_s ).toMap();
359 for (
auto propertyIterator = properties.constBegin(); propertyIterator != properties.constEnd(); ++propertyIterator )
363 QgsPropertiesDefinition::const_iterator it = definitions.constBegin();
364 for ( ; it != definitions.constEnd(); ++it )
366 if ( it->name() == propertyIterator.key() )
378 mProperties.insert( key, prop );
382 mHasActiveProperties = mHasActiveProperties || prop.
isActive();
383 mHasDynamicProperties = mHasDynamicProperties ||
413 if ( &other ==
this )
429 return mStack.size();
434 qDeleteAll( mStack );
445 return mStack.
value( index );
450 return mStack.
value( index );
455 const auto constMStack = mStack;
466 const auto constMStack = mStack;
477 const auto constMStack = mStack;
488 return static_cast< bool >(
property( key ) );
494 for (
int i = mStack.size() - 1; i >= 0; --i )
515 return p.
value( context, defaultValue );
520 QSet< QString > cols;
521 const auto constMStack = mStack;
524 cols.unite(
collection->referencedFields( context, ignoreContext ) );
532 const auto constMStack = mStack;
535 result = result &&
collection->prepare( context );
543 const auto constMStack = mStack;
553 const auto constMStack = mStack;
568 QVariantList properties;
570 const auto constMStack = mStack;
573 properties.append( child->toVariant( definitions ) );
576 collection.insert( u
"properties"_s, properties );
585 QVariantMap collectionMap =
collection.toMap();
587 setName( collectionMap.value( u
"name"_s ).toString() );
589 QVariantList properties = collectionMap.value( u
"properties"_s ).toList();
591 const auto constProperties = properties;
592 for (
const QVariant &
property : constProperties )
596 mStack.append( propertyCollection );
@ Field
Field based property.
@ Expression
Expression based property.
void setName(const QString &name)
Sets the descriptive name for the property collection.
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.
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.
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.
virtual QgsProperty property(int key) const =0
Returns a matching property from the collection, if one exists.
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.
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.
QgsAbstractPropertyCollection(const QString &name=QString())
Constructor for QgsAbstractPropertyCollection.
virtual bool loadVariant(const QVariant &configuration, const QgsPropertiesDefinition &definitions)=0
Loads this property collection from a QVariantMap, wrapped in a QVariant.
QString name() const
Returns the descriptive name of the property collection.
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
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.
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
virtual QVariant toVariant(const QgsPropertiesDefinition &definitions) const =0
Saves this property collection to a QVariantMap, wrapped in a QVariant.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsPropertyCollectionStack & operator=(const QgsPropertyCollectionStack &other)
int count() const
Returns the number of collections contained within the stack.
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 ...
void clear() final
Removes all collections from the stack.
QgsPropertyCollectionStack()=default
bool hasProperty(int key) const override
Returns true if the collection contains a property with the specified key.
void appendCollection(QgsPropertyCollection *collection)
Appends a collection to the end of the stack, and transfers ownership of the collection to the stack.
QgsPropertyCollection * at(int index)
Returns the collection at the corresponding index from the stack.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
QSet< int > propertyKeys() const override
Returns a list of property keys contained within the collection.
~QgsPropertyCollectionStack() override
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.
bool loadVariant(const QVariant &collection, const QgsPropertiesDefinition &definitions) override
Loads this property collection from 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.
bool isActive(int key) const override
Returns true if the stack contains an active property with the specified key.
QgsPropertyCollection * collection(const QString &name)
Returns the first collection with a matching name from the stack.
bool hasDynamicProperties() const override
Returns true if the collection has any active, non-static properties, or false if either all non-stat...
QVariant toVariant(const QgsPropertiesDefinition &definitions) const override
Saves this property collection to a QVariantMap, wrapped in a QVariant.
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
bool hasDynamicProperties() const final
Returns true if the collection has any active, non-static properties, or false if either all non-stat...
QVariant toVariant(const QgsPropertiesDefinition &definitions) const final
Saves this property collection to a QVariantMap, wrapped in a QVariant.
QgsPropertyCollection & operator=(const QgsPropertyCollection &other)
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const final
Returns the calculated value of the property with the specified key from within the collection.
QSet< int > propertyKeys() const final
Returns a list of property keys contained within the collection.
bool hasProperty(int key) const final
Returns true if the collection contains a property with the specified key.
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
bool operator!=(const QgsPropertyCollection &other) const
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
bool operator==(const QgsPropertyCollection &other) const
bool loadVariant(const QVariant &configuration, const QgsPropertiesDefinition &definitions) final
Loads this property collection from a QVariantMap, wrapped in a QVariant.
void clear() final
Removes all properties from the collection.
int count() const
Returns the number of properties contained within the collection.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const final
Prepares the collection against a specified expression context.
bool hasActiveProperties() const final
Returns true if the collection has any active properties, or false if all properties within the colle...
QgsProperty property(int key) const final
Returns a matching property from the collection, if one exists.
QgsPropertyCollection(const QString &name=QString())
Constructor for QgsPropertyCollection.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext(), bool ignoreContext=false) const final
Returns the set of any fields referenced by the active properties from the collection.
A store for object properties.
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.
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.
Qgis::PropertyType propertyType() const
Returns the property type.
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.
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...
bool isActive() const
Returns whether the property is currently active.
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.
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 valueAsBool(const QgsExpressionContext &context, bool defaultValue=false, bool *ok=nullptr) const
Calculates the current value of the property and interprets it as an boolean.
bool loadVariant(const QVariant &property)
Loads this property from a QVariantMap, wrapped in a QVariant.
static QgsProperty fromValue(const QVariant &value, bool isActive=true)
Returns a new StaticProperty created from the specified value.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.