QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
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;
159 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
160 for ( ; it != mProperties.constEnd(); ++it )
163 keys.insert( it.key() );
172 mHasActiveProperties =
false;
173 mHasDynamicProperties =
false;
180 mProperties.insert( key,
property );
182 mProperties.remove( key );
195 if ( mProperties.isEmpty() )
198 auto it = mProperties.constFind( key );
199 if ( it != mProperties.constEnd() )
206 if ( mProperties.isEmpty() )
209 return mProperties.value( key );
215 return mProperties[ key ];
220 if ( mProperties.isEmpty() )
227 return prop.
value( context, defaultValue );
233 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
234 for ( ; it != mProperties.constEnd(); ++it )
236 if ( !it.value().isActive() )
239 result = result && it.value().prepare( context );
246 QSet< QString > cols;
247 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
248 for ( ; it != mProperties.constEnd(); ++it )
250 if ( !it.value().isActive() )
253 cols.unite( it.value().referencedFields( context, ignoreContext ) );
260 if ( mProperties.isEmpty() )
263 auto it = mProperties.constFind( key );
264 if ( it != mProperties.constEnd() )
265 return ( *it ).isActive();
269 void QgsPropertyCollection::rescan()
const
271 mHasActiveProperties =
false;
272 mHasDynamicProperties =
false;
274 if ( !mProperties.isEmpty() )
276 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
277 for ( ; it != mProperties.constEnd(); ++it )
281 if ( it.value().isActive() )
283 mHasActiveProperties =
true;
286 mHasDynamicProperties =
true;
299 return mHasActiveProperties;
307 return mHasDynamicProperties;
312 QVariantMap collection;
314 collection.insert( QStringLiteral(
"name" ),
name() );
315 collection.insert( QStringLiteral(
"type" ), QStringLiteral(
"collection" ) );
317 QVariantMap properties;
319 QHash<int, QgsProperty>::const_iterator it = mProperties.constBegin();
320 for ( ; it != mProperties.constEnd(); ++it )
324 properties.insert( definitions.value( it.key() ).name(), it.value().toVariant() );
327 collection.insert( QStringLiteral(
"properties" ), properties );
335 QVariantMap collectionMap = collection.toMap();
337 setName( collectionMap.value( QStringLiteral(
"name" ) ).toString() );
340 QVariantMap properties = collectionMap.value( QStringLiteral(
"properties" ) ).toMap();
341 for (
auto propertyIterator = properties.constBegin(); propertyIterator != properties.constEnd(); ++propertyIterator )
345 QgsPropertiesDefinition::const_iterator it = definitions.constBegin();
346 for ( ; it != definitions.constEnd(); ++it )
348 if ( it->name() == propertyIterator.key() )
360 mProperties.insert( key, prop );
364 mHasActiveProperties = mHasActiveProperties || prop.
isActive();
365 mHasDynamicProperties = mHasDynamicProperties ||
408 return mStack.size();
413 qDeleteAll( mStack );
424 return mStack.value( index );
429 return mStack.value( index );
434 const auto constMStack = mStack;
445 const auto constMStack = mStack;
456 const auto constMStack = mStack;
467 return static_cast< bool >(
property( key ) );
473 for (
int i = mStack.size() - 1; i >= 0; --i )
494 return p.
value( context, defaultValue );
499 QSet< QString > cols;
500 const auto constMStack = mStack;
511 const auto constMStack = mStack;
522 const auto constMStack = mStack;
532 const auto constMStack = mStack;
544 collection.insert( QStringLiteral(
"type" ), QStringLiteral(
"stack" ) );
547 QVariantList properties;
549 const auto constMStack = mStack;
552 properties.append( child->toVariant( definitions ) );
555 collection.insert( QStringLiteral(
"properties" ), properties );
564 QVariantMap collectionMap =
collection.toMap();
566 setName( collectionMap.value( QStringLiteral(
"name" ) ).toString() );
568 QVariantList properties = collectionMap.value( QStringLiteral(
"properties" ) ).toList();
570 const auto constProperties = properties;
571 for (
const QVariant &
property : constProperties )
575 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 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.
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.