mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Fix painter scaling and add unit test
This commit is contained in:
parent
f287872798
commit
ccc601b31f
@ -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 @@ 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()
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 8.7 KiB |
3257
tests/testdata/qgis_server/test_project_legend_placeholder_image.qgs
vendored
Normal file
3257
tests/testdata/qgis_server/test_project_legend_placeholder_image.qgs
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user