Skip to content

Commit

Permalink
SRCHEIGHT SRCWIDTH and the logical part for selection
Browse files Browse the repository at this point in the history
it takes these values as map size in case of GetLegendGraphics Request and still HEIGHT and WIDTH if not a GetLegendGraphics Request
because this parameter is called from multiple used functions, this logical part is in the getWidthAsInt and getHeightAsInt functions
getHeight and getWidth can be used still like before
  • Loading branch information
signedav committed Mar 27, 2019
1 parent f878ecc commit 4c667ad
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 12 deletions.
46 changes: 46 additions & 0 deletions src/server/services/wms/qgswmsparameters.cpp
Expand Up @@ -363,6 +363,16 @@ namespace QgsWms
QVariant( 0 ) );
save( pWidth );

const QgsWmsParameter pSrcHeight( QgsWmsParameter::SRCHEIGHT,
QVariant::Int,
QVariant( 0 ) );
save( pSrcHeight );

const QgsWmsParameter pSrcWidth( QgsWmsParameter::SRCWIDTH,
QVariant::Int,
QVariant( 0 ) );
save( pSrcWidth );

const QgsWmsParameter pBbox( QgsWmsParameter::BBOX );
save( pBbox );

Expand Down Expand Up @@ -686,6 +696,42 @@ namespace QgsWms
return mWmsParameters[ QgsWmsParameter::WIDTH ].toInt();
}

QString QgsWmsParameters::srcHeight() const
{
return mWmsParameters[ QgsWmsParameter::SRCHEIGHT ].toString();
}

QString QgsWmsParameters::srcWidth() const
{
return mWmsParameters[ QgsWmsParameter::SRCWIDTH ].toString();
}

int QgsWmsParameters::srcHeightAsInt() const
{
return mWmsParameters[ QgsWmsParameter::SRCHEIGHT ].toInt();
}

int QgsWmsParameters::srcWidthAsInt() const
{
return mWmsParameters[ QgsWmsParameter::SRCWIDTH ].toInt();
}

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

int QgsWmsParameters::getWidthAsInt() const
{
if ( request().compare( QStringLiteral( "GetLegendGraphic" ), Qt::CaseInsensitive ) != 0 &&
request().compare( QStringLiteral( "GetLegendGraphics" ), Qt::CaseInsensitive ) != 0 )
return widthAsInt();
return srcWidthAsInt();
}

QString QgsWmsParameters::dpi() const
{
return mWmsParameters[ QgsWmsParameter::DPI ].toString();
Expand Down
48 changes: 47 additions & 1 deletion src/server/services/wms/qgswmsparameters.h
Expand Up @@ -176,7 +176,9 @@ namespace QgsWms
WITH_MAPTIP,
WMTVER,
ATLAS_PK,
FORMAT_OPTIONS
FORMAT_OPTIONS,
SRCWIDTH,
SRCHEIGHT
};
Q_ENUM( Name )

Expand Down Expand Up @@ -390,6 +392,50 @@ namespace QgsWms
*/
int heightAsInt() const;

/**
* Returns SRCWIDTH parameter or an empty string if not defined.
* \returns srcWidth parameter
*/
QString srcWidth() const;

/**
* Returns SRCWIDTH parameter as an int or its default value if not
* defined. An exception is raised if SRCWIDTH is defined and cannot be
* converted.
* \returns srcWidth parameter
* \throws QgsBadRequestException
*/
int srcWidthAsInt() const;

/**
* Returns SRCHEIGHT parameter or an empty string if not defined.
* \returns srcHeight parameter
*/
QString srcHeight() const;

/**
* Returns SRCHEIGHT parameter as an int or its default value if not
* defined. An exception is raised if SRCHEIGHT is defined and cannot be
* converted.
* \returns srcHeight parameter
* \throws QgsBadRequestException
*/
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
22 changes: 11 additions & 11 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -187,7 +187,7 @@ namespace QgsWms
if ( !mWmsParameters.bbox().isEmpty() )
{
QgsMapSettings mapSettings;
image.reset( createImage( mWmsParameters.widthAsInt(), mWmsParameters.heightAsInt(), false ) );
image.reset( createImage( mWmsParameters.getWidthAsInt(), mWmsParameters.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.widthAsInt();
int imageHeight = mWmsParameters.heightAsInt();
int imageWidth = mWmsParameters.getWidthAsInt();
int imageHeight = mWmsParameters.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.widthAsInt();
width = mWmsParameters.getWidthAsInt();

if ( height < 0 )
height = mWmsParameters.heightAsInt();
height = mWmsParameters.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.widthAsInt();
int height = mWmsParameters.heightAsInt();
int width = mWmsParameters.getWidthAsInt();
int height = mWmsParameters.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.widthAsInt();
int width = mWmsParameters.getWidthAsInt();
if ( wmsMaxWidth != -1 && width > wmsMaxWidth )
{
return false;
}

int wmsMaxHeight = QgsServerProjectUtils::wmsMaxHeight( *mProject );
int height = mWmsParameters.heightAsInt();
int height = mWmsParameters.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.widthAsInt();
int height = mWmsParameters.heightAsInt();
int width = mWmsParameters.getWidthAsInt();
int height = mWmsParameters.getHeightAsInt();
if ( width != image->width() || height != image->height() )
{
scaledImage = new QImage( image->scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
Expand Down

0 comments on commit 4c667ad

Please sign in to comment.