Skip to content

Commit

Permalink
Add proper method to determine whether a symbol uses map unit sizes,
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nyalldawson committed Dec 9, 2020
1 parent 1fc6062 commit 0ab761c
Show file tree
Hide file tree
Showing 31 changed files with 286 additions and 2 deletions.
Expand Up @@ -45,6 +45,8 @@ Create a new QgsArrowSymbolLayer

virtual bool hasDataDefinedProperties() const;

virtual bool usesMapUnits() const;


double arrowWidth() const;
%Docstring
Expand Down
Expand Up @@ -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 );

Expand Down
18 changes: 18 additions & 0 deletions python/core/auto_generated/symbology/qgsfillsymbollayer.sip.in
Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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/ );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );

Expand Down
Expand Up @@ -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/;

Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions python/core/auto_generated/symbology/qgsmarkersymbollayer.sip.in
Expand Up @@ -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;
Expand Down Expand Up @@ -512,6 +514,8 @@ Creates a new QgsFilledMarkerSymbolLayer.

virtual QColor color() const;

virtual bool usesMapUnits() const;


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

virtual QgsStringMap properties() const;

virtual bool usesMapUnits() const;


virtual QgsSvgMarkerSymbolLayer *clone() const /Factory/;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -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 );

Expand Down
7 changes: 7 additions & 0 deletions python/core/auto_generated/symbology/qgssymbol.sip.in
Expand Up @@ -381,6 +381,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 );
Expand Down
7 changes: 7 additions & 0 deletions python/core/auto_generated/symbology/qgssymbollayer.sip.in
Expand Up @@ -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 );
Expand Down
Expand Up @@ -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;

Expand Down
6 changes: 4 additions & 2 deletions src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -313,8 +313,10 @@ QgsSymbolLegendNode::QgsSymbolLegendNode( QgsLayerTreeLayer *nodeLayer, const Qg

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
Expand Down
10 changes: 10 additions & 0 deletions src/core/symbology/qgsarrowsymbollayer.cpp
Expand Up @@ -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() );
Expand Down
1 change: 1 addition & 0 deletions src/core/symbology/qgsarrowsymbollayer.h
Expand Up @@ -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; }
Expand Down
8 changes: 8 additions & 0 deletions src/core/symbology/qgsellipsesymbollayer.cpp
Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/core/symbology/qgsellipsesymbollayer.h
Expand Up @@ -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;
Expand Down

0 comments on commit 0ab761c

Please sign in to comment.