Skip to content
Permalink
Browse files
Fix painter scaling and add unit test
  • Loading branch information
mhugent committed Jul 2, 2021
1 parent f287872 commit ccc601b31fe51608f512187f54268fc219799ed2
@@ -946,18 +946,23 @@ QSizeF QgsImageLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemCo
{
Q_UNUSED( itemHeight )

if ( ctx && ctx->painter )
if ( ctx && ctx->painter && ctx->context )
{
QImage scaledImg = mImage.scaled( settings.wmsLegendSize().toSize(), Qt::KeepAspectRatio, Qt::FastTransformation );
QgsScopedRenderContextScaleToPixels scopedScaleToPixels( *( ctx->context ) );
double scaleFactor = ctx->context->scaleFactor();
double imgWidth = settings.wmsLegendSize().width() * scaleFactor;
double imgHeight = settings.wmsLegendSize().height() * scaleFactor;

QImage scaledImg = mImage.scaled( QSizeF( imgWidth, imgHeight ).toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation );
switch ( settings.symbolAlignment() )
{
case Qt::AlignLeft:
default:
ctx->painter->drawImage( QPointF( ctx->columnLeft, ctx->top ), scaledImg );
ctx->painter->drawImage( QPointF( ctx->columnLeft * scaleFactor, ctx->top * scaleFactor ), scaledImg );
break;

case Qt::AlignRight:
ctx->painter->drawImage( QPointF( ctx->columnRight - settings.wmsLegendSize().width(), ctx->top ), scaledImg );
ctx->painter->drawImage( QPointF( ctx->columnRight * scaleFactor - imgWidth, ctx->top * scaleFactor ), scaledImg );
break;
}
}
@@ -1045,6 +1045,19 @@ def testJsonSymbolMaxMinScale(self):
self.assertEqual(node['scaleMaxDenom'], 1000)
self.assertEqual(node['scaleMinDenom'], 10000)

def testLegendPlaceholderIcon(self):
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": self.testdata_path + 'test_project_legend_placeholder_image.qgs',
"SERVICE": "WMS",
"VERSION": "1.3",
"REQUEST": "GetLegendGraphic",
"LAYER": "landsat",
"FORMAT": "image/png",
}.items())])

r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_Legend_Placeholder_Icon")


if __name__ == '__main__':
unittest.main()
Binary file not shown.

0 comments on commit ccc601b

Please sign in to comment.