Skip to content
Permalink
Browse files

Add proper method to determine whether a symbol uses map unit sizes,

and use this to determine whether a legend item needs updating
as a result of a map change

This results in a HUGE speed up when loading large projects where
symbols don't use Millimeter based sizes, as the previous code
assumed only that any non-millimeter size was a map unit based size.

(cherry picked from commit 0ab761c)
  • Loading branch information
nyalldawson committed Dec 21, 2020
1 parent 17bd6da commit d90e81af93744be076afbf00946da5e9c5ca4c08
Showing with 286 additions and 2 deletions.
  1. +2 −0 python/core/auto_generated/symbology/qgsarrowsymbollayer.sip.in
  2. +2 −0 python/core/auto_generated/symbology/qgsellipsesymbollayer.sip.in
  3. +18 −0 python/core/auto_generated/symbology/qgsfillsymbollayer.sip.in
  4. +2 −0 python/core/auto_generated/symbology/qgsgeometrygeneratorsymbollayer.sip.in
  5. +6 −0 python/core/auto_generated/symbology/qgslinesymbollayer.sip.in
  6. +10 −0 python/core/auto_generated/symbology/qgsmarkersymbollayer.sip.in
  7. +2 −0 python/core/auto_generated/symbology/qgsmasksymbollayer.sip.in
  8. +7 −0 python/core/auto_generated/symbology/qgssymbol.sip.in
  9. +7 −0 python/core/auto_generated/symbology/qgssymbollayer.sip.in
  10. +2 −0 python/core/auto_generated/symbology/qgsvectorfieldsymbollayer.sip.in
  11. +4 −2 src/core/layertree/qgslayertreemodellegendnode.cpp
  12. +10 −0 src/core/symbology/qgsarrowsymbollayer.cpp
  13. +1 −0 src/core/symbology/qgsarrowsymbollayer.h
  14. +8 −0 src/core/symbology/qgsellipsesymbollayer.cpp
  15. +1 −0 src/core/symbology/qgsellipsesymbollayer.h
  16. +64 −0 src/core/symbology/qgsfillsymbollayer.cpp
  17. +9 −0 src/core/symbology/qgsfillsymbollayer.h
  18. +11 −0 src/core/symbology/qgsgeometrygeneratorsymbollayer.cpp
  19. +1 −0 src/core/symbology/qgsgeometrygeneratorsymbollayer.h
  20. +26 −0 src/core/symbology/qgslinesymbollayer.cpp
  21. +3 −0 src/core/symbology/qgslinesymbollayer.h
  22. +34 −0 src/core/symbology/qgsmarkersymbollayer.cpp
  23. +5 −0 src/core/symbology/qgsmarkersymbollayer.h
  24. +6 −0 src/core/symbology/qgsmasksymbollayer.cpp
  25. +1 −0 src/core/symbology/qgsmasksymbollayer.h
  26. +17 −0 src/core/symbology/qgssymbol.cpp
  27. +7 −0 src/core/symbology/qgssymbol.h
  28. +5 −0 src/core/symbology/qgssymbollayer.cpp
  29. +7 −0 src/core/symbology/qgssymbollayer.h
  30. +7 −0 src/core/symbology/qgsvectorfieldsymbollayer.cpp
  31. +1 −0 src/core/symbology/qgsvectorfieldsymbollayer.h
@@ -45,6 +45,8 @@ Create a new QgsArrowSymbolLayer

virtual bool hasDataDefinedProperties() const;

virtual bool usesMapUnits() const;


double arrowWidth() const;
%Docstring
@@ -152,6 +152,8 @@ Returns the units for the symbol's stroke width.

virtual QgsUnitTypes::RenderUnit outputUnit() const;

virtual bool usesMapUnits() const;


virtual void setMapUnitScale( const QgsMapUnitScale &scale );

@@ -159,6 +159,8 @@ Returns the map unit scale for the fill's offset.

virtual QgsUnitTypes::RenderUnit outputUnit() const;

virtual bool usesMapUnits() const;


virtual void setMapUnitScale( const QgsMapUnitScale &scale );

@@ -400,6 +402,8 @@ Returns the map unit scale for the fill's offset.

virtual QgsUnitTypes::RenderUnit outputUnit() const;

virtual bool usesMapUnits() const;


virtual void setMapUnitScale( const QgsMapUnitScale &scale );

@@ -743,6 +747,8 @@ Returns the units used for the offset of the shapeburst fill.

virtual QgsUnitTypes::RenderUnit outputUnit() const;

virtual bool usesMapUnits() const;


virtual void setMapUnitScale( const QgsMapUnitScale &scale );

@@ -904,6 +910,8 @@ Used internally when reading/writing symbols.

virtual double estimateMaxBleed( const QgsRenderContext &context ) const;

virtual bool usesMapUnits() const;


virtual QgsSymbol *subSymbol();
virtual bool setSubSymbol( QgsSymbol *symbol /Transfer/ );
@@ -1185,6 +1193,8 @@ Used internally when reading/writing symbols.

virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props ) const;

virtual bool usesMapUnits() const;


void setSvgFilePath( const QString &svgPath );
%Docstring
@@ -1658,6 +1668,8 @@ Returns the map unit scale for the pattern's line offset.

virtual QgsUnitTypes::RenderUnit outputUnit() const;

virtual bool usesMapUnits() const;

virtual void setMapUnitScale( const QgsMapUnitScale &scale );

virtual QgsMapUnitScale mapUnitScale() const;
@@ -1976,6 +1988,8 @@ Returns the unit scale for the vertical offset between rows in the pattern.

virtual QgsUnitTypes::RenderUnit outputUnit() const;

virtual bool usesMapUnits() const;


virtual void setMapUnitScale( const QgsMapUnitScale &scale );

@@ -2062,6 +2076,8 @@ Caller takes ownership of the returned symbol layer.

virtual QgsUnitTypes::RenderUnit outputUnit() const;

virtual bool usesMapUnits() const;


virtual void setMapUnitScale( const QgsMapUnitScale &scale );

@@ -2254,6 +2270,8 @@ Caller takes ownership of the returned symbol layer.

virtual QgsUnitTypes::RenderUnit outputUnit() const;

virtual bool usesMapUnits() const;


virtual void setMapUnitScale( const QgsMapUnitScale &scale );

@@ -46,6 +46,8 @@ that is created by this generator.

virtual void stopFeatureRender( const QgsFeature &feature, QgsRenderContext &context );

virtual bool usesMapUnits() const;


virtual QgsSymbolLayer *clone() const /Factory/;

@@ -66,6 +66,8 @@ Creates a new QgsSimpleLineSymbolLayer from an SLD XML DOM ``element``.

virtual QgsUnitTypes::RenderUnit outputUnit() const;

virtual bool usesMapUnits() const;

virtual void setMapUnitScale( const QgsMapUnitScale &scale );

virtual QgsMapUnitScale mapUnitScale() const;
@@ -770,6 +772,8 @@ Creates a new QgsMarkerLineSymbolLayer from an SLD XML DOM ``element``.

virtual void setOutputUnit( QgsUnitTypes::RenderUnit unit );

virtual bool usesMapUnits() const;

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

virtual bool hasDataDefinedProperties() const;
@@ -880,6 +884,8 @@ serialized in the ``properties`` map (corresponding to the output from

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

virtual bool usesMapUnits() const;


double hashAngle() const;
%Docstring
@@ -260,6 +260,8 @@ Creates a new QgsSimpleMarkerSymbolLayer from an SLD XML element.

virtual QgsMapUnitScale mapUnitScale() const;

virtual bool usesMapUnits() const;

virtual QRectF bounds( QPointF point, QgsSymbolRenderContext &context );

virtual QColor fillColor() const;
@@ -512,6 +514,8 @@ Creates a new QgsFilledMarkerSymbolLayer.

virtual QColor color() const;

virtual bool usesMapUnits() const;


private:
QgsFilledMarkerSymbolLayer( const QgsFilledMarkerSymbolLayer & );
@@ -563,6 +567,8 @@ Used internally when reading/writing symbols.

virtual QgsStringMap properties() const;

virtual bool usesMapUnits() const;


virtual QgsSvgMarkerSymbolLayer *clone() const /Factory/;

@@ -749,6 +755,8 @@ Used internally when reading/writing symbols.

virtual QgsRasterMarkerSymbolLayer *clone() const /Factory/;

virtual bool usesMapUnits() const;


double calculateAspectRatio( QgsSymbolRenderContext &context, double scaledSize, bool &hasDataDefinedAspectRatio ) const;
%Docstring
@@ -911,6 +919,8 @@ Creates a new QgsFontMarkerSymbolLayer from an SLD XML ``element``.

virtual void writeSldMarker( QDomDocument &doc, QDomElement &element, const QgsStringMap &props ) const;

virtual bool usesMapUnits() const;



QString fontFamily() const;
@@ -59,6 +59,8 @@ Create a new QgsMaskMarkerSymbolLayer

virtual QRectF bounds( QPointF point, QgsSymbolRenderContext &context );

virtual bool usesMapUnits() const;


virtual void drawPreviewIcon( QgsSymbolRenderContext &context, QSize size );

@@ -369,6 +369,13 @@ may use it to specify the units for the line width.
:return: output unit, or QgsUnitTypes.RenderUnknownUnit if the symbol contains mixed units

.. seealso:: :py:func:`setOutputUnit`
%End

bool usesMapUnits() const;
%Docstring
Returns ``True`` if the symbol has any components which use map unit based sizes.

.. versionadded:: 3.18
%End

void setOutputUnit( QgsUnitTypes::RenderUnit unit );
@@ -369,6 +369,13 @@ layer may use it to specify the units for the line width.
:return: output unit, or QgsUnitTypes.RenderUnknownUnit if the symbol layer contains mixed units

.. seealso:: :py:func:`setOutputUnit`
%End

virtual bool usesMapUnits() const;
%Docstring
Returns ``True`` if the symbol layer has any components which use map unit based sizes.

.. versionadded:: 3.18
%End

virtual void setMapUnitScale( const QgsMapUnitScale &scale );
@@ -65,6 +65,8 @@ A symbol layer class for displaying displacement arrows based on point layer att

virtual QgsStringMap properties() const;

virtual bool usesMapUnits() const;


virtual void toSld( QDomDocument &doc, QDomElement &element, const QgsStringMap &props ) const;

@@ -266,8 +266,10 @@ QgsSymbolLegendNode::QgsSymbolLegendNode( QgsLayerTreeLayer *nodeLayer, const Qg
connect( qobject_cast<QgsVectorLayer *>( nodeLayer->layer() ), &QgsVectorLayer::symbolFeatureCountMapChanged, this, &QgsSymbolLegendNode::updateLabel );
connect( nodeLayer, &QObject::destroyed, this, [ = ]() { mLayerNode = nullptr; } );

if ( auto *lSymbol = mItem.symbol() )
mSymbolUsesMapUnits = ( lSymbol->outputUnit() != QgsUnitTypes::RenderMillimeters );
if ( const QgsSymbol *symbol = mItem.symbol() )
{
mSymbolUsesMapUnits = symbol->usesMapUnits();
}
}

Qt::ItemFlags QgsSymbolLegendNode::flags() const
@@ -174,6 +174,16 @@ bool QgsArrowSymbolLayer::hasDataDefinedProperties() const
return false;
}

bool QgsArrowSymbolLayer::usesMapUnits() const
{
return mArrowWidthUnit == QgsUnitTypes::RenderMapUnits || mArrowWidthUnit == QgsUnitTypes::RenderMetersInMapUnits
|| mArrowStartWidthUnit == QgsUnitTypes::RenderMapUnits || mArrowStartWidthUnit == QgsUnitTypes::RenderMetersInMapUnits
|| mHeadLengthUnit == QgsUnitTypes::RenderMapUnits || mHeadLengthUnit == QgsUnitTypes::RenderMetersInMapUnits
|| mHeadThicknessUnit == QgsUnitTypes::RenderMapUnits || mHeadThicknessUnit == QgsUnitTypes::RenderMetersInMapUnits
|| mWidthUnit == QgsUnitTypes::RenderMapUnits || mWidthUnit == QgsUnitTypes::RenderMetersInMapUnits
|| mOffsetUnit == QgsUnitTypes::RenderMapUnits || mOffsetUnit == QgsUnitTypes::RenderMetersInMapUnits;
}

void QgsArrowSymbolLayer::startRender( QgsSymbolRenderContext &context )
{
mExpressionScope.reset( new QgsExpressionContextScope() );
@@ -48,6 +48,7 @@ class CORE_EXPORT QgsArrowSymbolLayer : public QgsLineSymbolLayer
bool setSubSymbol( QgsSymbol *symbol SIP_TRANSFER ) override;
QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
bool hasDataDefinedProperties() const override;
bool usesMapUnits() const override;

//! Gets current arrow width
double arrowWidth() const { return mArrowWidth; }
@@ -665,6 +665,14 @@ QgsUnitTypes::RenderUnit QgsEllipseSymbolLayer::outputUnit() const
return unit;
}

bool QgsEllipseSymbolLayer::usesMapUnits() const
{
return mSymbolWidthUnit == QgsUnitTypes::RenderMapUnits || mSymbolWidthUnit == QgsUnitTypes::RenderMetersInMapUnits
|| mSymbolHeightUnit == QgsUnitTypes::RenderMapUnits || mSymbolHeightUnit == QgsUnitTypes::RenderMetersInMapUnits
|| mStrokeWidthUnit == QgsUnitTypes::RenderMapUnits || mStrokeWidthUnit == QgsUnitTypes::RenderMetersInMapUnits
|| mOffsetUnit == QgsUnitTypes::RenderMapUnits || mOffsetUnit == QgsUnitTypes::RenderMetersInMapUnits;
}

void QgsEllipseSymbolLayer::setMapUnitScale( const QgsMapUnitScale &scale )
{
QgsMarkerSymbolLayer::setMapUnitScale( scale );
@@ -137,6 +137,7 @@ class CORE_EXPORT QgsEllipseSymbolLayer: public QgsMarkerSymbolLayer

void setOutputUnit( QgsUnitTypes::RenderUnit unit ) override;
QgsUnitTypes::RenderUnit outputUnit() const override;
bool usesMapUnits() const override;

void setMapUnitScale( const QgsMapUnitScale &scale ) override;
QgsMapUnitScale mapUnitScale() const override;

0 comments on commit d90e81a

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