QGIS API Documentation  3.4.3-Madeira (2f64a3c)
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 QString &name=QString())
 Constructor for QgsPropertyCollection. More...
 
 QgsPropertyCollection (const QgsPropertyCollection &other)
 Copy constructor. More...
 
void clear () override
 Removes all properties from the collection. More...
 
int count () const
 Returns the number of properties contained within the collection. More...
 
bool hasActiveProperties () const override
 Returns true if the collection has any active properties, or false if all properties within the collection are deactivated. More...
 
bool hasDynamicProperties () const override
 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. More...
 
bool hasProperty (int key) const override
 Returns true if the collection contains a property with the specified key. More...
 
bool isActive (int key) const override
 Returns true if the collection contains an active property with the specified key. More...
 
bool loadVariant (const QVariant &configuration, const QgsPropertiesDefinition &definitions) override
 Loads this property collection from a QVariantMap, wrapped in a QVariant. More...
 
QgsPropertyCollectionoperator= (const QgsPropertyCollection &other)
 
bool prepare (const QgsExpressionContext &context=QgsExpressionContext()) const override
 Prepares the collection against a specified expression context. More...
 
QgsProperty property (int key) const override
 Returns a matching property from the collection, if one exists. More...
 
virtual QgsPropertyproperty (int key)
 Returns a reference to a matching property from the collection, if one exists. More...
 
QSet< int > propertyKeys () const override
 Returns a list of property keys contained within the collection. More...
 
QSet< QString > referencedFields (const QgsExpressionContext &context=QgsExpressionContext()) const override
 Returns the set of any fields referenced by the active properties from the collection. More...
 
void setProperty (int key, const QgsProperty &property)
 Adds a property to the collection and takes ownership of it. More...
 
void setProperty (int key, const QVariant &value)
 Convenience method, creates a QgsStaticProperty and stores it within the collection. More...
 
QVariant toVariant (const QgsPropertiesDefinition &definitions) const override
 Saves this property collection to a QVariantMap, wrapped in a QVariant. More...
 
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. More...
 
- Public Member Functions inherited from QgsAbstractPropertyCollection
 QgsAbstractPropertyCollection (const QString &name=QString())
 Constructor for QgsAbstractPropertyCollection. More...
 
virtual ~QgsAbstractPropertyCollection ()=default
 
QString name () const
 Returns the descriptive name of the property collection. More...
 
virtual bool readXml (const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
 Reads property collection state from an XML element. More...
 
void setName (const QString &name)
 Sets the descriptive name for the property collection. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
virtual bool writeXml (QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
 Writes the current state of the property collection into an XML element. More...
 

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.

Since
QGIS 3.0

Definition at line 280 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 108 of file qgspropertycollection.cpp.

◆ QgsPropertyCollection() [2/2]

QgsPropertyCollection::QgsPropertyCollection ( const QgsPropertyCollection other)

Copy constructor.

Definition at line 112 of file qgspropertycollection.cpp.

Member Function Documentation

◆ clear()

void QgsPropertyCollection::clear ( )
overridevirtual

Removes all properties from the collection.

Implements QgsAbstractPropertyCollection.

Definition at line 156 of file qgspropertycollection.cpp.

◆ count()

int QgsPropertyCollection::count ( ) const

Returns the number of properties contained within the collection.

Definition at line 135 of file qgspropertycollection.cpp.

◆ hasActiveProperties()

bool QgsPropertyCollection::hasActiveProperties ( ) const
overridevirtual

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 276 of file qgspropertycollection.cpp.

◆ hasDynamicProperties()

bool QgsPropertyCollection::hasDynamicProperties ( ) const
overridevirtual

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 284 of file qgspropertycollection.cpp.

◆ hasProperty()

bool QgsPropertyCollection::hasProperty ( int  key) const
overridevirtual

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 181 of file qgspropertycollection.cpp.

◆ isActive()

bool QgsPropertyCollection::isActive ( int  key) const
overridevirtual

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 243 of file qgspropertycollection.cpp.

◆ loadVariant()

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

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 313 of file qgspropertycollection.cpp.

◆ operator=()

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

Definition at line 123 of file qgspropertycollection.cpp.

◆ prepare()

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

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 215 of file qgspropertycollection.cpp.

◆ property() [1/2]

QgsProperty QgsPropertyCollection::property ( int  key) const
overridevirtual

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 189 of file qgspropertycollection.cpp.

◆ property() [2/2]

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 197 of file qgspropertycollection.cpp.

◆ propertyKeys()

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

Returns a list of property keys contained within the collection.

Implements QgsAbstractPropertyCollection.

Definition at line 144 of file qgspropertycollection.cpp.

◆ referencedFields()

QSet< QString > QgsPropertyCollection::referencedFields ( const QgsExpressionContext context = QgsExpressionContext()) const
overridevirtual

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

Parameters
contextexpression context the properties will be evaluated against.

Implements QgsAbstractPropertyCollection.

Definition at line 229 of file qgspropertycollection.cpp.

◆ setProperty() [1/2]

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 165 of file qgspropertycollection.cpp.

◆ setProperty() [2/2]

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 175 of file qgspropertycollection.cpp.

◆ toVariant()

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

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 292 of file qgspropertycollection.cpp.

◆ value()

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

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

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 203 of file qgspropertycollection.cpp.


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