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 );
452 return static_cast< bool >(
property( key ) );
458 for (
int i = mStack.size() - 1; i >= 0; --i )
479 return p.
value( context, defaultValue );
484 QSet< QString > cols;
497 result = result && collection->
prepare( context );
525 collection.insert( QStringLiteral(
"type" ), QStringLiteral(
"stack" ) );
526 collection.insert( QStringLiteral(
"name" ),
name() );
528 QVariantList properties;
532 properties.append( child->
toVariant( definitions ) );
535 collection.insert( QStringLiteral(
"properties" ), properties );
544 QVariantMap collectionMap = collection.toMap();
546 setName( collectionMap.value( QStringLiteral(
"name" ) ).toString() );
548 QVariantList properties = collectionMap.value( QStringLiteral(
"properties" ) ).toList();
550 Q_FOREACH (
const QVariant &
property, properties )
553 propertyCollection->
loadVariant( property.toMap(), definitions );
554 mStack.append( propertyCollection );
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
~QgsPropertyCollectionStack() override
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...
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.
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
Expression based property (QgsExpressionBasedProperty)
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...
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(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 isActive() const
Returns whether the property is currently active.
bool hasProperty(int key) const override
Returns true if the collection contains a property with the specified key.
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.
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...
QgsPropertyCollectionStack()=default
Constructor for QgsPropertyCollectionStack.
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.
int count() const
Returns the number of collections contained within the stack.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
QString name() const
Returns the descriptive name of the property collection.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
static QgsProperty fromValue(const QVariant &value, bool isActive=true)
Returns a new StaticProperty created from the specified value.
bool loadVariant(const QVariant &property)
Loads this property from a QVariantMap, wrapped in a QVariant.
QgsPropertyCollection & operator=(const QgsPropertyCollection &other)
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Type propertyType() const
Returns the property type.
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.
virtual QgsProperty property(int key) const =0
Returns a matching property from the collection, if one exists.
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.
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.
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 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. ...
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...
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
QSet< int > propertyKeys() const override
Returns a list of property keys contained within the collection.
int count() const
Returns the number of properties contained within the collection.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const override
Returns the set of any fields referenced by the active properties from the collection.
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...
void clear() override
Removes all collections from the stack.
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...
QVariant toVariant(const QgsPropertiesDefinition &definitions) const override
Saves this property collection to a QVariantMap, wrapped in a QVariant.
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.
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.
QgsProperty property(int key) const override
Returns the highest priority property with a matching key from within the stack.
Invalid (not set) property.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
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...