Skip to content
Permalink
Browse files

Check parameters before calling the renderer

  • Loading branch information
pblottiere committed Apr 9, 2019
1 parent b2aa978 commit bc72ff231572a7f44a384b6ba5913b817d20d036
@@ -34,6 +34,9 @@ namespace QgsWms
// get parameters from query
QgsWmsParameters parameters( QUrlQuery( request.url() ) );

// check parameters validity
checkParameters( parameters );

// init render context
QgsWmsRenderContext context( project, serverIface );
context.setFlag( QgsWmsRenderContext::UseScaleDenominator );
@@ -100,5 +103,26 @@ namespace QgsWms
throw QgsException( QStringLiteral( "Failed to compute GetLegendGraphics image" ) );
}
}

void checkParameters( const QgsWmsParameters &parameters )
{
if ( parameters.allLayersNickname().isEmpty() )
{
throw QgsBadRequestException( QgsServiceException::QGIS_MISSING_PARAMETER_VALUE,
parameters[QgsWmsParameter::LAYERS] );
}

if ( parameters.format() == QgsWmsParameters::Format::NONE )
{
throw QgsBadRequestException( QgsServiceException::QGIS_MISSING_PARAMETER_VALUE,
parameters[QgsWmsParameter::FORMAT] );
}

if ( ! parameters.bbox().isEmpty() && !parameters.rule().isEmpty() )
{
throw QgsBadRequestException( QgsServiceException::QGIS_INVALID_PARAMETER_VALUE,
QStringLiteral( "BBOX parameter cannot be combined with RULE." ) );
}
}
} // namespace QgsWms

@@ -29,6 +29,7 @@ namespace QgsWms
const QString &version, const QgsServerRequest &request,
QgsServerResponse &response );

void checkParameters( const QgsWmsParameters &parameters );
} // namespace QgsWms


@@ -129,15 +129,6 @@ namespace QgsWms

QImage *QgsRenderer::getLegendGraphics()
{
// check parameters
if ( mWmsParameters.allLayersNickname().isEmpty() )
throw QgsBadRequestException( QgsServiceException::QGIS_MISSING_PARAMETER_VALUE,
mWmsParameters[QgsWmsParameter::LAYERS] );

if ( mWmsParameters.format() == QgsWmsParameters::Format::NONE )
throw QgsBadRequestException( QgsServiceException::QGIS_MISSING_PARAMETER_VALUE,
mWmsParameters[QgsWmsParameter::FORMAT] );

// get layers
std::unique_ptr<QgsLayerRestorer> restorer;
restorer.reset( new QgsLayerRestorer( mContext.layers() ) );

0 comments on commit bc72ff2

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