QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
37 return defaultDateTime;
85 return prop.
valueAsInt( context, defaultValue, ok );
96 return prop.
valueAsBool( context, defaultValue, ok );
101 QVariant collection =
toVariant( definitions );
102 QDomDocument doc = collectionElem.ownerDocument();
104 collectionElem.appendChild( element );
111 return loadVariant( collection.toMap(), definitions );
126 , mProperties( other.mProperties )
127 , mDirty( other.mDirty )
128 , mHasActiveProperties( other.mHasActiveProperties )
129 , mHasDynamicProperties( other.mHasDynamicProperties )
130 , mCount( other.mCount )
132 mProperties.detach();
137 QgsAbstractPropertyCollection::operator=( other );
138 mProperties = other.mProperties;
139 mProperties.detach();
140 mDirty = other.mDirty;
141 mHasActiveProperties = other.mHasActiveProperties;
142 mHasDynamicProperties = other.mHasDynamicProperties;
143 mCount = other.mCount;
149 return mProperties == other.mProperties;
154 return !( *
this == other );
169 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
170 for ( ; it != mProperties.constEnd(); ++it )
173 keys.insert( it.key() );
182 mHasActiveProperties =
false;
183 mHasDynamicProperties =
false;
190 mProperties.insert( key,
property );
192 mProperties.remove( key );
205 if ( mProperties.isEmpty() )
208 auto it = mProperties.constFind( key );
209 if ( it != mProperties.constEnd() )
216 if ( mProperties.isEmpty() )
219 return mProperties.value( key );
225 return mProperties[ key ];
230 if ( mProperties.isEmpty() )
237 return prop.
value( context, defaultValue );
243 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
244 for ( ; it != mProperties.constEnd(); ++it )
246 if ( !it.value().isActive() )
249 result = result && it.value().prepare( context );
256 QSet< QString > cols;
257 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
258 for ( ; it != mProperties.constEnd(); ++it )
260 if ( !it.value().isActive() )
263 cols.unite( it.value().referencedFields( context, ignoreContext ) );
270 if ( mProperties.isEmpty() )
273 auto it = mProperties.constFind( key );
274 if ( it != mProperties.constEnd() )
275 return ( *it ).isActive();
279 void QgsPropertyCollection::rescan()
const
281 mHasActiveProperties =
false;
282 mHasDynamicProperties =
false;
284 if ( !mProperties.isEmpty() )
286 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
287 for ( ; it != mProperties.constEnd(); ++it )
291 if ( it.value().isActive() )
293 mHasActiveProperties =
true;
296 mHasDynamicProperties =
true;
309 return mHasActiveProperties;
317 return mHasDynamicProperties;
322 QVariantMap collection;
324 collection.insert( QStringLiteral(
"name" ),
name() );
325 collection.insert( QStringLiteral(
"type" ), QStringLiteral(
"collection" ) );
327 QVariantMap properties;
329 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
330 for ( ; it != mProperties.constEnd(); ++it )
334 properties.insert( definitions.value( it.key() ).name(), it.value().toVariant() );
337 collection.insert( QStringLiteral(
"properties" ), properties );
345 QVariantMap collectionMap = collection.toMap();
347 setName( collectionMap.value( QStringLiteral(
"name" ) ).toString() );
350 QVariantMap properties = collectionMap.value( QStringLiteral(
"properties" ) ).toMap();
351 for (
auto propertyIterator = properties.constBegin(); propertyIterator != properties.constEnd(); ++propertyIterator )
355 QgsPropertiesDefinition::const_iterator it = definitions.constBegin();
356 for ( ; it != definitions.constEnd(); ++it )
358 if ( it->name() == propertyIterator.key() )
370 mProperties.insert( key, prop );
374 mHasActiveProperties = mHasActiveProperties || prop.
isActive();
375 mHasDynamicProperties = mHasDynamicProperties ||
418 return mStack.size();
423 qDeleteAll( mStack );
434 return mStack.value( index );
439 return mStack.value( index );
444 const auto constMStack = mStack;
455 const auto constMStack = mStack;
466 const auto constMStack = mStack;
477 return static_cast< bool >(
property( key ) );
483 for (
int i = mStack.size() - 1; i >= 0; --i )
504 return p.
value( context, defaultValue );
509 QSet< QString > cols;
510 const auto constMStack = mStack;
521 const auto constMStack = mStack;
532 const auto constMStack = mStack;
542 const auto constMStack = mStack;
554 collection.insert( QStringLiteral(
"type" ), QStringLiteral(
"stack" ) );
557 QVariantList properties;
559 const auto constMStack = mStack;
562 properties.append( child->toVariant( definitions ) );
565 collection.insert( QStringLiteral(
"properties" ), properties );
574 QVariantMap collectionMap =
collection.toMap();
576 setName( collectionMap.value( QStringLiteral(
"name" ) ).toString() );
578 QVariantList properties = collectionMap.value( QStringLiteral(
"properties" ) ).toList();
580 const auto constProperties = properties;
581 for (
const QVariant &
property : constProperties )
585 mStack.append( propertyCollection );
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
bool isActive() const
Returns whether the property is currently active.
int count() const
Returns the number of properties contained within the collection.
bool operator!=(const QgsPropertyCollection &other) const
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
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.
A store for object properties.
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.
bool hasProperty(int key) const override
Returns true if the collection contains a property with the specified key.
QSet< int > propertyKeys() const override
Returns a list of property keys contained within the collection.
@ FieldBasedProperty
Field based property (QgsFieldBasedProperty)
virtual bool readXml(const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
Reads property collection state from an XML element.
Abstract base class for QgsPropertyCollection like objects.
bool loadVariant(const QVariant &configuration, const QgsPropertiesDefinition &definitions) override
Loads this property collection from a QVariantMap, wrapped in a QVariant.
virtual bool loadVariant(const QVariant &configuration, const QgsPropertiesDefinition &definitions)=0
Loads this property collection from a QVariantMap, wrapped in a QVariant.
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 ...
QgsProperty property(int key) const override
Returns the highest priority property with a matching key from within the stack.
Type propertyType() const
Returns the property type.
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 loadVariant(const QVariant &property)
Loads this property from a QVariantMap, wrapped in a QVariant.
void clear() override
Removes all properties from the collection.
void setName(const QString &name)
Sets the descriptive name for the property 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...
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
static QgsProperty fromValue(const QVariant &value, bool isActive=true)
Returns a new StaticProperty created from the specified value.
QgsPropertyCollection(const QString &name=QString())
Constructor for QgsPropertyCollection.
@ ExpressionBasedProperty
Expression based property (QgsExpressionBasedProperty)
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
QgsPropertyCollection * at(int index)
Returns the collection at the corresponding index from the stack.
void clear() override
Removes all collections from the stack.
QString name() const
Returns the descriptive name of the property collection.
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
virtual QgsProperty property(int key) const =0
Returns a matching property from the collection, if one exists.
QgsPropertyCollection & operator=(const QgsPropertyCollection &other)
bool hasDynamicProperties() const override
Returns true if the collection has any active, non-static properties, or false if either all non-stat...
QSet< int > propertyKeys() const override
Returns a list of property keys contained within the collection.
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.
int count() const
Returns the number of collections contained within the stack.
bool hasDynamicProperties() const override
Returns true if the collection has any active, non-static properties, or false if either all non-stat...
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 collection.
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.
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.
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.
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.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
virtual QVariant toVariant(const QgsPropertiesDefinition &definitions) const =0
Saves this property collection to a QVariantMap, wrapped in a QVariant.
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
void appendCollection(QgsPropertyCollection *collection)
Appends a collection to the end of the stack, and transfers ownership of the collection to the stack.
bool operator==(const QgsPropertyCollection &other) const
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.
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 loadVariant(const QVariant &collection, const QgsPropertiesDefinition &definitions) override
Loads this property collection from a QVariantMap, wrapped in a QVariant.
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 hasProperty(int key) const override
Returns true if the collection contains a property with the specified key.
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.
QVariant toVariant(const QgsPropertiesDefinition &definitions) const override
Saves this property collection to a QVariantMap, wrapped in a QVariant.
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.
QgsPropertyCollectionStack()=default
Constructor for QgsPropertyCollectionStack.
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
~QgsPropertyCollectionStack() override
QVariant toVariant(const QgsPropertiesDefinition &definitions) const override
Saves this property collection to a QVariantMap, wrapped in a QVariant.
QgsPropertyCollectionStack & operator=(const QgsPropertyCollectionStack &other)
@ StaticProperty
Static property (QgsStaticProperty)
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
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.
An ordered stack of QgsPropertyCollection containers, where collections added later to the stack will...
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
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.
QgsAbstractPropertyCollection(const QString &name=QString())
Constructor for QgsAbstractPropertyCollection.