Skip to content

Commit

Permalink
Move another method to context
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Mar 27, 2019
1 parent 5c874ca commit dedf0ab
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
14 changes: 14 additions & 0 deletions src/server/services/wms/qgswmsrendercontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/server/services/wms/qgswmsrendercontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
17 changes: 3 additions & 14 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

Expand Down Expand Up @@ -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 )
Expand Down
3 changes: 0 additions & 3 deletions src/server/services/wms/qgswmsrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dedf0ab

Please sign in to comment.