QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
Public Member Functions | List of all members
QgsPropertyCollection Class Reference

A grouped map of multiple QgsProperty objects, each referenced by a integer key value. More...

#include <qgspropertycollection.h>

Inheritance diagram for QgsPropertyCollection:
Inheritance graph
[legend]

Public Member Functions

 QgsPropertyCollection (const QgsPropertyCollection &other)
 
 QgsPropertyCollection (const QString &name=QString())
 Constructor for QgsPropertyCollection.
 
void clear () final
 Removes all properties from the collection.
 
int count () const
 Returns the number of properties contained within the collection.
 
bool hasActiveProperties () const final
 Returns true if the collection has any active properties, or false if all properties within the collection are deactivated.
 
bool hasDynamicProperties () const final
 Returns true if the collection has any active, non-static properties, or false if either all non-static properties within the collection are deactivated or if the collection only contains static properties.
 
bool hasProperty (int key) const final
 Returns true if the collection contains a property with the specified key.
 
template<class T >
bool hasProperty (T key) const
 Returns true if the collection contains a property with the specified key.
 
bool isActive (int key) const final
 Returns true if the collection contains an active property with the specified key.
 
template<class T >
bool isActive (T key) const
 Returns true if the property with the specified key is active.
 
bool loadVariant (const QVariant &configuration, const QgsPropertiesDefinition &definitions) final
 Loads this property collection from a QVariantMap, wrapped in a QVariant.
 
bool operator!= (const QgsPropertyCollection &other) const
 
QgsPropertyCollectionoperator= (const QgsPropertyCollection &other)
 
bool operator== (const QgsPropertyCollection &other) const
 
bool prepare (const QgsExpressionContext &context=QgsExpressionContext()) const final
 Prepares the collection against a specified expression context.
 
virtual QgsPropertyproperty (int key)
 Returns a reference to a matching property from the collection, if one exists.
 
QgsProperty property (int key) const final
 Returns a matching property from the collection, if one exists.
 
template<class T >
QgsProperty property (T key) const
 Returns the property with the specified key.
 
QSet< int > propertyKeys () const final
 Returns a list of property keys contained within the collection.
 
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.
 
void setProperty (int key, const QgsProperty &property)
 Adds a property to the collection and takes ownership of it.
 
void setProperty (int key, const QVariant &value)
 Convenience method, creates a QgsStaticProperty and stores it within the collection.
 
template<class T >
void setProperty (T key, const QgsProperty &property)
 Adds a property to the collection and takes ownership of it.
 
template<class T >
void setProperty (T key, const QVariant &value)
 Convenience method, creates a QgsStaticProperty and stores it within the collection.
 
QVariant toVariant (const QgsPropertiesDefinition &definitions) const final
 Saves this property collection to a QVariantMap, wrapped in a QVariant.
 
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.
 
template<class T >
QVariant value (T key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const
 Returns the value of the property with the specified key.
 
- Public Member Functions inherited from QgsAbstractPropertyCollection
 QgsAbstractPropertyCollection (const QString &name=QString())
 Constructor for QgsAbstractPropertyCollection.
 
virtual ~QgsAbstractPropertyCollection ()=default
 
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.
 
void setName (const QString &name)
 Sets the descriptive name for the property 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.
 
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.
 
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.
 
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.
 
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.
 

Detailed Description

A grouped map of multiple QgsProperty objects, each referenced by a integer key value.

Properties within a collection are referenced by an integer key. This is done to avoid the cost of string creation and comparisons which would be required by a string key. The intended use case is that a context specific enum is cast to int and used for the key value. Examples of such enums are :

See also
QgsLayoutObject::DataDefinedProperty
QgsSymbolLayer::Property
QgsPalLabeling::Property
QgsAbstract3DSymbol::Property
QgsDiagramLayerSettings::Property
QgsPalLayerSettings::Property
QgsWidgetWrapper::Property

Definition at line 343 of file qgspropertycollection.h.

Constructor & Destructor Documentation

◆ QgsPropertyCollection() [1/2]

QgsPropertyCollection::QgsPropertyCollection ( const QString &  name = QString())

Constructor for QgsPropertyCollection.

Parameters
namecollection name

Definition at line 120 of file qgspropertycollection.cpp.

◆ QgsPropertyCollection() [2/2]

QgsPropertyCollection::QgsPropertyCollection ( const QgsPropertyCollection other)

Definition at line 124 of file qgspropertycollection.cpp.

Member Function Documentation

◆ clear()

void QgsPropertyCollection::clear ( )
finalvirtual

Removes all properties from the collection.

Implements QgsAbstractPropertyCollection.

Definition at line 178 of file qgspropertycollection.cpp.

◆ count()

int QgsPropertyCollection::count ( ) const

Returns the number of properties contained within the collection.

Definition at line 157 of file qgspropertycollection.cpp.

◆ hasActiveProperties()

bool QgsPropertyCollection::hasActiveProperties ( ) const
finalvirtual

Returns true if the collection has any active properties, or false if all properties within the collection are deactivated.

See also
hasDynamicProperties()

Implements QgsAbstractPropertyCollection.

Definition at line 304 of file qgspropertycollection.cpp.

◆ hasDynamicProperties()

bool QgsPropertyCollection::hasDynamicProperties ( ) const
finalvirtual

Returns true if the collection has any active, non-static properties, or false if either all non-static properties within the collection are deactivated or if the collection only contains static properties.

See also
hasActiveProperties()

Implements QgsAbstractPropertyCollection.

Definition at line 312 of file qgspropertycollection.cpp.

◆ hasProperty() [1/2]

bool QgsPropertyCollection::hasProperty ( int  key) const
finalvirtual

Returns true if the collection contains a property with the specified key.

Parameters
keyinteger key for property. The intended use case is that a context specific enum is cast to int and used for the key value.
See also
property()

Implements QgsAbstractPropertyCollection.

Definition at line 203 of file qgspropertycollection.cpp.

◆ hasProperty() [2/2]

template<class T >
bool QgsPropertyCollection::hasProperty ( key) const
inline

Returns true if the collection contains a property with the specified key.

See also
property()
Since
QGIS 3.36

Definition at line 374 of file qgspropertycollection.h.

◆ isActive() [1/2]

bool QgsPropertyCollection::isActive ( int  key) const
finalvirtual

Returns true if the collection contains an active property with the specified key.

Parameters
keyinteger key for property to test. The intended use case is that a context specific enum is cast to int and used for the key value.

Implements QgsAbstractPropertyCollection.

Definition at line 268 of file qgspropertycollection.cpp.

◆ isActive() [2/2]

template<class T >
bool QgsPropertyCollection::isActive ( key) const
inline

Returns true if the property with the specified key is active.

See also
property()
Since
QGIS 3.36

Definition at line 414 of file qgspropertycollection.h.

◆ loadVariant()

bool QgsPropertyCollection::loadVariant ( const QVariant &  configuration,
const QgsPropertiesDefinition definitions 
)
finalvirtual

Loads this property collection from a QVariantMap, wrapped in a QVariant.

You can use QgsXmlUtils::readVariant to save it to an XML document.

See also
toVariant()

Implements QgsAbstractPropertyCollection.

Definition at line 341 of file qgspropertycollection.cpp.

◆ operator!=()

bool QgsPropertyCollection::operator!= ( const QgsPropertyCollection other) const

Definition at line 152 of file qgspropertycollection.cpp.

◆ operator=()

QgsPropertyCollection & QgsPropertyCollection::operator= ( const QgsPropertyCollection other)

Definition at line 135 of file qgspropertycollection.cpp.

◆ operator==()

bool QgsPropertyCollection::operator== ( const QgsPropertyCollection other) const

Definition at line 147 of file qgspropertycollection.cpp.

◆ prepare()

bool QgsPropertyCollection::prepare ( const QgsExpressionContext context = QgsExpressionContext()) const
finalvirtual

Prepares the collection against a specified expression context.

Calling prepare before evaluating the collection's properties multiple times allows precalculation of expensive setup tasks such as parsing expressions. Returns true if preparation was successful.

Implements QgsAbstractPropertyCollection.

Definition at line 240 of file qgspropertycollection.cpp.

◆ property() [1/3]

QgsProperty & QgsPropertyCollection::property ( int  key)
virtual

Returns a reference to a matching property from the collection, if one exists.

Parameters
keyinteger key for property to return. The intended use case is that a context specific enum is cast to int and used for the key value.
Returns
matching property, or null if no matching, active property found.
See also
hasProperty()

Definition at line 222 of file qgspropertycollection.cpp.

◆ property() [2/3]

QgsProperty QgsPropertyCollection::property ( int  key) const
finalvirtual

Returns a matching property from the collection, if one exists.

Parameters
keyinteger key for property to return. The intended use case is that a context specific enum is cast to int and used for the key value.
Returns
matching property, or null if no matching, active property found.
See also
hasProperty()

Implements QgsAbstractPropertyCollection.

Definition at line 214 of file qgspropertycollection.cpp.

◆ property() [3/3]

template<class T >
QgsProperty QgsPropertyCollection::property ( key) const
inline

Returns the property with the specified key.

Since
QGIS 3.36

Definition at line 382 of file qgspropertycollection.h.

◆ propertyKeys()

QSet< int > QgsPropertyCollection::propertyKeys ( ) const
finalvirtual

Returns a list of property keys contained within the collection.

Implements QgsAbstractPropertyCollection.

Definition at line 166 of file qgspropertycollection.cpp.

◆ referencedFields()

QSet< QString > QgsPropertyCollection::referencedFields ( const QgsExpressionContext context = QgsExpressionContext(),
bool  ignoreContext = false 
) const
finalvirtual

Returns the set of any fields referenced by the active properties from the collection.

Parameters
contextexpression context the properties will be evaluated against.
ignoreContextThis parameter has been added in QGIS 3.14. When set to true, even fields not set in context's fields() will be reported - this is useful e.g. with vector tiles where the actual available field names may not be known beforehand.

Implements QgsAbstractPropertyCollection.

Definition at line 254 of file qgspropertycollection.cpp.

◆ setProperty() [1/4]

void QgsPropertyCollection::setProperty ( int  key,
const QgsProperty property 
)

Adds a property to the collection and takes ownership of it.

Parameters
keyinteger key for property. Any existing property with the same key will be removed and replaced by this property. The intended use case is that a context specific enum is cast to int and used for the key value.
propertyproperty to add. Ownership is transferred to the collection. Setting an invalid property will remove the property from the collection.

Definition at line 187 of file qgspropertycollection.cpp.

◆ setProperty() [2/4]

void QgsPropertyCollection::setProperty ( int  key,
const QVariant &  value 
)

Convenience method, creates a QgsStaticProperty and stores it within the collection.

Parameters
keyinteger key for property. Any existing property with the same key will be deleted and replaced by this property. The intended use case is that a context specific enum is cast to int and used for the key value.
valuestatic value for property

Definition at line 197 of file qgspropertycollection.cpp.

◆ setProperty() [3/4]

template<class T >
void QgsPropertyCollection::setProperty ( key,
const QgsProperty property 
)
inline

Adds a property to the collection and takes ownership of it.

Parameters
keyinteger key for property. Any existing property with the same key will be removed and replaced by this property. The intended use case is that a context specific enum is cast to int and used for the key value.
propertyproperty to add. Ownership is transferred to the collection. Setting an invalid property will remove the property from the collection.
Since
QGIS 3.36

Definition at line 442 of file qgspropertycollection.h.

◆ setProperty() [4/4]

template<class T >
void QgsPropertyCollection::setProperty ( key,
const QVariant &  value 
)
inline

Convenience method, creates a QgsStaticProperty and stores it within the collection.

Parameters
keyinteger key for property. Any existing property with the same key will be deleted and replaced by this property. The intended use case is that a context specific enum is cast to int and used for the key value.
valuestatic value for property
Since
QGIS 3.36

Definition at line 462 of file qgspropertycollection.h.

◆ toVariant()

QVariant QgsPropertyCollection::toVariant ( const QgsPropertiesDefinition definitions) const
finalvirtual

Saves this property collection to a QVariantMap, wrapped in a QVariant.

You can use QgsXmlUtils::writeVariant to save it to an XML document.

See also
loadVariant()

Implements QgsAbstractPropertyCollection.

Definition at line 320 of file qgspropertycollection.cpp.

◆ value() [1/2]

QVariant QgsPropertyCollection::value ( int  key,
const QgsExpressionContext context,
const QVariant &  defaultValue = QVariant() 
) const
finalvirtual

Returns the calculated value of the property with the specified key from within the collection.

If you need the validity of the value (like ok provided from the valueAs* variants) refer to the property() and QgsProperty::value()

Parameters
keyinteger key for property to return. The intended use case is that a context specific enum is cast to int and used for the key value.
contextexpression context to evaluate property against
defaultValuedefault value to return if no matching, active property found or if the property value cannot be calculated
Returns
calculated property value, or default value if property could not be evaluated
See also
valueAsString()
valueAsColor()
valueAsDouble()
valueAsInt()
valueAsBool()

Implements QgsAbstractPropertyCollection.

Definition at line 228 of file qgspropertycollection.cpp.

◆ value() [2/2]

template<class T >
QVariant QgsPropertyCollection::value ( key,
const QgsExpressionContext context,
const QVariant &  defaultValue = QVariant() 
) const
inline

Returns the value of the property with the specified key.

Since
QGIS 3.36

Definition at line 403 of file qgspropertycollection.h.


The documentation for this class was generated from the following files: