Skip to content

Commit 7de50a0

Browse files
committed
calculate mMmPerMapUnit with mapUnitsPerPixel to avoid to have redundant info
1 parent a04f91b commit 7de50a0

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

src/core/layertree/qgslayertreemodellegendnode.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ QSizeF QgsSymbolLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemC
395395
QgsRenderContext context;
396396
context.setScaleFactor( settings.dpi() / 25.4 );
397397
context.setRendererScale( settings.mapScale() );
398-
context.setMapToPixel( QgsMapToPixel( settings.mapUnitsPerPixel() == 1 ? 1 / ( settings.mmPerMapUnit() * context.scaleFactor() ) : settings.mapUnitsPerPixel() ) );
398+
context.setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * context.scaleFactor() ) ) );
399399
context.setForceVectorOutput( true );
400400
context.setPainter( ctx ? ctx->painter : nullptr );
401401

src/core/qgslegendsettings.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ QgsLegendSettings::QgsLegendSettings()
3737
rstyle( QgsLegendStyle::SymbolLabel ).rfont().setPointSizeF( 12.0 );
3838
}
3939

40+
double QgsLegendSettings::mapUnitsPerPixel() const
41+
{
42+
return 1 / ( mMmPerMapUnit * ( mDpi / 25.4 ) );
43+
}
44+
45+
void QgsLegendSettings::setMapUnitsPerPixel( double mapUnitsPerPixel )
46+
{
47+
mMmPerMapUnit = 1 / mapUnitsPerPixel / ( mDpi / 25.4 );
48+
}
49+
4050
QStringList QgsLegendSettings::evaluateItemText( const QString &text, const QgsExpressionContext &context ) const
4151
{
4252
const QString textToRender = QgsExpression::replaceExpressionText( text, &context );

src/core/qgslegendsettings.h

+5-8
Original file line numberDiff line numberDiff line change
@@ -179,16 +179,16 @@ class CORE_EXPORT QgsLegendSettings
179179
void setMapScale( double scale ) { mMapScale = scale; }
180180

181181
/**
182-
* Returns the factor of map units per pixel used for symbol sized by map units.
183-
* \see setMapScale()
182+
* Returns the factor of map units per pixel for symbols with size given in map units calculated by mDpi and mMmPerMapUnit
183+
* \see setMapUnitsPerPixel()
184184
*/
185-
double mapUnitsPerPixel() const { return mMapUnitsPerPixel; }
185+
double mapUnitsPerPixel() const;
186186

187187
/**
188-
* Sets the map units per pixel \a mapUnitsPerPixel mostly taken from the map settings.
188+
* Sets the the mMmPerMapUnit calculated by \a mapUnitsPerPixel mostly taken from the map settings.
189189
* \see mapUnitsPerPixel()
190190
*/
191-
void setMapUnitsPerPixel( double mapUnitsPerPixel ) { mMapUnitsPerPixel = mapUnitsPerPixel; }
191+
void setMapUnitsPerPixel( double mapUnitsPerPixel );
192192

193193
int dpi() const { return mDpi; }
194194
void setDpi( int dpi ) { mDpi = dpi; }
@@ -302,9 +302,6 @@ class CORE_EXPORT QgsLegendSettings
302302
//! Denominator of map's scale
303303
double mMapScale = 1;
304304

305-
//! the map units per pixel given by the map parameters - for symbols with size given in map units
306-
double mMapUnitsPerPixel = 1;
307-
308305
//! DPI to be used when rendering legend
309306
int mDpi = 96;
310307
};

src/server/services/wms/qgswmsrenderer.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,13 @@ namespace QgsWms
184184
std::unique_ptr<QPainter> painter;
185185

186186
// getting scale from bbox
187-
if( !mWmsParameters.bbox().isEmpty() )
187+
if ( !mWmsParameters.bbox().isEmpty() )
188188
{
189-
QgsMapSettings mapSettings;
190-
image.reset( createImage( mWmsParameters.widthAsInt(), mWmsParameters.heightAsInt(), false ) );
191-
configureMapSettings( image.get(), mapSettings );
192-
legendSettings.setMapScale( mapSettings.scale() );
193-
legendSettings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
189+
QgsMapSettings mapSettings;
190+
image.reset( createImage( mWmsParameters.widthAsInt(), mWmsParameters.heightAsInt(), false ) );
191+
configureMapSettings( image.get(), mapSettings );
192+
legendSettings.setMapScale( mapSettings.scale() );
193+
legendSettings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
194194
}
195195

196196
if ( !mWmsParameters.rule().isEmpty() )

0 commit comments

Comments
 (0)