Skip to content

Commit

Permalink
Fix data defined size legend
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Apr 5, 2019
1 parent 3198112 commit 29fe352
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/core/qgsdatadefinedsizelegend.cpp
Expand Up @@ -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
Expand All @@ -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 )
Expand All @@ -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 )
Expand Down Expand Up @@ -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 );

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

0 comments on commit 29fe352

Please sign in to comment.