Skip to content
Permalink
Browse files
Preserve image aspect ratio in legend
  • Loading branch information
mhugent committed Jul 2, 2021
1 parent 6effd6b commit d76fa2bf3b233c933f06a7c7271bc780399a4438
Showing with 3 additions and 4 deletions.
  1. +3 −4 src/core/layertree/qgslayertreemodellegendnode.cpp
@@ -948,17 +948,16 @@ QSizeF QgsImageLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemCo

if ( ctx && ctx->painter )
{
QImage scaledImg = mImage.scaled( settings.wmsLegendSize().toSize(), Qt::KeepAspectRatio, Qt::FastTransformation );
switch ( settings.symbolAlignment() )
{
case Qt::AlignLeft:
default:
ctx->painter->drawImage( QRectF( ctx->columnLeft, ctx->top, settings.wmsLegendSize().width(), settings.wmsLegendSize().height() ),
mImage, QRectF( 0, 0, mImage.width(), mImage.height() ) );
ctx->painter->drawImage( QPointF( ctx->columnLeft, ctx->top ), scaledImg );
break;

case Qt::AlignRight:
ctx->painter->drawImage( QRectF( ctx->columnRight - settings.wmsLegendSize().width(), ctx->top, settings.wmsLegendSize().width(), settings.wmsLegendSize().height() ),
mImage, QRectF( 0, 0, mImage.width(), mImage.height() ) );
ctx->painter->drawImage( QPointF( ctx->columnRight - settings.wmsLegendSize().width(), ctx->top ), scaledImg );
break;
}
}

0 comments on commit d76fa2b

Please sign in to comment.