Skip to content
Permalink
Browse files
Port symbology and composer to properties framework
  • Loading branch information
nyalldawson committed Jan 23, 2017
1 parent 43bbf68 commit ad2324021dc82d9320163b5012d7eacb40ad138e
Show file tree
Hide file tree
Showing 165 changed files with 2,262 additions and 2,927 deletions.
@@ -84,21 +84,24 @@ class QgsComposerObject : QObject, QgsExpressionContextGenerator
*/
virtual bool readXml( const QDomElement& itemElem, const QDomDocument& doc );

/** Returns a reference to the data defined settings for one of the item's data defined properties.
* @param property data defined property to return
* @note this method was added in version 2.5
/** Returns a reference to the object's property collection, used for data defined overrides.
* @note added in QGIS 3.0
* @see setDataDefinedProperties()
*/
QgsDataDefined* dataDefinedProperty( const DataDefinedProperty property ) const;
QgsPropertyCollection& dataDefinedProperties();

/** Sets parameters for a data defined property for the item
* @param property data defined property to set
* @param active true if data defined property is active, false if it is disabled
* @param useExpression true if the expression should be used
* @param expression expression for data defined property
* @param field field name if the data defined property should take its value from a field
* @note this method was added in version 2.5
/** Returns a reference to the object's property collection, used for data defined overrides.
* @note added in QGIS 3.0
* @see setDataDefinedProperties()
*/
//const QgsPropertyCollection& dataDefinedProperties() const;

/** Sets the objects's property collection, used for data defined overrides.
* @param collection property collection. Existing properties will be replaced.
* @note added in QGIS 3.0
* @see dataDefinedProperties()
*/
void setDataDefinedProperty( const DataDefinedProperty property, const bool active, const bool useExpression, const QString &expression, const QString &field );
void setDataDefinedProperties( const QgsPropertyCollection& collection );

/** Set a custom property for the object.
* @param key property key. If a property with the same key already exists it will be overwritten.
@@ -159,18 +162,6 @@ class QgsComposerObject : QObject, QgsExpressionContextGenerator
*/
virtual void refreshDataDefinedProperty( const DataDefinedProperty property = AllProperties, const QgsExpressionContext* context = 0 );

protected:

/** Evaluate a data defined property and return the calculated value
* @returns true if data defined property could be successfully evaluated
* @param property data defined property to evaluate
* @param expressionValue QVariant for storing the evaluated value
* @param context expression context for evaluating expressions. Must have feature and fields set to current
* atlas feature and coverage layer fields prior to calling this method.
* @note this method was added in version 2.5
*/
bool dataDefinedEvaluate( const QgsComposerObject::DataDefinedProperty property, QVariant &expressionValue, const QgsExpressionContext& context = QgsExpressionContext() ) const;

signals:
/** Emitted when the item changes. Signifies that the item widgets must update the
* gui elements.
@@ -102,40 +102,19 @@ class QgsComposerUtils
*/
static bool decodePresetPaperSize( const QString& presetString, double &width, double &height );

/** Reads all data defined properties from xml
* @param itemElem dom element containing data defined properties
* @param dataDefinedNames map of data defined property to name used within xml
* @param dataDefinedProperties map of data defined properties to QgsDataDefined in which to store properties from xml
* @note this method was added in version 2.5
/** Reads all pre 3.0 data defined properties from an XML element.
* @note this method was added in version 3.0
* @see readDataDefinedProperty
* @see writeDataDefinedPropertyMap
*/
static void readDataDefinedPropertyMap( const QDomElement &itemElem,
QMap< QgsComposerObject::DataDefinedProperty, QString >* dataDefinedNames,
QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >* dataDefinedProperties
);
static void readOldDataDefinedPropertyMap( const QDomElement &itemElem,
QgsPropertyCollection& dataDefinedProperties );

/** Reads a single data defined property from xml DOM element
* @param property data defined property to read
* @param ddElem dom element containing settings for data defined property
* @param dataDefinedProperties map of data defined properties to QgsDataDefined in which to store properties from xml
* @note this method was added in version 2.5
/** Reads a pre 3.0 data defined property from an XML DOM element.
* @note this method was added in version 3.0
* @see readDataDefinedPropertyMap
*/
static void readDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property, const QDomElement &ddElem,
QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >* dataDefinedProperties );

/** Writes data defined properties to xml
* @param itemElem DOM element in which to store data defined properties
* @param doc DOM document
* @param dataDefinedNames map of data defined property to name used within xml
* @param dataDefinedProperties map of data defined properties to QgsDataDefined for storing in xml
* @note this method was added in version 2.5
* @see readDataDefinedPropertyMap
*/
static void writeDataDefinedPropertyMap( QDomElement &itemElem, QDomDocument &doc,
const QMap< QgsComposerObject::DataDefinedProperty, QString >* dataDefinedNames,
const QMap< QgsComposerObject::DataDefinedProperty, QgsDataDefined* >* dataDefinedProperties );
static QgsAbstractProperty* readOldDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property, const QDomElement &ddElem ) /Factory/;

/** Returns a font where size is set in pixels and the size has been upscaled with FONT_WORKAROUND_SCALE
* to workaround QT font rendering bugs
@@ -660,22 +660,6 @@ class QgsComposition : QGraphicsScene, QgsExpressionContextGenerator
*/
QList< QgsPaperItem* > pages();

/** Returns a reference to the data defined settings for one of the composition's data defined properties.
* @param property data defined property to return
* @note this method was added in version 2.5
*/
QgsDataDefined* dataDefinedProperty( const QgsComposerObject::DataDefinedProperty property );

/** Sets parameters for a data defined property for the composition
* @param property data defined property to set
* @param active true if data defined property is active, false if it is disabled
* @param useExpression true if the expression should be used
* @param expression expression for data defined property
* @param field field name if the data defined property should take its value from a field
* @note this method was added in version 2.5
*/
void setDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property, bool active, bool useExpression, const QString &expression, const QString &field );

/** Returns the items model attached to the composition
* @returns QgsComposerModel for composition
* @note this method was added in version 2.5
@@ -775,6 +759,25 @@ class QgsComposition : QGraphicsScene, QgsExpressionContextGenerator
*/
QgsExpressionContext createExpressionContext() const;

/** Returns a reference to the composition's property collection, used for data defined overrides.
* @note added in QGIS 3.0
* @see setDataDefinedProperties()
*/
QgsPropertyCollection& dataDefinedProperties();

/** Returns a reference to the composition's property collection, used for data defined overrides.
* @note added in QGIS 3.0
* @see setDataDefinedProperties()
*/
//const QgsPropertyCollection& dataDefinedProperties() const;

/** Sets the composition's property collection, used for data defined overrides.
* @param collection property collection. Existing properties will be replaced.
* @note added in QGIS 3.0
* @see dataDefinedProperties()
*/
void setDataDefinedProperties( const QgsPropertyCollection& collection );

protected:
void init();

@@ -56,7 +56,7 @@ class QgsAbstractProperty

/** Returns a clone of the property.
*/
virtual QgsAbstractProperty* clone() = 0 /Factory/;
virtual QgsAbstractProperty* clone() const = 0 /Factory/;

/** Returns whether the property is currently active.
* @see setActive()
@@ -69,6 +69,12 @@ class QgsAbstractProperty
*/
void setActive( bool active );

/**
* Returns an expression string representing the state of the property, or an empty
* string if the property could not be converted to an expression
*/
virtual QString asExpression() const = 0;

/**
* Prepares the property against a specified expression context. Calling prepare before evaluating the
* property multiple times allows precalculation of expensive setup tasks such as parsing expressions.
@@ -93,6 +99,18 @@ class QgsAbstractProperty
*/
QVariant value( const QgsExpressionContext& context, const QVariant& defaultValue = QVariant() ) const;

/**
* Calculates the current value of the property and interprets it as a string.
* @param context QgsExpressionContext to evaluate the property for.
* @param defaultString default string to return if the property cannot be calculated as a string
* @param ok if specified, will be set to true if conversion was successful
* @returns value parsed to string
* @see value()
* @see valueAsDouble()
* @see valueAsInt()
*/
QString valueAsString( const QgsExpressionContext& context, const QString& defaultString = QString(), bool* ok /Out/ = nullptr ) const;

/** Calculates the current value of the property and interprets it as a color.
* @param context QgsExpressionContext to evaluate the property for.
* @param defaultColor default color to return if the property cannot be calculated as a color
@@ -101,7 +119,7 @@ class QgsAbstractProperty
* @see valueAsDouble()
* @see valueAsInt()
*/
QColor valueAsColor( const QgsExpressionContext& context, const QColor& defaultColor = QColor() ) const;
QColor valueAsColor( const QgsExpressionContext& context, const QColor& defaultColor = QColor(), bool* ok /Out/ = nullptr ) const;

/** Calculates the current value of the property and interprets it as a double.
* @param context QgsExpressionContext to evaluate the property for.
@@ -111,7 +129,7 @@ class QgsAbstractProperty
* @see valueAsInt()
* @see valueAsColor()
*/
double valueAsDouble( const QgsExpressionContext& context, double defaultValue = 0.0 ) const;
double valueAsDouble( const QgsExpressionContext& context, double defaultValue = 0.0, bool* ok /Out/ = nullptr ) const;

/** Calculates the current value of the property and interprets it as an integer.
* @param context QgsExpressionContext to evaluate the property for.
@@ -121,7 +139,7 @@ class QgsAbstractProperty
* @see valueAsDouble()
* @see valueAsColor()
*/
int valueAsInt( const QgsExpressionContext& context, int defaultValue = 0 ) const;
int valueAsInt( const QgsExpressionContext& context, int defaultValue = 0, bool* ok /Out/ = nullptr ) const;

/**
* Calculates the current value of the property and interprets it as an boolean.
@@ -132,7 +150,7 @@ class QgsAbstractProperty
* @see valueAsDouble()
* @see valueAsColor()
*/
bool valueAsBool( const QgsExpressionContext& context, bool defaultValue = false ) const;
bool valueAsBool( const QgsExpressionContext& context, bool defaultValue = false, bool* ok /Out/ = nullptr ) const;

/** Writes the current state of the property into an XML element
* @param propertyElem destination element for the property's state
@@ -197,7 +215,8 @@ class QgsStaticProperty : QgsAbstractProperty

virtual Type propertyType() const;

virtual QgsStaticProperty* clone() /Factory/;
virtual QgsStaticProperty* clone() const /Factory/;
virtual QString asExpression() const;

/** Sets the static value for the property.
* @param value property value
@@ -238,11 +257,12 @@ class QgsFieldBasedProperty : QgsAbstractProperty
* @param field field name
* @param isActive whether the property is intially active
*/
QgsFieldBasedProperty( const QString& field = QString(), bool isActive = false );
QgsFieldBasedProperty( const QString& field = QString(), bool isActive = true );

virtual Type propertyType() const;

virtual QgsFieldBasedProperty* clone() /Factory/;
virtual QgsFieldBasedProperty* clone() const /Factory/;
virtual QString asExpression() const;

/** Sets the field name the property references.
* @param field field name
@@ -285,11 +305,12 @@ class QgsExpressionBasedProperty : QgsAbstractProperty
* @param expression expression string
* @param isActive whether the property is intially active
*/
QgsExpressionBasedProperty( const QString& expression = QString(), bool isActive = false );
QgsExpressionBasedProperty( const QString& expression = QString(), bool isActive = true );

virtual Type propertyType() const;

virtual QgsExpressionBasedProperty* clone() /Factory/;
virtual QgsExpressionBasedProperty* clone() const /Factory/;
virtual QString asExpression() const;

/** Sets the expression to use for the property value.
* @param expression expression string
@@ -88,6 +88,20 @@ class QgsAbstractPropertyCollection
*/
virtual QVariant value( int key, const QgsExpressionContext& context, const QVariant& defaultValue = QVariant() ) const = 0;

/**
* Calculates the current value of the property with the specified key and interprets it as a string.
* @param key integer 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.
* @param context QgsExpressionContext to evaluate the property for.
* @param defaultValue default string to return if the property cannot be calculated as a string
* @param ok if specified, will be set to true if conversion was successful
* @returns value parsed to string
* @see value()
* @see valueAsInteger()
* @see valueAsColor()
*/
QString valueAsString( int key, const QgsExpressionContext& context, const QString& defaultString = QString(), bool* ok /Out/ = nullptr ) const;


/**
* Calculates the current value of the property with the specified key and interprets it as a color.
@@ -100,7 +114,7 @@ class QgsAbstractPropertyCollection
* @see valueAsDouble()
* @see valueAsInteger()
*/
QColor valueAsColor( int key, const QgsExpressionContext& context, const QColor& defaultColor = QColor() ) const;
QColor valueAsColor( int key, const QgsExpressionContext& context, const QColor& defaultColor = QColor(), bool* ok /Out/ = nullptr ) const;

/**
* Calculates the current value of the property with the specified key and interprets it as a double.
@@ -113,7 +127,7 @@ class QgsAbstractPropertyCollection
* @see valueAsInteger()
* @see valueAsColor()
*/
double valueAsDouble( int key, const QgsExpressionContext& context, double defaultValue = 0.0 ) const;
double valueAsDouble( int key, const QgsExpressionContext& context, double defaultValue = 0.0, bool* ok /Out/ = nullptr ) const;

/**
* Calculates the current value of the property with the specified key and interprets it as an integer.
@@ -126,7 +140,7 @@ class QgsAbstractPropertyCollection
* @see valueAsDouble()
* @see valueAsColor()
*/
int valueAsInt( int key, const QgsExpressionContext& context, int defaultValue = 0 ) const;
int valueAsInt( int key, const QgsExpressionContext& context, int defaultValue = 0, bool* ok /Out/ = nullptr ) const;

/**
* Calculates the current value of the property with the specified key and interprets it as an boolean.
@@ -139,7 +153,7 @@ class QgsAbstractPropertyCollection
* @see valueAsDouble()
* @see valueAsColor()
*/
bool valueAsBool( int key, const QgsExpressionContext& context, bool defaultValue = false ) const;
bool valueAsBool( int key, const QgsExpressionContext& context, bool defaultValue = false, bool* ok /Out/ = nullptr ) const;


/**
@@ -164,14 +178,14 @@ class QgsAbstractPropertyCollection

/**
* Returns true if the collection has any active properties, or false if all properties
* within the collection are deactived.
* within the collection are deactivated.
* @see hasActiveDynamicProperties()
*/
virtual bool hasActiveProperties() 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 deactived or if the collection only contains static properties.
* within the collection are deactivated or if the collection only contains static properties.
* @see hasActiveProperties()
*/
virtual bool hasActiveDynamicProperties() const = 0;
@@ -323,14 +337,14 @@ class QgsPropertyCollectionStack : QgsAbstractPropertyCollection
QgsPropertyCollection* collection( const QString& name );

/** Returns true if the collection has any active properties, or false if all properties
* within the collection are deactived.
* within the collection are deactivated.
* @see hasActiveProperty()
* @see hasActiveDynamicProperties()
*/
bool hasActiveProperties() const;

/** Returns true if the collection has any active, non-static properties, or false if either all non-static properties
* within the collection are deactived or if the collection only contains static properties.
* within the collection are deactivated or if the collection only contains static properties.
* @see hasActiveProperties()
*/
bool hasActiveDynamicProperties() const;
@@ -33,7 +33,7 @@ class Qgs25DRenderer : QgsFeatureRenderer
void startRender( QgsRenderContext& context, const QgsFields& fields );
void stopRender( QgsRenderContext& context );

QSet<QString> usedAttributes() const;
QSet<QString> usedAttributes( const QgsRenderContext& context ) const;
QgsFeatureRenderer* clone() const;

virtual QgsSymbol* symbolForFeature( QgsFeature& feature, QgsRenderContext& context );
@@ -32,7 +32,7 @@ class QgsArrowSymbolLayer : public QgsLineSymbolLayer
virtual bool setSubSymbol( QgsSymbol* symbol /Transfer/ );

/** Return a list of attributes required to render this feature */
virtual QSet<QString> usedAttributes() const;
virtual QSet<QString> usedAttributes( const QgsRenderContext& context ) const;

/** Get current arrow width */
double arrowWidth() const;
@@ -59,7 +59,7 @@ class QgsCategorizedSymbolRenderer : QgsFeatureRenderer

virtual void stopRender( QgsRenderContext& context );

virtual QSet<QString> usedAttributes() const;
virtual QSet<QString> usedAttributes( const QgsRenderContext& context ) const;

virtual QString dump() const;

0 comments on commit ad23240

Please sign in to comment.