23using namespace Qt::StringLiterals;
40 return defaultDateTime;
88 return prop.
valueAsInt( context, defaultValue, ok );
99 return prop.
valueAsBool( context, defaultValue, ok );
104 QVariant collection =
toVariant( definitions );
105 QDomDocument doc = collectionElem.ownerDocument();
107 collectionElem.appendChild( element );
114 return loadVariant( collection.toMap(), definitions );
128 , mProperties( other.mProperties )
129 , mDirty( other.mDirty )
130 , mHasActiveProperties( other.mHasActiveProperties )
131 , mHasDynamicProperties( other.mHasDynamicProperties )
132 , mCount( other.mCount )
134 mProperties.detach();
139 if ( &other ==
this )
142 QgsAbstractPropertyCollection::operator=( other );
143 mProperties = other.mProperties;
144 mProperties.detach();
145 mDirty = other.mDirty;
146 mHasActiveProperties = other.mHasActiveProperties;
147 mHasDynamicProperties = other.mHasDynamicProperties;
148 mCount = other.mCount;
154 return mProperties == other.mProperties;
159 return !( *
this == other );
174 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
175 for ( ; it != mProperties.constEnd(); ++it )
178 keys.insert( it.key() );
187 mHasActiveProperties =
false;
188 mHasDynamicProperties =
false;
195 mProperties.insert( key,
property );
197 mProperties.remove( key );
210 if ( mProperties.isEmpty() )
213 auto it = mProperties.constFind( key );
214 if ( it != mProperties.constEnd() )
215 return static_cast< bool >( *it );
221 if ( mProperties.isEmpty() )
224 return mProperties.value( key );
230 return mProperties[key];
235 if ( mProperties.isEmpty() )
242 return prop.
value( context, defaultValue );
248 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
249 for ( ; it != mProperties.constEnd(); ++it )
251 if ( !it.value().isActive() )
254 result = result && it.value().prepare( context );
261 QSet< QString > cols;
262 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
263 for ( ; it != mProperties.constEnd(); ++it )
265 if ( !it.value().isActive() )
268 cols.unite( it.value().referencedFields( context, ignoreContext ) );
276 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
277 for ( ; it != mProperties.constEnd(); ++it )
279 if ( !it.value().isActive() )
281 vars.unite( it.value().referencedVariables() );
288 if ( mProperties.isEmpty() )
291 auto it = mProperties.constFind( key );
292 if ( it != mProperties.constEnd() )
293 return ( *it ).isActive();
297void QgsPropertyCollection::rescan()
const
299 mHasActiveProperties =
false;
300 mHasDynamicProperties =
false;
302 if ( !mProperties.isEmpty() )
304 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
305 for ( ; it != mProperties.constEnd(); ++it )
309 if ( it.value().isActive() )
311 mHasActiveProperties =
true;
314 mHasDynamicProperties =
true;
327 return mHasActiveProperties;
335 return mHasDynamicProperties;
340 QVariantMap collection;
342 collection.insert( u
"name"_s,
name() );
343 collection.insert( u
"type"_s, u
"collection"_s );
345 QVariantMap properties;
347 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
348 for ( ; it != mProperties.constEnd(); ++it )
352 properties.insert( definitions.value( it.key() ).name(), it.value().toVariant() );
355 collection.insert( u
"properties"_s, properties );
363 QVariantMap collectionMap = collection.toMap();
365 setName( collectionMap.value( u
"name"_s ).toString() );
368 QVariantMap properties = collectionMap.value( u
"properties"_s ).toMap();
369 for (
auto propertyIterator = properties.constBegin(); propertyIterator != properties.constEnd(); ++propertyIterator )
373 QgsPropertiesDefinition::const_iterator it = definitions.constBegin();
374 for ( ; it != definitions.constEnd(); ++it )
376 if ( it->name() == propertyIterator.key() )
388 mProperties.insert( key, prop );
392 mHasActiveProperties = mHasActiveProperties || prop.
isActive();
421 if ( &other ==
this )
437 return mStack.size();
442 qDeleteAll( mStack );
453 return mStack.
value( index );
458 return mStack.
value( index );
463 const auto constMStack = mStack;
474 const auto constMStack = mStack;
485 const auto constMStack = mStack;
496 return static_cast< bool >(
property( key ) );
502 for (
int i = mStack.size() - 1; i >= 0; --i )
523 return p.
value( context, defaultValue );
528 QSet< QString > cols;
529 const auto constMStack = mStack;
532 cols.unite(
collection->referencedFields( context, ignoreContext ) );
540 const auto constMStack = mStack;
543 vars.unite(
collection->referencedVariables() );
551 const auto constMStack = mStack;
554 result = result &&
collection->prepare( context );
562 const auto constMStack = mStack;
572 const auto constMStack = mStack;
587 QVariantList properties;
589 const auto constMStack = mStack;
592 properties.append( child->toVariant( definitions ) );
595 collection.insert( u
"properties"_s, properties );
604 QVariantMap collectionMap =
collection.toMap();
606 setName( collectionMap.value( u
"name"_s ).toString() );
608 QVariantList properties = collectionMap.value( u
"properties"_s ).toList();
610 const auto constProperties = properties;
611 for (
const QVariant &
property : constProperties )
615 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.
QSet< QString > referencedVariables() const override
Returns the set of any variables referenced by the active expression properties in 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.
QSet< QString > referencedVariables() const final
Returns the set of any variables referenced by the active expression properties in the collection.
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.