QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
Public Member Functions | List of all members
QgsAbstractPropertyCollection Class Referenceabstract

Abstract base class for QgsPropertyCollection like objects. More...

#include <qgspropertycollection.h>

Inheritance diagram for QgsAbstractPropertyCollection:
Inheritance graph
[legend]

Public Member Functions

 QgsAbstractPropertyCollection (const QString &name=QString())
 Constructor for QgsAbstractPropertyCollection. More...
 
virtual ~QgsAbstractPropertyCollection ()=default
 
virtual void clear ()=0
 Removes all properties from the collection. More...
 
virtual bool hasActiveProperties () const =0
 Returns true if the collection has any active properties, or false if all properties within the collection are deactivated. More...
 
virtual bool hasDynamicProperties () const =0
 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...
 
virtual bool hasProperty (int key) const =0
 Returns true if the collection contains a property with the specified key. More...
 
virtual bool isActive (int key) const =0
 Returns true if the collection contains an active property with the specified key. More...
 
virtual bool loadVariant (const QVariant &configuration, const QgsPropertiesDefinition &definitions)=0
 Loads this property collection from a QVariantMap, wrapped in a QVariant. More...
 
QString name () const
 Returns the descriptive name of the property collection. More...
 
virtual bool prepare (const QgsExpressionContext &context=QgsExpressionContext()) const =0
 Prepares the collection against a specified expression context. More...
 
virtual QgsProperty property (int key) const =0
 Returns a matching property from the collection, if one exists. More...
 
virtual QSet< int > propertyKeys () const =0
 Returns a list of property keys contained within the collection. More...
 
virtual bool readXml (const QDomElement &collectionElem, const QgsPropertiesDefinition &definitions)
 Reads property collection state from an XML element. More...
 
virtual QSet< QString > referencedFields (const QgsExpressionContext &context=QgsExpressionContext(), bool ignoreContext=false) const =0
 Returns the set of any fields referenced by the active properties from the collection. More...
 
void setName (const QString &name)
 Sets the descriptive name for the property collection. More...
 
virtual QVariant toVariant (const QgsPropertiesDefinition &definitions) const =0
 Saves this property collection to a QVariantMap, wrapped in a QVariant. More...
 
virtual QVariant value (int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const =0
 Returns the calculated value of the property with the specified key from within the 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...
 
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. 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

Abstract base class for QgsPropertyCollection like objects.

Since
QGIS 3.0

Definition at line 41 of file qgspropertycollection.h.

Constructor & Destructor Documentation

◆ QgsAbstractPropertyCollection()

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

Constructor for QgsAbstractPropertyCollection.

The name parameter should be set to a descriptive name for the collection.

Definition at line 24 of file qgspropertycollection.cpp.

◆ ~QgsAbstractPropertyCollection()

virtual QgsAbstractPropertyCollection::~QgsAbstractPropertyCollection ( )
virtualdefault

Member Function Documentation

◆ clear()

virtual void QgsAbstractPropertyCollection::clear ( )
pure virtual

Removes all properties from the collection.

Implemented in QgsPropertyCollection, and QgsPropertyCollectionStack.

◆ hasActiveProperties()

virtual bool QgsAbstractPropertyCollection::hasActiveProperties ( ) const
pure virtual

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

See also
hasDynamicProperties()

Implemented in QgsPropertyCollection, and QgsPropertyCollectionStack.

◆ hasDynamicProperties()

virtual bool QgsAbstractPropertyCollection::hasDynamicProperties ( ) const
pure virtual

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()

Implemented in QgsPropertyCollection, and QgsPropertyCollectionStack.

◆ hasProperty()

virtual bool QgsAbstractPropertyCollection::hasProperty ( int  key) const
pure virtual

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()

Implemented in QgsPropertyCollection, and QgsPropertyCollectionStack.

◆ isActive()

virtual bool QgsAbstractPropertyCollection::isActive ( int  key) const
pure virtual

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.

Implemented in QgsPropertyCollection, and QgsPropertyCollectionStack.

◆ loadVariant()

virtual bool QgsAbstractPropertyCollection::loadVariant ( const QVariant &  configuration,
const QgsPropertiesDefinition definitions 
)
pure virtual

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()

Implemented in QgsPropertyCollectionStack, and QgsPropertyCollection.

◆ name()

QString QgsAbstractPropertyCollection::name ( ) const
inline

Returns the descriptive name of the property collection.

See also
setName()

Definition at line 69 of file qgspropertycollection.h.

◆ prepare()

virtual bool QgsAbstractPropertyCollection::prepare ( const QgsExpressionContext context = QgsExpressionContext()) const
pure virtual

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.

Implemented in QgsPropertyCollection, and QgsPropertyCollectionStack.

◆ property()

virtual QgsProperty QgsAbstractPropertyCollection::property ( int  key) const
pure virtual

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()

Implemented in QgsPropertyCollection, and QgsPropertyCollectionStack.

◆ propertyKeys()

virtual QSet< int > QgsAbstractPropertyCollection::propertyKeys ( ) const
pure virtual

Returns a list of property keys contained within the collection.

Implemented in QgsPropertyCollection, and QgsPropertyCollectionStack.

◆ readXml()

bool QgsAbstractPropertyCollection::readXml ( const QDomElement &  collectionElem,
const QgsPropertiesDefinition definitions 
)
virtual

Reads property collection state from an XML element.

Parameters
collectionElemsource DOM element for property collection's state
definitionsproperty definitions
See also
writeXml()

Definition at line 108 of file qgspropertycollection.cpp.

◆ referencedFields()

virtual QSet< QString > QgsAbstractPropertyCollection::referencedFields ( const QgsExpressionContext context = QgsExpressionContext(),
bool  ignoreContext = false 
) const
pure virtual

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.

Implemented in QgsPropertyCollection, and QgsPropertyCollectionStack.

◆ setName()

void QgsAbstractPropertyCollection::setName ( const QString &  name)
inline

Sets the descriptive name for the property collection.

See also
name()

Definition at line 75 of file qgspropertycollection.h.

◆ toVariant()

virtual QVariant QgsAbstractPropertyCollection::toVariant ( const QgsPropertiesDefinition definitions) const
pure virtual

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()

Implemented in QgsPropertyCollection, and QgsPropertyCollectionStack.

◆ value()

virtual QVariant QgsAbstractPropertyCollection::value ( int  key,
const QgsExpressionContext context,
const QVariant &  defaultValue = QVariant() 
) const
pure virtual

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()

Implemented in QgsPropertyCollection, and QgsPropertyCollectionStack.

◆ valueAsBool()

bool QgsAbstractPropertyCollection::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.

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.
contextQgsExpressionContext to evaluate the property for.
defaultValuedefault boolean to return if the property cannot be calculated as a boolean
okif specified, will be set to true if conversion was successful
Returns
value parsed to bool
See also
value()
valueAsDateTime()
valueAsString()
valueAsColor()
valueAsDouble()
valueAsInt()

Definition at line 88 of file qgspropertycollection.cpp.

◆ valueAsColor()

QColor QgsAbstractPropertyCollection::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.

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.
contextQgsExpressionContext to evaluate the property for.
defaultColordefault color to return if the property cannot be calculated as a color
okif specified, will be set to true if conversion was successful
Returns
value parsed to color
See also
value()
valueAsDateTime()
valueAsString()
valueAsDouble()
valueAsInt()
valueAsBool()

Definition at line 54 of file qgspropertycollection.cpp.

◆ valueAsDateTime()

QDateTime QgsAbstractPropertyCollection::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.

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.
contextQgsExpressionContext to evaluate the property for.
defaultDateTimedefault datetime to return if the property cannot be calculated as a datetime
okif specified, will be set to true if conversion was successful
Returns
value parsed to datetime
See also
value()
valueAsString()
valueAsColor()
valueAsDouble()
valueAsInt()
valueAsBool()
Since
QGIS 3.14

Definition at line 30 of file qgspropertycollection.cpp.

◆ valueAsDouble()

double QgsAbstractPropertyCollection::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.

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.
contextQgsExpressionContext to evaluate the property for.
defaultValuedefault double to return if the property cannot be calculated as a double
okif specified, will be set to true if conversion was successful
Returns
value parsed to double
See also
value()
valueAsDateTime()
valueAsString()
valueAsColor()
valueAsInt()
valueAsBool()

Definition at line 66 of file qgspropertycollection.cpp.

◆ valueAsInt()

int QgsAbstractPropertyCollection::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.

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.
contextQgsExpressionContext to evaluate the property for.
defaultValuedefault integer to return if the property cannot be calculated as a integer
okif specified, will be set to true if conversion was successful
Returns
value parsed to integer
See also
value()
valueAsDateTime()
valueAsString()
valueAsColor()
valueAsDouble()
valueAsBool()

Definition at line 77 of file qgspropertycollection.cpp.

◆ valueAsString()

QString QgsAbstractPropertyCollection::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.

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.
contextQgsExpressionContext to evaluate the property for.
defaultStringdefault string to return if the property cannot be calculated as a string
okif specified, will be set to true if conversion was successful
Returns
value parsed to string
See also
value()
valueAsDateTime()
valueAsColor()
valueAsDouble()
valueAsInt()
valueAsBool()

Definition at line 42 of file qgspropertycollection.cpp.

◆ writeXml()

bool QgsAbstractPropertyCollection::writeXml ( QDomElement &  collectionElem,
const QgsPropertiesDefinition definitions 
) const
virtual

Writes the current state of the property collection into an XML element.

Parameters
collectionElemdestination element for the property collection's state
definitionsproperty definitions
See also
readXml()

Definition at line 99 of file qgspropertycollection.cpp.


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