Skip to content
Permalink
Browse files

Move another method to context

  • Loading branch information
pblottiere committed Mar 27, 2019
1 parent 5c874ca commit dedf0abaebc2a7dc623218edcc6c8369fedc1fa4
@@ -141,6 +141,20 @@ int QgsWmsRenderContext::precision() const
return precision;
}

qreal QgsWmsRenderContext::dotsPerMm() const
{
// Apply DPI parameter if present. This is an extension of QGIS Server
// compared to WMS 1.3.
// Because of backwards compatibility, this parameter is optional
double OGC_PX_M = 0.00028; // OGC reference pixel size in meter
int dpm = 1 / OGC_PX_M;

if ( !mParameters.dpi().isEmpty() )
dpm = mParameters.dpiAsDouble() / 0.0254;

return dpm / 1000.0;
}

QList<QgsMapLayer *> QgsWmsRenderContext::layersToRender() const
{
return mLayersToRender;
@@ -158,6 +158,11 @@ namespace QgsWms
*/
QString layerNickname( const QgsMapLayer &layer ) const;

/**
* Returns default dots per mm according to the current configuration.
*/
qreal dotsPerMm() const;

#ifdef HAVE_SERVER_PYTHON_PLUGINS

/**
@@ -161,7 +161,7 @@ namespace QgsWms
legendModel.reset( buildLegendTreeModel( layers, mContext.scaleDenominator(), rootGroup ) );

// rendering step
qreal dpmm = dotsPerMm();
const qreal dpmm = mContext.dotsPerMm();
std::unique_ptr<QImage> image;
std::unique_ptr<QPainter> painter;

@@ -1014,15 +1014,10 @@ namespace QgsWms
throw QgsException( QStringLiteral( "createImage: image could not be created, check for out of memory conditions" ) );
}

//apply DPI parameter if present. This is an extension of Qgis Mapserver compared to WMS 1.3.
//Because of backwards compatibility, this parameter is optional
double OGC_PX_M = 0.00028; // OGC reference pixel size in meter, also used by qgis
int dpm = 1 / OGC_PX_M;
if ( !mWmsParameters.dpi().isEmpty() )
dpm = mWmsParameters.dpiAsDouble() / 0.0254;

const qreal dpm = mContext.dotsPerMm() * 1000.0;
image->setDotsPerMeterX( dpm );
image->setDotsPerMeterY( dpm );

return image.release();
}

@@ -3020,12 +3015,6 @@ namespace QgsWms
return legendModel;
}

qreal QgsRenderer::dotsPerMm() const
{
std::unique_ptr<QImage> tmpImage( createImage( 1, 1, false ) );
return tmpImage->dotsPerMeterX() / 1000.0;
}

void QgsRenderer::handlePrintErrors( const QgsLayout *layout ) const
{
if ( !layout )
@@ -155,9 +155,6 @@ namespace QgsWms
// Build a layer tree model for legend
QgsLayerTreeModel *buildLegendTreeModel( const QList<QgsMapLayer *> &layers, double scaleDenominator, QgsLayerTree &rootGroup );

// Returns default dots per mm
qreal dotsPerMm() const;

/**
* Creates a QImage from the HEIGHT and WIDTH parameters
* \param width image width (or -1 if width should be taken from WIDTH wms parameter)

0 comments on commit dedf0ab

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