Skip to content

Commit

Permalink
decide in qgswmsrenderer if SRCWIDTH (for GetLegendGraphic) or WIDTH …
Browse files Browse the repository at this point in the history
…(for GetMap) is used
  • Loading branch information
signedav committed Mar 27, 2019
1 parent 6722ad5 commit 61a89af
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 40 deletions.
15 changes: 0 additions & 15 deletions src/server/services/wms/qgswmsparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,21 +716,6 @@ namespace QgsWms
return mWmsParameters[ QgsWmsParameter::SRCWIDTH ].toInt();
}

int QgsWmsParameters::getHeightAsInt() const
{
if ( QStringList( { QStringLiteral( "GetLegendGraphic" ), QStringLiteral( "GetLegendGraphics" ) } ).contains( request() ) && srcHeightAsInt() > 0 )
return srcHeightAsInt();
return heightAsInt();
}

int QgsWmsParameters::getWidthAsInt() const
{

if ( QStringList( { QStringLiteral( "GetLegendGraphic" ), QStringLiteral( "GetLegendGraphics" ) } ).contains( request() ) && srcWidthAsInt() > 0 )
return srcWidthAsInt();
return widthAsInt();
}

QString QgsWmsParameters::dpi() const
{
return mWmsParameters[ QgsWmsParameter::DPI ].toString();
Expand Down
14 changes: 0 additions & 14 deletions src/server/services/wms/qgswmsparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,20 +422,6 @@ namespace QgsWms
*/
int srcHeightAsInt() const;

/**
* Returns SRCHEIGHT parameter if it's a GetLegendGraphics request and otherwise HEIGHT parameter
*
* \returns getHeightAsInt parameter
*/
int getHeightAsInt() const;

/**
* Returns SRCWIDTH parameter if it's a GetLegendGraphics request and otherwise WIDTH parameter
*
* \returns getWidthAsInt parameter
*/
int getWidthAsInt() const;

/**
* Returns VERSION parameter if defined or its default value.
* \returns version
Expand Down
38 changes: 27 additions & 11 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ namespace QgsWms
if ( !mWmsParameters.bbox().isEmpty() )
{
QgsMapSettings mapSettings;
image.reset( createImage( mWmsParameters.getWidthAsInt(), mWmsParameters.getHeightAsInt(), false ) );
image.reset( createImage( getWidthAsInt(), getHeightAsInt(), false ) );
configureMapSettings( image.get(), mapSettings );
legendSettings.setMapScale( mapSettings.scale() );
legendSettings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
Expand Down Expand Up @@ -1045,8 +1045,8 @@ namespace QgsWms
}

// create the mapSettings and the output image
int imageWidth = mWmsParameters.getWidthAsInt();
int imageHeight = mWmsParameters.getHeightAsInt();
int imageWidth = getWidthAsInt();
int imageHeight = getHeightAsInt();

// Provide default image width/height values if format is not image
if ( !( imageWidth && imageHeight ) && ! mWmsParameters.infoFormatIsImage() )
Expand Down Expand Up @@ -1123,10 +1123,10 @@ namespace QgsWms
QImage *QgsRenderer::createImage( int width, int height, bool useBbox ) const
{
if ( width < 0 )
width = mWmsParameters.getWidthAsInt();
width = getWidthAsInt();

if ( height < 0 )
height = mWmsParameters.getHeightAsInt();
height = getHeightAsInt();

//Adapt width / height if the aspect ratio does not correspond with the BBOX.
//Required by WMS spec. 1.3.
Expand Down Expand Up @@ -1315,8 +1315,8 @@ namespace QgsWms
i = mWmsParameters.xAsInt();
j = mWmsParameters.yAsInt();
}
int width = mWmsParameters.getWidthAsInt();
int height = mWmsParameters.getHeightAsInt();
int width = getWidthAsInt();
int height = getHeightAsInt();
if ( ( i != -1 && j != -1 && width != 0 && height != 0 ) && ( width != outputImage->width() || height != outputImage->height() ) )
{
i *= ( outputImage->width() / static_cast<double>( width ) );
Expand Down Expand Up @@ -1994,14 +1994,14 @@ namespace QgsWms
{
//test if maxWidth / maxHeight set and WIDTH / HEIGHT parameter is in the range
int wmsMaxWidth = QgsServerProjectUtils::wmsMaxWidth( *mProject );
int width = mWmsParameters.getWidthAsInt();
int width = getWidthAsInt();
if ( wmsMaxWidth != -1 && width > wmsMaxWidth )
{
return false;
}

int wmsMaxHeight = QgsServerProjectUtils::wmsMaxHeight( *mProject );
int height = mWmsParameters.getHeightAsInt();
int height = getHeightAsInt();
if ( wmsMaxHeight != -1 && height > wmsMaxHeight )
{
return false;
Expand Down Expand Up @@ -3206,8 +3206,8 @@ namespace QgsWms
// WIDTH / HEIGHT parameters. If not, the image has to be scaled (required
// by WMS spec)
QImage *scaledImage = nullptr;
int width = mWmsParameters.getWidthAsInt();
int height = mWmsParameters.getHeightAsInt();
int width = getWidthAsInt();
int height = getHeightAsInt();
if ( width != image->width() || height != image->height() )
{
scaledImage = new QImage( image->scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
Expand Down Expand Up @@ -3418,4 +3418,20 @@ namespace QgsWms
}
}

int QgsRenderer::getHeightAsInt() const
{
if ( mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphic" ), Qt::CaseInsensitive ) == 0 ||
mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphics" ), Qt::CaseInsensitive ) )
return mWmsParameters.srcHeightAsInt();
return mWmsParameters.heightAsInt();
}

int QgsRenderer::getWidthAsInt() const
{
if ( mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphic" ), Qt::CaseInsensitive ) == 0 ||
mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphics" ), Qt::CaseInsensitive ) )
return mWmsParameters.srcWidthAsInt();
return mWmsParameters.heightAsInt();
}

} // namespace QgsWms
12 changes: 12 additions & 0 deletions src/server/services/wms/qgswmsrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,18 @@ namespace QgsWms

void handlePrintErrors( const QgsLayout *layout ) const;

/**
* Returns QgsWmsParameter SRCWIDTH if it's a GetLegendGraphics request and otherwise HEIGHT parameter
* \returns getHeightAsInt parameter
*/
int getHeightAsInt() const;

/**
* Returns QgsWmsParameter SRCWIDTH parameter if it's a GetLegendGraphics request and otherwise WIDTH parameter
* \returns getWidthAsInt parameter
*/
int getWidthAsInt() const;

const QgsWmsParameters &mWmsParameters;

#ifdef HAVE_SERVER_PYTHON_PLUGINS
Expand Down

0 comments on commit 61a89af

Please sign in to comment.