Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replace use of expressions for symbology data defined properties
with QgsDataDefined. Allows for direct use of fields and for
deactivating data defined properties without loss of expression/
specified field.
  • Loading branch information
nyalldawson committed May 6, 2015
1 parent 2f6b8e7 commit aab3b15
Show file tree
Hide file tree
Showing 11 changed files with 668 additions and 709 deletions.
118 changes: 110 additions & 8 deletions python/core/symbology-ng/qgssymbollayerv2.sip
Expand Up @@ -124,15 +124,93 @@ class QgsSymbolLayerV2
void setRenderingPass( int renderingPass );
int renderingPass() const;

// symbol layers normally only use additional attributes to provide data defined settings
/** Returns the set of attributes referenced by the layer. This includes attributes
* required by any data defined properties associated with the layer.
*/
virtual QSet<QString> usedAttributes() const;

virtual const QgsExpression* dataDefinedProperty( const QString& property ) const;
virtual QString dataDefinedPropertyString( const QString& property ) const;
virtual void setDataDefinedProperty( const QString& property, const QString& expressionString );
/** Returns a data defined expression for a property, if set
* @deprecated use getDataDefinedProperty instead
*/
virtual const QgsExpression* dataDefinedProperty( const QString& property ) const /Deprecated/;

/** Returns a data defined expression for a property, if set
* @deprecated use getDataDefinedProperty instead
*/
virtual QString dataDefinedPropertyString( const QString& property ) const /Deprecated/;

/** Sets a data defined expression for a property
* @deprecated use setDataDefinedProperty( const QString& property, QgsDataDefined* dataDefined ) instead
*/
virtual void setDataDefinedProperty( const QString& property, const QString& expressionString ) /Deprecated/;

/** Returns the data defined property corresponding to the specified property key
* @param property property key
* @returns matching data defined property if it exists
* @note added in QGIS 2.9
* @see setDataDefinedProperty
* @see hasDataDefinedProperty
* @see evaluateDataDefinedProperty
*/
virtual QgsDataDefined* getDataDefinedProperty( const QString& property ) const;

/** Sets a data defined property for the layer.
* @param property unique property key. Any existing data defined with the same
* key will be deleted and overriden.
* @param dataDefined data defined object to associate with property key. Ownership
* is transferred to the layer.
* @note added in QGIS 2.9
* @see getDataDefinedProperty
* @see removeDataDefinedProperty
*/
virtual void setDataDefinedProperty( const QString& property, QgsDataDefined* dataDefined /Transfer/ );

/** Removes a data defined property from the layer.
* @param property unique property key. If an associated QgsDataDefined object exists,
* it will be deleted and removed from the layer.
* @note added in QGIS 2.9
* @see setDataDefinedProperty
* @see removeDataDefinedProperties
*/
virtual void removeDataDefinedProperty( const QString& property );

/** Removes all data defined properties from the layer and deletes associated
* objects.
* @see removeDataDefinedProperty
* @note added in QGIS 2.9
*/
virtual void removeDataDefinedProperties();
bool hasDataDefinedProperties() const;

/** Checks whether the layer has any associated data defined properties.
* @returns true if layer has data defined properties
* @see hasDataDefinedProperty
*/
virtual bool hasDataDefinedProperties() const;

/** Checks whether the layer has a matching data defined property and if
* that property is currently actived.
* @param property property key
* @returns true if data defined property exists and is active
* @see hasDataDefinedProperties
* @see evaluateDataDefinedProperty
* @see getDataDefinedProperty
* @note added in QGIS 2.9
*/
virtual bool hasDataDefinedProperty( const QString& property ) const;

/** Evaluates the matching data defined property and returns the calculated
* value. Prior to evaluation the data defined property must be prepared
* by calling @link prepareExpressions @endlink.
* @param property property key
* @param feature pointer to the feature to use during expression or field
* evaluation
* @returns calculated value for data defined property, or an invalid QVariant
* if property does not exist or is deactived.
* @see hasDataDefinedProperty
* @see getDataDefinedProperty
* @note added in QGIS 2.9
*/
virtual QVariant evaluateDataDefinedProperty( const QString& property, const QgsFeature* feature ) const;

virtual bool writeDxf( QgsDxfExport& e,
double mmMapUnitScaleFactor,
Expand Down Expand Up @@ -168,12 +246,36 @@ class QgsSymbolLayerV2
protected:
QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false );

/** Prepares all data defined property expressions for evaluation. This should
* be called prior to evaluating data defined properties.
* @param fields associated layer fields
* @param scale map scale
*/
virtual void prepareExpressions( const QgsFields* fields, double scale = -1.0 );
virtual QgsExpression* expression( const QString& property ) const;
/**Saves data defined properties to string map*/

/** Returns the data defined expression associated with a property
* @deprecated use getDataDefinedProperty or evaluateDataDefinedProperty instead
*/
virtual QgsExpression* expression( const QString& property ) const /Deprecated/;

/** Saves all data defined properties to a string map.
* @param stringMap destination string map
* @see restoreDataDefinedProperties
*/
void saveDataDefinedProperties( QgsStringMap& stringMap ) const;
/**Copies data defined properties of this layer to another symbol layer*/

/** Restores all data defined properties from string map.
* @param stringMap source string map
* @note added in QGIS 2.9
* @see saveDataDefinedProperties
*/
void restoreDataDefinedProperties( const QgsStringMap& stringMap );

/** Copies all data defined properties of this layer to another symbol layer.
* @param destLayer destination layer
*/
void copyDataDefinedProperties( QgsSymbolLayerV2* destLayer ) const;

/**Copies paint effect of this layer to another symbol layer
* @param destLayer destination layer
* @note added in QGIS 2.9
Expand Down

0 comments on commit aab3b15

Please sign in to comment.