Skip to content
Permalink
Browse files

Fix data defined size legend

  • Loading branch information
m-kuhn committed Apr 5, 2019
1 parent 3198112 commit 29fe35265ce989809838936c10d309dbabaa3baf
Showing with 7 additions and 8 deletions.
  1. +7 −8 src/core/qgsdatadefinedsizelegend.cpp
@@ -148,8 +148,8 @@ void QgsDataDefinedSizeLegend::drawCollapsedLegend( QgsRenderContext &context, Q
// optionally scale size values if transformer is defined
if ( mSizeScaleTransformer )
{
for ( auto it = classes.begin(); it != classes.end(); ++it )
it->size = mSizeScaleTransformer->size( it->size );
for ( SizeClass &cls : classes )
cls.size = mSizeScaleTransformer->size( cls.size );
}

// make sure we draw bigger symbols first
@@ -174,7 +174,7 @@ void QgsDataDefinedSizeLegend::drawCollapsedLegend( QgsRenderContext &context, Q

// find out how wide the text will be
int maxTextWidth = 0;
for ( const SizeClass &c : qgis::as_const( mSizeClasses ) )
for ( const SizeClass &c : qgis::as_const( classes ) )
{
int w = fm.width( c.label );
if ( w > maxTextWidth )
@@ -189,7 +189,7 @@ void QgsDataDefinedSizeLegend::drawCollapsedLegend( QgsRenderContext &context, Q

// find out top Y coordinate for individual symbol sizes
QList<int> symbolTopY;
for ( const SizeClass &c : qgis::as_const( mSizeClasses ) )
for ( const SizeClass &c : qgis::as_const( classes ) )
{
int outputSymbolSize = std::round( context.convertToPainterUnits( c.size, s->sizeUnit(), s->sizeMapUnitScale() ) );
switch ( mVAlign )
@@ -243,7 +243,7 @@ void QgsDataDefinedSizeLegend::drawCollapsedLegend( QgsRenderContext &context, Q
p->translate( 0, -textTopY );

// draw symbols first so that they do not cover
for ( const SizeClass &c : qgis::as_const( mSizeClasses ) )
for ( const SizeClass &c : qgis::as_const( classes ) )
{
s->setSize( c.size );

@@ -268,7 +268,7 @@ void QgsDataDefinedSizeLegend::drawCollapsedLegend( QgsRenderContext &context, Q
p->setFont( mFont );

int i = 0;
for ( const SizeClass &c : qgis::as_const( mSizeClasses ) )
for ( const SizeClass &c : qgis::as_const( classes ) )
{
// line from symbol to the text
p->drawLine( outputLargestSize / 2, symbolTopY[i], outputLargestSize + hLengthLine, textCenterY[i] );
@@ -405,8 +405,7 @@ void QgsDataDefinedSizeLegend::writeXml( QDomElement &elem, const QgsReadWriteCo
if ( !mSizeClasses.isEmpty() )
{
QDomElement elemClasses = doc.createElement( QStringLiteral( "classes" ) );
const auto constMSizeClasses = mSizeClasses;
for ( const SizeClass &sc : constMSizeClasses )
for ( const SizeClass &sc : qgis::as_const( mSizeClasses ) )
{
QDomElement elemClass = doc.createElement( QStringLiteral( "class" ) );
elemClass.setAttribute( QStringLiteral( "size" ), sc.size );

0 comments on commit 29fe352

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