Skip to content
Permalink
Browse files
Merge pull request #46164 from kadas-albireo/master
Improve layout legend rendering by preserving aspect ratio of legend …
  • Loading branch information
manisandro committed Nov 22, 2021
2 parents a21530b + 4599111 commit eb089c3cc5d61f108777798a66a53eef48603bb0
Showing with 19 additions and 6 deletions.
  1. +19 −6 src/core/layertree/qgslayertreemodellegendnode.cpp
@@ -1248,33 +1248,46 @@ QSizeF QgsWmsLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemCont
{
Q_UNUSED( itemHeight )

const QImage image = getLegendGraphic();

QSize targetSize = image.size();
if ( settings.wmsLegendSize().width() < image.width() )
{
double targetHeight = image.height() * settings.wmsLegendSize().width() / image.width();
targetSize = QSize( settings.wmsLegendSize().width(), targetHeight );
}
else if ( settings.wmsLegendSize().height() < image.height() )
{
double targetWidth = image.width() * settings.wmsLegendSize().height() / image.height();
targetSize = QSize( targetWidth, settings.wmsLegendSize().height() );
}

if ( ctx && ctx->painter )
{
const QImage image = getLegendGraphic();

switch ( settings.symbolAlignment() )
{
case Qt::AlignLeft:
default:
ctx->painter->drawImage( QRectF( ctx->columnLeft,
ctx->top,
settings.wmsLegendSize().width(),
settings.wmsLegendSize().height() ),
targetSize.width(),
targetSize.height() ),
image,
QRectF( QPointF( 0, 0 ), image.size() ) );
break;

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

QJsonObject QgsWmsLegendNode::exportSymbolToJson( const QgsLegendSettings &, const QgsRenderContext & ) const

0 comments on commit eb089c3

Please sign in to comment.