Skip to content

Commit

Permalink
Port symbology and composer to properties framework
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 23, 2017
1 parent 43bbf68 commit ad23240
Show file tree
Hide file tree
Showing 165 changed files with 2,262 additions and 2,927 deletions.
39 changes: 15 additions & 24 deletions python/core/composer/qgscomposerobject.sip
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
35 changes: 7 additions & 28 deletions python/core/composer/qgscomposerutils.sip
Expand Up @@ -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
Expand Down
35 changes: 19 additions & 16 deletions python/core/composer/qgscomposition.sip
Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down
41 changes: 31 additions & 10 deletions python/core/qgsproperty.sip
Expand Up @@ -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()
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 22 additions & 8 deletions python/core/qgspropertycollection.sip
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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;


/**
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion python/core/symbology-ng/qgs25drenderer.sip
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion python/core/symbology-ng/qgsarrowsymbollayer.sip
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion python/core/symbology-ng/qgscategorizedsymbolrenderer.sip
Expand Up @@ -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;

Expand Down

0 comments on commit ad23240

Please sign in to comment.