@@ -847,8 +847,6 @@ QImage* QgsWmsServer::getLegendGraphics()
847
847
}
848
848
QgsLayerTreeModel legendModel ( &rootGroup );
849
849
850
- QList<QgsLayerTreeNode*> rootChildren = rootGroup.children ();
851
-
852
850
if ( scaleDenominator > 0 )
853
851
legendModel.setLegendFilterByScale ( scaleDenominator );
854
852
@@ -889,7 +887,7 @@ QImage* QgsWmsServer::getLegendGraphics()
889
887
}
890
888
891
889
// find out DPI
892
- QImage* tmpImage = createImage ( 1 , 1 );
890
+ QImage* tmpImage = createImage ( 1 , 1 , false );
893
891
if ( !tmpImage )
894
892
return nullptr ;
895
893
qreal dpmm = tmpImage->dotsPerMeterX () / 1000.0 ;
@@ -917,7 +915,7 @@ QImage* QgsWmsServer::getLegendGraphics()
917
915
if ( !rule.isEmpty () )
918
916
{
919
917
// create second image with the right dimensions
920
- QImage* paintImage = createImage ( ruleSymbolWidth, ruleSymbolHeight );
918
+ QImage* paintImage = createImage ( ruleSymbolWidth, ruleSymbolHeight, false );
921
919
922
920
// go through the items a second time for painting
923
921
QPainter p ( paintImage );
@@ -939,6 +937,7 @@ QImage* QgsWmsServer::getLegendGraphics()
939
937
return paintImage;
940
938
}
941
939
940
+ QList<QgsLayerTreeNode*> rootChildren = rootGroup.children ();
942
941
Q_FOREACH ( QgsLayerTreeNode* node, rootChildren )
943
942
{
944
943
if ( QgsLayerTree::isLayer ( node ) )
@@ -978,7 +977,7 @@ QImage* QgsWmsServer::getLegendGraphics()
978
977
QSizeF minSize = legendRenderer.minimumSize ();
979
978
QSize s ( minSize.width () * dpmm, minSize.height () * dpmm );
980
979
981
- QImage* paintImage = createImage ( s.width (), s.height () );
980
+ QImage* paintImage = createImage ( s.width (), s.height (), false );
982
981
983
982
QPainter p ( paintImage );
984
983
p.setRenderHint ( QPainter::Antialiasing, true );
@@ -1422,7 +1421,7 @@ QImage* QgsWmsServer::getMap( QgsMapSettings& mapSettings, HitTest* hitTest )
1422
1421
QStringList highlightLayersId = QgsWmsConfigParser::addHighlightLayers ( mParameters , layerSetIds );
1423
1422
1424
1423
QList<QgsMapLayer *> layerSet;
1425
- Q_FOREACH ( QString layerSetId, layerSetIds )
1424
+ Q_FOREACH ( QString layerSetId, layerSetIds )
1426
1425
{
1427
1426
layerSet.append ( QgsProject::instance ()->mapLayer ( layerSetId ) );
1428
1427
}
@@ -1967,7 +1966,7 @@ QImage* QgsWmsServer::initializeRendering( QStringList& layersList, QStringList&
1967
1966
#endif
1968
1967
1969
1968
QList<QgsMapLayer *> layers;
1970
- Q_FOREACH ( QString layerId, layerIdList )
1969
+ Q_FOREACH ( QString layerId, layerIdList )
1971
1970
{
1972
1971
layers.append ( QgsProject::instance ()->mapLayer ( layerId ) );
1973
1972
}
@@ -1979,7 +1978,7 @@ QImage* QgsWmsServer::initializeRendering( QStringList& layersList, QStringList&
1979
1978
return theImage;
1980
1979
}
1981
1980
1982
- QImage* QgsWmsServer::createImage ( int width, int height ) const
1981
+ QImage* QgsWmsServer::createImage ( int width, int height, bool useBbox ) const
1983
1982
{
1984
1983
bool conversionSuccess;
1985
1984
@@ -2001,23 +2000,26 @@ QImage* QgsWmsServer::createImage( int width, int height ) const
2001
2000
2002
2001
// Adapt width / height if the aspect ratio does not correspond with the BBOX.
2003
2002
// Required by WMS spec. 1.3.
2004
- bool bboxOk;
2005
- QgsRectangle mapExtent = _parseBBOX ( mParameters .value ( " BBOX" ), bboxOk );
2006
- if ( bboxOk )
2003
+ if ( useBbox )
2007
2004
{
2008
- double mapWidthHeightRatio = mapExtent. width () / mapExtent. height () ;
2009
- double imageWidthHeightRatio = ( double )width / ( double )height ;
2010
- if ( ! qgsDoubleNear ( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
2005
+ bool bboxOk ;
2006
+ QgsRectangle mapExtent = _parseBBOX ( mParameters . value ( " BBOX " ), bboxOk ) ;
2007
+ if ( bboxOk )
2011
2008
{
2012
- if ( mapWidthHeightRatio >= imageWidthHeightRatio )
2009
+ double mapWidthHeightRatio = mapExtent.width () / mapExtent.height ();
2010
+ double imageWidthHeightRatio = ( double )width / ( double )height;
2011
+ if ( !qgsDoubleNear ( mapWidthHeightRatio, imageWidthHeightRatio, 0.0001 ) )
2013
2012
{
2014
- // decrease image height
2015
- height = width / mapWidthHeightRatio;
2016
- }
2017
- else
2018
- {
2019
- // decrease image width
2020
- width = height * mapWidthHeightRatio;
2013
+ if ( mapWidthHeightRatio >= imageWidthHeightRatio )
2014
+ {
2015
+ // decrease image height
2016
+ height = width / mapWidthHeightRatio;
2017
+ }
2018
+ else
2019
+ {
2020
+ // decrease image width
2021
+ width = height * mapWidthHeightRatio;
2022
+ }
2021
2023
}
2022
2024
}
2023
2025
}
0 commit comments