From 9552777d6ad4a0043a05a3061ebae646f6df3dd9 Mon Sep 17 00:00:00 2001 From: David Signer Date: Thu, 21 Feb 2019 16:36:45 +0100 Subject: [PATCH] use scale and mapUnitsPerPixel from map parameters bbox and size. in case bbox and size is given in the GetLegendGraphics request, the size of symbols defined by map units is calculated regarding the scale of that. calculate mMmPerMapUnit with mapUnitsPerPixel to avoid to have redundant info fixes #21309 (cherry-picked from a04f91b840f8bce5cbcbd9d9211fa3aa6fe236c5 7de50a016d896281be2192cf20986f052c411722 3e861635143cb2a7055602bdf369dbcb66fdac25) --- .../auto_generated/qgslegendsettings.sip.in | 18 ++++++++++++++++++ src/core/qgslegendsettings.cpp | 10 ++++++++++ src/core/qgslegendsettings.h | 14 ++++++++++++++ src/server/services/wms/qgswmsrenderer.cpp | 10 ++++++++++ 4 files changed, 52 insertions(+) diff --git a/python/core/auto_generated/qgslegendsettings.sip.in b/python/core/auto_generated/qgslegendsettings.sip.in index fccba00168db..e3920f0fe4af 100644 --- a/python/core/auto_generated/qgslegendsettings.sip.in +++ b/python/core/auto_generated/qgslegendsettings.sip.in @@ -192,6 +192,24 @@ Sets the legend map ``scale``. The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. .. seealso:: :py:func:`mapScale` +%End + + double mapUnitsPerPixel() const; +%Docstring +Returns the factor of map units per pixel for symbols with size given in map units calculated by dpi and mmPerMapUnit + +.. seealso:: :py:func:`setMapUnitsPerPixel` + +.. versionadded:: 3.6 +%End + + void setMapUnitsPerPixel( double mapUnitsPerPixel ); +%Docstring +Sets the the mmPerMapUnit calculated by ``mapUnitsPerPixel`` mostly taken from the map settings. + +.. seealso:: :py:func:`mapUnitsPerPixel` + +.. versionadded:: 3.6 %End int dpi() const; diff --git a/src/core/qgslegendsettings.cpp b/src/core/qgslegendsettings.cpp index b47bc581e036..07e959658bc1 100644 --- a/src/core/qgslegendsettings.cpp +++ b/src/core/qgslegendsettings.cpp @@ -37,6 +37,16 @@ QgsLegendSettings::QgsLegendSettings() rstyle( QgsLegendStyle::SymbolLabel ).rfont().setPointSizeF( 12.0 ); } +double QgsLegendSettings::mapUnitsPerPixel() const +{ + return 1 / ( mMmPerMapUnit * ( mDpi / 25.4 ) ); +} + +void QgsLegendSettings::setMapUnitsPerPixel( double mapUnitsPerPixel ) +{ + mMmPerMapUnit = 1 / mapUnitsPerPixel / ( mDpi / 25.4 ); +} + QStringList QgsLegendSettings::evaluateItemText( const QString &text, const QgsExpressionContext &context ) const { const QString textToRender = QgsExpression::replaceExpressionText( text, &context ); diff --git a/src/core/qgslegendsettings.h b/src/core/qgslegendsettings.h index 1dcb9f73566c..b4a9afd0f5bd 100644 --- a/src/core/qgslegendsettings.h +++ b/src/core/qgslegendsettings.h @@ -178,6 +178,20 @@ class CORE_EXPORT QgsLegendSettings */ void setMapScale( double scale ) { mMapScale = scale; } + /** + * Returns the factor of map units per pixel for symbols with size given in map units calculated by dpi and mmPerMapUnit + * \see setMapUnitsPerPixel() + * \since QGIS 3.6 + */ + double mapUnitsPerPixel() const; + + /** + * Sets the the mmPerMapUnit calculated by \a mapUnitsPerPixel mostly taken from the map settings. + * \see mapUnitsPerPixel() + * \since QGIS 3.6 + */ + void setMapUnitsPerPixel( double mapUnitsPerPixel ); + int dpi() const { return mDpi; } void setDpi( int dpi ) { mDpi = dpi; } diff --git a/src/server/services/wms/qgswmsrenderer.cpp b/src/server/services/wms/qgswmsrenderer.cpp index 62042efb95bf..9b0f0006674a 100644 --- a/src/server/services/wms/qgswmsrenderer.cpp +++ b/src/server/services/wms/qgswmsrenderer.cpp @@ -183,6 +183,16 @@ namespace QgsWms std::unique_ptr image; std::unique_ptr painter; + // getting scale from bbox + if ( !mWmsParameters.bbox().isEmpty() ) + { + QgsMapSettings mapSettings; + image.reset( createImage( mWmsParameters.widthAsInt(), mWmsParameters.heightAsInt(), false ) ); + configureMapSettings( image.get(), mapSettings ); + legendSettings.setMapScale( mapSettings.scale() ); + legendSettings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() ); + } + if ( !mWmsParameters.rule().isEmpty() ) { QString rule = mWmsParameters.rule();