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 return mProperties.contains( key ) && mProperties.value( key );
191 if ( mProperties.isEmpty() )
194 return mProperties.value( key );
200 return mProperties[ key ];
205 if ( mProperties.isEmpty() )
212 return prop.
value( context, defaultValue );
218 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
219 for ( ; it != mProperties.constEnd(); ++it )
221 if ( !it.value().isActive() )
224 result = result && it.value().prepare( context );
231 QSet< QString > cols;
232 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
233 for ( ; it != mProperties.constEnd(); ++it )
235 if ( !it.value().isActive() )
238 cols.unite( it.value().referencedFields( context ) );
245 if ( mProperties.isEmpty() )
248 return mProperties.value( key ).isActive();
251 void QgsPropertyCollection::rescan()
const 253 mHasActiveProperties =
false;
254 mHasDynamicProperties =
false;
256 if ( !mProperties.isEmpty() )
258 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
259 for ( ; it != mProperties.constEnd(); ++it )
263 if ( it.value().isActive() )
265 mHasActiveProperties =
true;
268 mHasDynamicProperties =
true;
281 return mHasActiveProperties;
289 return mHasDynamicProperties;
294 QVariantMap collection;
296 collection.insert( QStringLiteral(
"name" ),
name() );
297 collection.insert( QStringLiteral(
"type" ), QStringLiteral(
"collection" ) );
299 QVariantMap properties;
301 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
302 for ( ; it != mProperties.constEnd(); ++it )
306 properties.insert( definitions.value( it.key() ).
name(), it.value().toVariant() );
309 collection.insert( QStringLiteral(
"properties" ), properties );
317 QVariantMap collectionMap = collection.toMap();
319 setName( collectionMap.value( QStringLiteral(
"name" ) ).toString() );
322 QVariantMap properties = collectionMap.value( QStringLiteral(
"properties" ) ).toMap();
323 for (
auto propertyIterator = properties.constBegin(); propertyIterator != properties.constEnd(); ++propertyIterator )
327 QgsPropertiesDefinition::const_iterator it = definitions.constBegin();
328 for ( ; it != definitions.constEnd(); ++it )
330 if ( it->name() == propertyIterator.key() )
342 mProperties.insert( key, prop );
346 mHasActiveProperties = mHasActiveProperties || prop.
isActive();
347 mHasDynamicProperties = mHasDynamicProperties ||
390 return mStack.size();
395 qDeleteAll( mStack );
401 mStack.append( collection );
406 return mStack.value( index );
411 return mStack.value( index );
446 return static_cast< bool >(
property( key ) );
452 for (
int i = mStack.size() - 1; i >= 0; --i )
473 return p.
value( context, defaultValue );
478 QSet< QString > cols;
491 result = result && collection->
prepare( context );
519 collection.insert( QStringLiteral(
"type" ), QStringLiteral(
"stack" ) );
520 collection.insert( QStringLiteral(
"name" ),
name() );
522 QVariantList properties;
526 properties.append( child->
toVariant( definitions ) );
529 collection.insert( QStringLiteral(
"properties" ), properties );
538 QVariantMap collectionMap = collection.toMap();
540 setName( collectionMap.value( QStringLiteral(
"name" ) ).toString() );
542 QVariantList properties = collectionMap.value( QStringLiteral(
"properties" ) ).toList();
544 Q_FOREACH (
const QVariant &
property, properties )
547 propertyCollection->
loadVariant( property.toMap(), definitions );
548 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.
Invalid (not set) property.
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.