Skip to content

Commit

Permalink
Fix evaluation of data defined properties for subsymbols of subsymbols
Browse files Browse the repository at this point in the history
Fixes #18384

(cherry picked from commit 9cf2ff3)
  • Loading branch information
nyalldawson committed Jan 24, 2019
1 parent 7bc0844 commit 7e25cea
Show file tree
Hide file tree
Showing 26 changed files with 173 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Create a new QgsArrowSymbolLayer

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

virtual bool hasDataDefinedProperties() const;


double arrowWidth() const;
%Docstring
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ Returns the stroke width map unit scale.

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

virtual bool hasDataDefinedProperties() const;


protected:

Expand Down Expand Up @@ -1563,6 +1565,8 @@ Returns the map unit scale for the pattern's line offset.

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

virtual bool hasDataDefinedProperties() const;


protected:

Expand Down Expand Up @@ -1727,6 +1731,8 @@ Returns the units for the vertical displacement between rows in the pattern.

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

virtual bool hasDataDefinedProperties() const;

virtual void setColor( const QColor &c );

virtual QColor color() const;
Expand Down Expand Up @@ -1798,6 +1804,8 @@ class QgsCentroidFillSymbolLayer : QgsFillSymbolLayer

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

virtual bool hasDataDefinedProperties() const;


void setPointOnSurface( bool pointOnSurface );
bool pointOnSurface() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Gets the expression to generate this geometry.

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

virtual bool hasDataDefinedProperties() const;


virtual bool isCompatibleWithSymbol( QgsSymbol *symbol ) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ Returns the units for the interval between markers.

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

virtual bool hasDataDefinedProperties() const;


virtual void setDataDefinedProperty( QgsSymbolLayer::Property key, const QgsProperty &property );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ Creates a new QgsFilledMarkerSymbolLayer.

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

virtual bool hasDataDefinedProperties() const;

virtual void setColor( const QColor &c );

virtual QColor color() const;
Expand Down
7 changes: 7 additions & 0 deletions python/core/auto_generated/symbology/qgssymbollayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,13 @@ Sets the symbol layer's property collection, used for data defined overrides.
.. seealso:: :py:func:`properties`

.. versionadded:: 3.0
%End

virtual bool hasDataDefinedProperties() const;
%Docstring
Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.

.. versionadded:: 3.4.5
%End

protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ A symbol layer class for displaying displacement arrows based on point layer att

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

virtual bool hasDataDefinedProperties() const;


void setXAttribute( const QString &attribute );
QString xAttribute() const;
Expand Down
2 changes: 1 addition & 1 deletion src/core/dxf/qgsdxfexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4253,7 +4253,7 @@ bool QgsDxfExport::hasDataDefinedProperties( const QgsSymbolLayer *sl, const Qgs
return true;
}

return sl->dataDefinedProperties().hasActiveProperties();
return sl->hasDataDefinedProperties();
}

double QgsDxfExport::dashSize() const
Expand Down
8 changes: 8 additions & 0 deletions src/core/symbology/qgsarrowsymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ QSet<QString> QgsArrowSymbolLayer::usedAttributes( const QgsRenderContext &conte
return attributes;
}

bool QgsArrowSymbolLayer::hasDataDefinedProperties() const
{
if ( QgsSymbolLayer::hasDataDefinedProperties() )
return true;
if ( mSymbol && mSymbol->hasDataDefinedProperties() )
return true;
return false;
}

void QgsArrowSymbolLayer::startRender( QgsSymbolRenderContext &context )
{
Expand Down
1 change: 1 addition & 0 deletions src/core/symbology/qgsarrowsymbollayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CORE_EXPORT QgsArrowSymbolLayer : public QgsLineSymbolLayer
QgsSymbol *subSymbol() override { return mSymbol.get(); }
bool setSubSymbol( QgsSymbol *symbol SIP_TRANSFER ) override;
QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
bool hasDataDefinedProperties() const override;

//! Gets current arrow width
double arrowWidth() const { return mArrowWidth; }
Expand Down
36 changes: 36 additions & 0 deletions src/core/symbology/qgsfillsymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,15 @@ QSet<QString> QgsImageFillSymbolLayer::usedAttributes( const QgsRenderContext &c
return attr;
}

bool QgsImageFillSymbolLayer::hasDataDefinedProperties() const
{
if ( QgsSymbolLayer::hasDataDefinedProperties() )
return true;
if ( mStroke && mStroke->hasDataDefinedProperties() )
return true;
return false;
}


//QgsSVGFillSymbolLayer

Expand Down Expand Up @@ -2325,6 +2334,15 @@ QSet<QString> QgsLinePatternFillSymbolLayer::usedAttributes( const QgsRenderCont
return attr;
}

bool QgsLinePatternFillSymbolLayer::hasDataDefinedProperties() const
{
if ( QgsSymbolLayer::hasDataDefinedProperties() )
return true;
if ( mFillLineSymbol && mFillLineSymbol->hasDataDefinedProperties() )
return true;
return false;
}

double QgsLinePatternFillSymbolLayer::estimateMaxBleed( const QgsRenderContext & ) const
{
return 0;
Expand Down Expand Up @@ -3336,6 +3354,15 @@ QSet<QString> QgsPointPatternFillSymbolLayer::usedAttributes( const QgsRenderCon
return attributes;
}

bool QgsPointPatternFillSymbolLayer::hasDataDefinedProperties() const
{
if ( QgsSymbolLayer::hasDataDefinedProperties() )
return true;
if ( mMarkerSymbol && mMarkerSymbol->hasDataDefinedProperties() )
return true;
return false;
}

void QgsPointPatternFillSymbolLayer::setColor( const QColor &c )
{
mColor = c;
Expand Down Expand Up @@ -3515,6 +3542,15 @@ QSet<QString> QgsCentroidFillSymbolLayer::usedAttributes( const QgsRenderContext
return attributes;
}

bool QgsCentroidFillSymbolLayer::hasDataDefinedProperties() const
{
if ( QgsSymbolLayer::hasDataDefinedProperties() )
return true;
if ( mMarker && mMarker->hasDataDefinedProperties() )
return true;
return false;
}

void QgsCentroidFillSymbolLayer::setOutputUnit( QgsUnitTypes::RenderUnit unit )
{
if ( mMarker )
Expand Down
4 changes: 4 additions & 0 deletions src/core/symbology/qgsfillsymbollayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ class CORE_EXPORT QgsImageFillSymbolLayer: public QgsFillSymbolLayer
QColor dxfColor( QgsSymbolRenderContext &context ) const override;
Qt::PenStyle dxfPenStyle() const override;
QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
bool hasDataDefinedProperties() const override;

protected:
QBrush mBrush;
Expand Down Expand Up @@ -1406,6 +1407,7 @@ class CORE_EXPORT QgsLinePatternFillSymbolLayer: public QgsImageFillSymbolLayer
bool setSubSymbol( QgsSymbol *symbol SIP_TRANSFER ) override;
QgsSymbol *subSymbol() override;
QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
bool hasDataDefinedProperties() const override;

protected:

Expand Down Expand Up @@ -1560,6 +1562,7 @@ class CORE_EXPORT QgsPointPatternFillSymbolLayer: public QgsImageFillSymbolLayer
QgsMapUnitScale mapUnitScale() const override;

QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
bool hasDataDefinedProperties() const override;
void setColor( const QColor &c ) override;
QColor color() const override;

Expand Down Expand Up @@ -1632,6 +1635,7 @@ class CORE_EXPORT QgsCentroidFillSymbolLayer : public QgsFillSymbolLayer
QgsMapUnitScale mapUnitScale() const override;

QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
bool hasDataDefinedProperties() const override;

void setPointOnSurface( bool pointOnSurface ) { mPointOnSurface = pointOnSurface; }
bool pointOnSurface() const { return mPointOnSurface; }
Expand Down
8 changes: 8 additions & 0 deletions src/core/symbology/qgsgeometrygeneratorsymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ QSet<QString> QgsGeometryGeneratorSymbolLayer::usedAttributes( const QgsRenderCo
+ mExpression->referencedColumns();
}

bool QgsGeometryGeneratorSymbolLayer::hasDataDefinedProperties() const
{
// we treat geometry generator layers like they have data defined properties,
// since the WHOLE layer is based on expressions and requires the full expression
// context
return true;
}

bool QgsGeometryGeneratorSymbolLayer::isCompatibleWithSymbol( QgsSymbol *symbol ) const
{
Q_UNUSED( symbol )
Expand Down
1 change: 1 addition & 0 deletions src/core/symbology/qgsgeometrygeneratorsymbollayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class CORE_EXPORT QgsGeometryGeneratorSymbolLayer : public QgsSymbolLayer
bool setSubSymbol( QgsSymbol *symbol SIP_TRANSFER ) override;

QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
bool hasDataDefinedProperties() const override;

/**
* Will always return true.
Expand Down
9 changes: 9 additions & 0 deletions src/core/symbology/qgslinesymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,15 @@ QSet<QString> QgsMarkerLineSymbolLayer::usedAttributes( const QgsRenderContext &
return attr;
}

bool QgsMarkerLineSymbolLayer::hasDataDefinedProperties() const
{
if ( QgsSymbolLayer::hasDataDefinedProperties() )
return true;
if ( mMarker && mMarker->hasDataDefinedProperties() )
return true;
return false;
}

double QgsMarkerLineSymbolLayer::estimateMaxBleed( const QgsRenderContext &context ) const
{
return context.convertToPainterUnits( ( mMarker->size() / 2.0 ), mMarker->sizeUnit(), mMarker->sizeMapUnitScale() ) +
Expand Down
1 change: 1 addition & 0 deletions src/core/symbology/qgslinesymbollayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ class CORE_EXPORT QgsMarkerLineSymbolLayer : public QgsLineSymbolLayer
QgsMapUnitScale mapUnitScale() const override;

QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
bool hasDataDefinedProperties() const override;

void setDataDefinedProperty( QgsSymbolLayer::Property key, const QgsProperty &property ) override;

Expand Down
9 changes: 9 additions & 0 deletions src/core/symbology/qgsmarkersymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,15 @@ QSet<QString> QgsFilledMarkerSymbolLayer::usedAttributes( const QgsRenderContext
return attr;
}

bool QgsFilledMarkerSymbolLayer::hasDataDefinedProperties() const
{
if ( QgsSymbolLayer::hasDataDefinedProperties() )
return true;
if ( mFill && mFill->hasDataDefinedProperties() )
return true;
return false;
}

void QgsFilledMarkerSymbolLayer::setColor( const QColor &c )
{
mColor = c;
Expand Down
1 change: 1 addition & 0 deletions src/core/symbology/qgsmarkersymbollayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ class CORE_EXPORT QgsFilledMarkerSymbolLayer : public QgsSimpleMarkerSymbolLayer
bool setSubSymbol( QgsSymbol *symbol SIP_TRANSFER ) override;
double estimateMaxBleed( const QgsRenderContext &context ) const override;
QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
bool hasDataDefinedProperties() const override;
void setColor( const QColor &c ) override;
QColor color() const override;

Expand Down
7 changes: 1 addition & 6 deletions src/core/symbology/qgssymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,7 @@ bool QgsSymbol::hasDataDefinedProperties() const
{
Q_FOREACH ( QgsSymbolLayer *layer, mLayers )
{
if ( layer->dataDefinedProperties().hasActiveProperties() )
return true;
// we treat geometry generator layers like they have data defined properties,
// since the WHOLE layer is based on expressions and requires the full expression
// context
if ( layer->layerType() == QLatin1String( "GeometryGenerator" ) )
if ( layer->hasDataDefinedProperties() )
return true;
}
return false;
Expand Down
5 changes: 5 additions & 0 deletions src/core/symbology/qgssymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ void QgsSymbolLayer::prepareExpressions( const QgsSymbolRenderContext &context )
}
}

bool QgsSymbolLayer::hasDataDefinedProperties() const
{
return mDataDefinedProperties.hasActiveProperties();
}

const QgsPropertiesDefinition &QgsSymbolLayer::propertyDefinitions()
{
QgsSymbolLayer::initPropertyDefinitions();
Expand Down
7 changes: 7 additions & 0 deletions src/core/symbology/qgssymbollayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,13 @@ class CORE_EXPORT QgsSymbolLayer
*/
void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }

/**
* Returns true if the symbol layer (or any of its sub-symbols) contains data defined properties.
*
* \since QGIS 3.4.5
*/
virtual bool hasDataDefinedProperties() const;

protected:

QgsSymbolLayer( QgsSymbol::SymbolType type, bool locked = false );
Expand Down
9 changes: 9 additions & 0 deletions src/core/symbology/qgsvectorfieldsymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,15 @@ QSet<QString> QgsVectorFieldSymbolLayer::usedAttributes( const QgsRenderContext
return attributes;
}

bool QgsVectorFieldSymbolLayer::hasDataDefinedProperties() const
{
if ( QgsSymbolLayer::hasDataDefinedProperties() )
return true;
if ( mLineSymbol && mLineSymbol->hasDataDefinedProperties() )
return true;
return false;
}

void QgsVectorFieldSymbolLayer::convertPolarToCartesian( double length, double angle, double &x, double &y ) const
{
//convert angle to degree and to north orientation
Expand Down
1 change: 1 addition & 0 deletions src/core/symbology/qgsvectorfieldsymbollayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class CORE_EXPORT QgsVectorFieldSymbolLayer: public QgsMarkerSymbolLayer
void drawPreviewIcon( QgsSymbolRenderContext &context, QSize size ) override;

QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
bool hasDataDefinedProperties() const override;

//setters and getters
void setXAttribute( const QString &attribute ) { mXAttribute = attribute; }
Expand Down
Loading

0 comments on commit 7e25cea

Please sign in to comment.