Skip to content
Permalink
Browse files

calculate mMmPerMapUnit with mapUnitsPerPixel to avoid to have redund…

…ant info
  • Loading branch information
signedav committed Feb 21, 2019
1 parent a04f91b commit 7de50a016d896281be2192cf20986f052c411722
@@ -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 );

@@ -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 );
@@ -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; }
@@ -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;
};
@@ -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() )

0 comments on commit 7de50a0

Please sign in to comment.
You can’t perform that action at this time.