Skip to content

Commit

Permalink
Move some methods from renderer to context
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed Mar 27, 2019
1 parent ca602ec commit 59eadbb
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/server/services/wms/qgswmsgetlegendgraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace QgsWms

if ( result )
{
writeImage( response, *result, format, renderer.imageQuality() );
writeImage( response, *result, format, context.imageQuality() );
if ( cacheManager )
{
QByteArray content = response.data();
Expand Down
7 changes: 1 addition & 6 deletions src/server/services/wms/qgswmsgetmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,12 @@ namespace QgsWms
if ( result )
{
const QString format = request.parameters().value( QStringLiteral( "FORMAT" ), QStringLiteral( "PNG" ) );
writeImage( response, *result, format, renderer.imageQuality() );
writeImage( response, *result, format, context.imageQuality() );
}
else
{
throw QgsServiceException( QStringLiteral( "UnknownError" ),
QStringLiteral( "Failed to compute GetMap image" ) );
}
}

} // namespace QgsWms




24 changes: 24 additions & 0 deletions src/server/services/wms/qgswmsrendercontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,30 @@ QgsWmsParametersLayer QgsWmsRenderContext::parameters( const QgsMapLayer &layer
return parameters;
}

int QgsWmsRenderContext::imageQuality() const
{
int imageQuality = QgsServerProjectUtils::wmsImageQuality( *mProject );

if ( !mParameters.imageQuality().isEmpty() )
{
imageQuality = mParameters.imageQualityAsInt();
}

return imageQuality;
}

int QgsWmsRenderContext::precision() const
{
int precision = QgsServerProjectUtils::wmsFeatureInfoPrecision( *mProject );

if ( mParameters.wmsPrecisionAsInt() > -1 )
{
precision = mParameters.wmsPrecisionAsInt();
}

return precision;
}

QList<QgsMapLayer *> QgsWmsRenderContext::layersToRender() const
{
return mLayersToRender;
Expand Down
11 changes: 11 additions & 0 deletions src/server/services/wms/qgswmsrendercontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ namespace QgsWms
*/
QgsWmsParametersLayer parameters( const QgsMapLayer &layer ) const;

/**
* Returns the image quality to use for rendering according to the
* current configuration.
*/
int imageQuality() const;

/**
* Returns the precision to use according to the current configuration.
*/
int precision() const;

#ifdef HAVE_SERVER_PYTHON_PLUGINS

/**
Expand Down
46 changes: 9 additions & 37 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1554,10 +1554,10 @@ namespace QgsWms
{
QDomElement bBoxElem = infoDocument.createElement( QStringLiteral( "BoundingBox" ) );
bBoxElem.setAttribute( version == QLatin1String( "1.1.1" ) ? "SRS" : "CRS", outputCrs.authid() );
bBoxElem.setAttribute( QStringLiteral( "minx" ), qgsDoubleToString( box.xMinimum(), wmsPrecision() ) );
bBoxElem.setAttribute( QStringLiteral( "maxx" ), qgsDoubleToString( box.xMaximum(), wmsPrecision() ) );
bBoxElem.setAttribute( QStringLiteral( "miny" ), qgsDoubleToString( box.yMinimum(), wmsPrecision() ) );
bBoxElem.setAttribute( QStringLiteral( "maxy" ), qgsDoubleToString( box.yMaximum(), wmsPrecision() ) );
bBoxElem.setAttribute( QStringLiteral( "minx" ), qgsDoubleToString( box.xMinimum(), mContext.precision() ) );
bBoxElem.setAttribute( QStringLiteral( "maxx" ), qgsDoubleToString( box.xMaximum(), mContext.precision() ) );
bBoxElem.setAttribute( QStringLiteral( "miny" ), qgsDoubleToString( box.yMinimum(), mContext.precision() ) );
bBoxElem.setAttribute( QStringLiteral( "maxy" ), qgsDoubleToString( box.yMaximum(), mContext.precision() ) );
featureElement.appendChild( bBoxElem );
}

Expand Down Expand Up @@ -1588,7 +1588,7 @@ namespace QgsWms
}
QDomElement geometryElement = infoDocument.createElement( QStringLiteral( "Attribute" ) );
geometryElement.setAttribute( QStringLiteral( "name" ), QStringLiteral( "geometry" ) );
geometryElement.setAttribute( QStringLiteral( "value" ), geom.asWkt( wmsPrecision() ) );
geometryElement.setAttribute( QStringLiteral( "value" ), geom.asWkt( mContext.precision() ) );
geometryElement.setAttribute( QStringLiteral( "type" ), QStringLiteral( "derived" ) );
featureElement.appendChild( geometryElement );
}
Expand Down Expand Up @@ -2260,11 +2260,11 @@ namespace QgsWms
QDomElement boxElem;
if ( version < 3 )
{
boxElem = QgsOgcUtils::rectangleToGMLBox( &box, doc, wmsPrecision() );
boxElem = QgsOgcUtils::rectangleToGMLBox( &box, doc, mContext.precision() );
}
else
{
boxElem = QgsOgcUtils::rectangleToGMLEnvelope( &box, doc, wmsPrecision() );
boxElem = QgsOgcUtils::rectangleToGMLEnvelope( &box, doc, mContext.precision() );
}

if ( crs.isValid() )
Expand All @@ -2288,11 +2288,11 @@ namespace QgsWms
QDomElement gmlElem;
if ( version < 3 )
{
gmlElem = QgsOgcUtils::geometryToGML( geom, doc, wmsPrecision() );
gmlElem = QgsOgcUtils::geometryToGML( geom, doc, mContext.precision() );
}
else
{
gmlElem = QgsOgcUtils::geometryToGML( geom, doc, QStringLiteral( "GML3" ), wmsPrecision() );
gmlElem = QgsOgcUtils::geometryToGML( geom, doc, QStringLiteral( "GML3" ), mContext.precision() );
}

if ( !gmlElem.isNull() )
Expand Down Expand Up @@ -2365,34 +2365,6 @@ namespace QgsWms
return value;
}

int QgsRenderer::imageQuality() const
{
// First taken from QGIS project
int imageQuality = QgsServerProjectUtils::wmsImageQuality( *mProject );

// Then checks if a parameter is given, if so use it instead
if ( !mWmsParameters.imageQuality().isEmpty() )
{
imageQuality = mWmsParameters.imageQualityAsInt();
}

return imageQuality;
}

int QgsRenderer::wmsPrecision() const
{
// First taken from QGIS project and the default value is 6
int WMSPrecision = QgsServerProjectUtils::wmsFeatureInfoPrecision( *mProject );

// Then checks if a parameter is given, if so use it instead
int WMSPrecisionParameter = mWmsParameters.wmsPrecisionAsInt();

if ( WMSPrecisionParameter > -1 )
return WMSPrecisionParameter;
else
return WMSPrecision;
}

QgsRectangle QgsRenderer::featureInfoSearchRect( QgsVectorLayer *ml, const QgsMapSettings &mapSettings, const QgsRenderContext &rct, const QgsPointXY &infoPoint ) const
{
if ( !ml )
Expand Down
6 changes: 0 additions & 6 deletions src/server/services/wms/qgswmsrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ namespace QgsWms
*/
QByteArray getFeatureInfo( const QString &version = "1.3.0" );

//! Returns the image quality to use for getMap request
int imageQuality() const;

//! Returns the precision to use for GetFeatureInfo request
int wmsPrecision() const;

private:

// Init the restricted layers with nicknames
Expand Down

0 comments on commit 59eadbb

Please sign in to comment.