Skip to content
Permalink
Browse files

Move min/max symbol size handling to QgsSymbolLayerUtils

  • Loading branch information
mhugent committed Jun 30, 2020
1 parent 9ecded8 commit 80b3a81771e362f5c8aee1378664ea89e75ca365
@@ -813,6 +813,17 @@ Encodes a reference to a parametric SVG into a path with parameters according to
Converts a set of symbol layer id to a set of pointers to actual symbol layers carried by the feature renderer.

.. versionadded:: 3.12
%End

static bool restrictSymbolSize( double &size, double minSize, double maxSize );
%Docstring
Restricts size value to min/max size

:param size: value will be set so minSize if below minimum or to maxSize if above minimum
:param minSize: the minimum symbolSize
:param maxSize: the maximum symbol size

:return: true if size value has been changed
%End
};

@@ -567,13 +567,12 @@ QSizeF QgsSymbolLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemC
double size = markerSymbol->size( *context ) / context->scaleFactor();

//If marker size exceeds max marker size, clone symbol and set max size in mm
if ( ( maxSymbolSize > 0 && size > maxSymbolSize ) || ( minSymbolSize > 0 && size < minSymbolSize ) )
if ( QgsSymbolLayerUtils::restrictSymbolSize( size, minSymbolSize, maxSymbolSize ) )
{
minMaxSizeMarkerSymbol.reset( dynamic_cast<QgsMarkerSymbol *>( s->clone() ) );
minMaxSizeMarkerSymbol->setSize( size > maxSymbolSize ? maxSymbolSize : minSymbolSize );
minMaxSizeMarkerSymbol->setSize( size );
minMaxSizeMarkerSymbol->setSizeUnit( QgsUnitTypes::RenderMillimeters );
s = minMaxSizeMarkerSymbol.get();
size = ( size > maxSymbolSize ) ? maxSymbolSize : minSymbolSize;
}

height = size;
@@ -592,15 +591,14 @@ QSizeF QgsSymbolLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemC
if ( QgsLineSymbol *lineSymbol = dynamic_cast<QgsLineSymbol *>( s ) )
{
double width = lineSymbol->width( *context ) / context->scaleFactor();
if ( ( maxSymbolSize > 0 && width > maxSymbolSize ) || ( minSymbolSize > 0 && width < minSymbolSize ) )
if ( QgsSymbolLayerUtils::restrictSymbolSize( width, minSymbolSize, maxSymbolSize ) )
{
minMaxSizeLineSymbol.reset( dynamic_cast<QgsLineSymbol *>( s->clone() ) );
minMaxSizeLineSymbol->setWidth( width > maxSymbolSize ? maxSymbolSize : minSymbolSize );
minMaxSizeLineSymbol->setWidth( width );
minMaxSizeLineSymbol->setWidthUnit( QgsUnitTypes::RenderMillimeters );
s = minMaxSizeLineSymbol.get();
width = ( width > maxSymbolSize ) ? maxSymbolSize : minSymbolSize;
height = width;
}
height = width;
}

if ( ctx && ctx->painter )
@@ -4473,3 +4473,18 @@ QSet<const QgsSymbolLayer *> QgsSymbolLayerUtils::toSymbolLayerPointers( QgsFeat
renderer->accept( &visitor );
return visitor.mSymbolLayers;
}

bool QgsSymbolLayerUtils::restrictSymbolSize( double &size, double minSize, double maxSize )
{
if ( size < minSize )
{
size = minSize;
return true;
}
if ( size > maxSize )
{
size = maxSize;
return true;
}
return false;
}
@@ -728,6 +728,15 @@ class CORE_EXPORT QgsSymbolLayerUtils
* \since QGIS 3.12
*/
static QSet<const QgsSymbolLayer *> toSymbolLayerPointers( QgsFeatureRenderer *renderer, const QSet<QgsSymbolLayerId> &symbolLayerIds );

/**
* \brief Restricts size value to min/max size
* \param size value will be set so minSize if below minimum or to maxSize if above minimum
* \param minSize the minimum symbolSize
* \param maxSize the maximum symbol size
* \return true if size value has been changed
*/
static bool restrictSymbolSize( double &size, double minSize, double maxSize );
};

class QPolygonF;

0 comments on commit 80b3a81

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