Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix painter scaling and add unit test
  • Loading branch information
mhugent committed Jul 2, 2021
1 parent f287872 commit ccc601b
Show file tree
Hide file tree
Showing 4 changed files with 3,279 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -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;
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/src/python/test_qgsserver_wms_getlegendgraphic.py
Expand Up @@ -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()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ccc601b

Please sign in to comment.