Skip to content
Permalink
Browse files

Move some methods from renderer to context

  • Loading branch information
pblottiere committed Mar 27, 2019
1 parent ca602ec commit 59eadbb5c6b0703f602e27c44cf8b07eb6a271d6
@@ -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();
@@ -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




@@ -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;
@@ -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

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

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

0 comments on commit 59eadbb

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