Skip to content

Commit

Permalink
calculate mMmPerMapUnit with mapUnitsPerPixel to avoid to have redund…
Browse files Browse the repository at this point in the history
…ant info
  • Loading branch information
signedav committed Feb 22, 2019
1 parent a04f91b commit 7de50a0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -395,7 +395,7 @@ QSizeF QgsSymbolLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemC
QgsRenderContext context;
context.setScaleFactor( settings.dpi() / 25.4 );
context.setRendererScale( settings.mapScale() );
context.setMapToPixel( QgsMapToPixel( settings.mapUnitsPerPixel() == 1 ? 1 / ( settings.mmPerMapUnit() * context.scaleFactor() ) : settings.mapUnitsPerPixel() ) );
context.setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * context.scaleFactor() ) ) );
context.setForceVectorOutput( true );
context.setPainter( ctx ? ctx->painter : nullptr );

Expand Down
10 changes: 10 additions & 0 deletions src/core/qgslegendsettings.cpp
Expand Up @@ -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 );
Expand Down
13 changes: 5 additions & 8 deletions src/core/qgslegendsettings.h
Expand Up @@ -179,16 +179,16 @@ class CORE_EXPORT QgsLegendSettings
void setMapScale( double scale ) { mMapScale = scale; }

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

/**
* Sets the map units per pixel \a mapUnitsPerPixel mostly taken from the map settings.
* Sets the the mMmPerMapUnit calculated by \a mapUnitsPerPixel mostly taken from the map settings.
* \see mapUnitsPerPixel()
*/
void setMapUnitsPerPixel( double mapUnitsPerPixel ) { mMapUnitsPerPixel = mapUnitsPerPixel; }
void setMapUnitsPerPixel( double mapUnitsPerPixel );

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

//! the map units per pixel given by the map parameters - for symbols with size given in map units
double mMapUnitsPerPixel = 1;

//! DPI to be used when rendering legend
int mDpi = 96;
};
Expand Down
12 changes: 6 additions & 6 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -184,13 +184,13 @@ namespace QgsWms
std::unique_ptr<QPainter> painter;

// getting scale from bbox
if( !mWmsParameters.bbox().isEmpty() )
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() );
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() )
Expand Down

0 comments on commit 7de50a0

Please sign in to comment.