Skip to content
Permalink
Browse files

Fix evaluation of data defined properties for subsymbols of subsymbols

Fixes #18384
  • Loading branch information
nyalldawson committed Jan 22, 2019
1 parent 855b3b4 commit 9cf2ff31d86e6b7671aaca137a60a7b7a975ef62
Showing with 173 additions and 12 deletions.
  1. +2 −0 python/core/auto_generated/symbology/qgsarrowsymbollayer.sip.in
  2. +8 −0 python/core/auto_generated/symbology/qgsfillsymbollayer.sip.in
  3. +2 −0 python/core/auto_generated/symbology/qgsgeometrygeneratorsymbollayer.sip.in
  4. +2 −0 python/core/auto_generated/symbology/qgslinesymbollayer.sip.in
  5. +2 −0 python/core/auto_generated/symbology/qgsmarkersymbollayer.sip.in
  6. +7 −0 python/core/auto_generated/symbology/qgssymbollayer.sip.in
  7. +2 −0 python/core/auto_generated/symbology/qgsvectorfieldsymbollayer.sip.in
  8. +1 −1 src/core/dxf/qgsdxfexport.cpp
  9. +8 −0 src/core/symbology/qgsarrowsymbollayer.cpp
  10. +1 −0 src/core/symbology/qgsarrowsymbollayer.h
  11. +36 −0 src/core/symbology/qgsfillsymbollayer.cpp
  12. +4 −0 src/core/symbology/qgsfillsymbollayer.h
  13. +8 −0 src/core/symbology/qgsgeometrygeneratorsymbollayer.cpp
  14. +1 −0 src/core/symbology/qgsgeometrygeneratorsymbollayer.h
  15. +9 −0 src/core/symbology/qgslinesymbollayer.cpp
  16. +1 −0 src/core/symbology/qgslinesymbollayer.h
  17. +9 −0 src/core/symbology/qgsmarkersymbollayer.cpp
  18. +1 −0 src/core/symbology/qgsmarkersymbollayer.h
  19. +1 −6 src/core/symbology/qgssymbol.cpp
  20. +5 −0 src/core/symbology/qgssymbollayer.cpp
  21. +7 −0 src/core/symbology/qgssymbollayer.h
  22. +9 −0 src/core/symbology/qgsvectorfieldsymbollayer.cpp
  23. +1 −0 src/core/symbology/qgsvectorfieldsymbollayer.h
  24. +46 −5 tests/src/python/test_qgsmarkerlinesymbollayer.py
  25. BIN ...ta/control_images/symbol_markerline/expected_part_count_variable/expected_part_count_variable.png
  26. BIN ...stdata/control_images/symbol_markerline/expected_part_num_variable/expected_part_num_variable.png
@@ -43,6 +43,8 @@ Create a new QgsArrowSymbolLayer

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

virtual bool hasDataDefinedProperties() const;


double arrowWidth() const;
%Docstring
@@ -734,6 +734,8 @@ Returns the stroke width map unit scale.

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

virtual bool hasDataDefinedProperties() const;


protected:

@@ -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:

@@ -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;
@@ -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;
@@ -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;

@@ -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 );

@@ -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;
@@ -403,6 +403,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:
@@ -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;
@@ -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
@@ -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 )
{
@@ -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; }
@@ -1707,6 +1707,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

@@ -2326,6 +2335,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;
@@ -3337,6 +3355,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;
@@ -3516,6 +3543,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 )
@@ -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;
@@ -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:

@@ -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;

@@ -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; }
@@ -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 )
@@ -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.
@@ -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() ) +
@@ -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;

@@ -1645,6 +1645,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;
@@ -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;

@@ -677,12 +677,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;
@@ -193,6 +193,11 @@ void QgsSymbolLayer::prepareExpressions( const QgsSymbolRenderContext &context )
}
}

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

const QgsPropertiesDefinition &QgsSymbolLayer::propertyDefinitions()
{
QgsSymbolLayer::initPropertyDefinitions();
@@ -398,6 +398,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 );
@@ -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
@@ -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; }

0 comments on commit 9cf2ff3

Please sign in to comment.
You can’t perform that action at this time.