15#ifndef QGSPROPERTYCOLLECTION_H
16#define QGSPROPERTYCOLLECTION_H
46 sipType = sipType_QgsPropertyCollection;
48 sipType = sipType_QgsPropertyCollectionStack;
50 sipType = sipType_QgsAbstractPropertyCollection;
68 QString
name()
const {
return mName; }
296 return valueAsDateTime(
static_cast< int >( key ), context, defaultDateTime, ok );
298 template<
class T> QString valueAsString(
const T &key,
const QgsExpressionContext &context,
const QString &defaultString = QString(),
bool *ok =
nullptr ) const
SIP_SKIP
300 return valueAsString(
static_cast< int >( key ), context, defaultString, ok );
302 template<
class T> QColor valueAsColor(
const T &key,
const QgsExpressionContext &context,
const QColor &defaultColor = QColor(),
bool *ok =
nullptr ) const
SIP_SKIP
304 return valueAsColor(
static_cast< int >( key ), context, defaultColor, ok );
306 template<
class T>
double valueAsDouble(
const T &key,
const QgsExpressionContext &context,
double defaultValue = 0.0,
bool *ok =
nullptr ) const
SIP_SKIP
308 return valueAsDouble(
static_cast< int >( key ), context, defaultValue, ok );
310 template<
class T>
int valueAsInt(
const T &key,
const QgsExpressionContext &context,
int defaultValue = 0,
bool *ok =
nullptr ) const
SIP_SKIP
312 return valueAsInt(
static_cast< int >( key ), context, defaultValue, ok );
314 template<
class T>
bool valueAsBool(
const T &key,
const QgsExpressionContext &context,
bool defaultValue =
false,
bool *ok =
nullptr ) const
SIP_SKIP
316 return valueAsBool(
static_cast< int >( key ), context, defaultValue, ok );
394 template<
class T>
QgsProperty &property( T key )
SIP_SKIP {
return property(
static_cast< int >( key ) ); }
397 QVariant value(
int key,
const QgsExpressionContext &context,
const QVariant &defaultValue = QVariant() ) const final;
403 template< class T> QVariant
value( T key, const
QgsExpressionContext &context, const QVariant &defaultValue = QVariant() ) const
SIP_SKIP {
return value(
static_cast< int >( key ), context, defaultValue ); }
407 bool isActive(
int key ) const final;
416 bool hasActiveProperties() const final;
417 bool hasDynamicProperties() const final;
430 void setProperty(
int key, const
QgsProperty &property );
451 void setProperty(
int key,
const QVariant &value );
466 QHash<int, QgsProperty> mProperties;
468 mutable bool mDirty =
false;
469 mutable bool mHasActiveProperties =
false;
470 mutable bool mHasDynamicProperties =
false;
471 mutable int mCount = 0;
557 bool isActive(
int key ) const override;
577 QVariant
value(
int key, const
QgsExpressionContext &context, const QVariant &defaultValue = QVariant() ) const override;
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.
void setName(const QString &name)
Sets the descriptive name for the property collection.
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.
virtual bool hasProperty(int key) const =0
Returns true if the collection contains a property with the specified key.
virtual bool isActive(int key) const =0
Returns true if the collection contains an active property with the specified key.
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.
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.
virtual QgsProperty property(int key) const =0
Returns a matching property from the collection, if one exists.
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.
virtual QSet< int > propertyKeys() const =0
Returns a list of property keys contained within the collection.
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.
virtual void clear()=0
Removes all properties from the collection.
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.
virtual bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const =0
Prepares the collection against a specified expression context.
QgsAbstractPropertyCollection(const QString &name=QString())
Constructor for QgsAbstractPropertyCollection.
virtual bool loadVariant(const QVariant &configuration, const QgsPropertiesDefinition &definitions)=0
Loads this property collection from a QVariantMap, wrapped in a QVariant.
virtual bool hasActiveProperties() const =0
Returns true if the collection has any active properties, or false if all properties within the colle...
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.
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 hasDynamicProperties() const =0
Returns true if the collection has any active, non-static properties, or false if either all non-stat...
virtual bool writeXml(QDomElement &collectionElem, const QgsPropertiesDefinition &definitions) const
Writes the current state of the property collection into an XML element.
virtual ~QgsAbstractPropertyCollection()=default
virtual QVariant toVariant(const QgsPropertiesDefinition &definitions) const =0
Saves this property collection to a QVariantMap, wrapped in a QVariant.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
An ordered stack of QgsPropertyCollection containers, where collections added later to the stack will...
QgsPropertyCollectionStack & operator=(const QgsPropertyCollectionStack &other)
int count() const
Returns the number of collections contained within the stack.
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 ...
void clear() final
Removes all collections from the stack.
QgsPropertyCollectionStack()=default
bool hasProperty(int key) const override
Returns true if the collection contains a property with the specified key.
void appendCollection(QgsPropertyCollection *collection)
Appends a collection to the end of the stack, and transfers ownership of the collection to the stack.
QgsPropertyCollection * at(int index)
Returns the collection at the corresponding index from the stack.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
QSet< int > propertyKeys() const override
Returns a list of property keys contained within the collection.
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.
bool loadVariant(const QVariant &collection, const QgsPropertiesDefinition &definitions) override
Loads this property collection from a QVariantMap, wrapped in a QVariant.
QgsProperty property(int key) const override
Returns the highest priority property with a matching key from within the stack.
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 hasDynamicProperties() const override
Returns true if the collection has any active, non-static properties, or false if either all non-stat...
QVariant toVariant(const QgsPropertiesDefinition &definitions) const override
Saves this property collection to a QVariantMap, wrapped in a QVariant.
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
QgsPropertyCollection & operator=(const QgsPropertyCollection &other)
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.
QSet< int > propertyKeys() const final
Returns a list of property keys contained within the collection.
bool hasProperty(T key) const
Returns true if the collection contains a property with the specified key.
bool hasProperty(int key) const final
Returns true if the collection contains a property with the specified key.
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
void setProperty(T key, const QVariant &value)
Convenience method, creates a QgsStaticProperty and stores it within the collection.
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
void clear() final
Removes all properties from the collection.
int count() const
Returns the number of properties contained within the collection.
QVariant value(T key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const
Returns the value of the property with the specified key.
bool isActive(T key) const
Returns true if the property with the specified key is active.
QgsProperty property(T key) const
Returns the property with the specified key.
void setProperty(T key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
QgsProperty property(int key) const final
Returns a matching property from the collection, if one exists.
QgsPropertyCollection(const QString &name=QString())
Constructor for QgsPropertyCollection.
A store for object properties.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.