Fix painter scaling and add unit test

This commit is contained in:
Marco Hugentobler 2021-07-02 09:45:34 +02:00
parent f287872798
commit ccc601b31f
4 changed files with 3279 additions and 4 deletions

View File

@ -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;
}
}

View File

@ -1045,6 +1045,19 @@ class TestQgsServerWMSGetLegendGraphic(TestQgsServerWMSTestBase):
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()

File diff suppressed because one or more lines are too long