Skip to content

Commit 4c667ad

Browse files
committed
SRCHEIGHT SRCWIDTH and the logical part for selection
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
1 parent f878ecc commit 4c667ad

File tree

3 files changed

+104
-12
lines changed

3 files changed

+104
-12
lines changed

src/server/services/wms/qgswmsparameters.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,16 @@ namespace QgsWms
363363
QVariant( 0 ) );
364364
save( pWidth );
365365

366+
const QgsWmsParameter pSrcHeight( QgsWmsParameter::SRCHEIGHT,
367+
QVariant::Int,
368+
QVariant( 0 ) );
369+
save( pSrcHeight );
370+
371+
const QgsWmsParameter pSrcWidth( QgsWmsParameter::SRCWIDTH,
372+
QVariant::Int,
373+
QVariant( 0 ) );
374+
save( pSrcWidth );
375+
366376
const QgsWmsParameter pBbox( QgsWmsParameter::BBOX );
367377
save( pBbox );
368378

@@ -686,6 +696,42 @@ namespace QgsWms
686696
return mWmsParameters[ QgsWmsParameter::WIDTH ].toInt();
687697
}
688698

699+
QString QgsWmsParameters::srcHeight() const
700+
{
701+
return mWmsParameters[ QgsWmsParameter::SRCHEIGHT ].toString();
702+
}
703+
704+
QString QgsWmsParameters::srcWidth() const
705+
{
706+
return mWmsParameters[ QgsWmsParameter::SRCWIDTH ].toString();
707+
}
708+
709+
int QgsWmsParameters::srcHeightAsInt() const
710+
{
711+
return mWmsParameters[ QgsWmsParameter::SRCHEIGHT ].toInt();
712+
}
713+
714+
int QgsWmsParameters::srcWidthAsInt() const
715+
{
716+
return mWmsParameters[ QgsWmsParameter::SRCWIDTH ].toInt();
717+
}
718+
719+
int QgsWmsParameters::getHeightAsInt() const
720+
{
721+
if ( request().compare( QStringLiteral( "GetLegendGraphic" ), Qt::CaseInsensitive ) != 0 &&
722+
request().compare( QStringLiteral( "GetLegendGraphics" ), Qt::CaseInsensitive ) != 0 )
723+
return heightAsInt();
724+
return srcHeightAsInt();
725+
}
726+
727+
int QgsWmsParameters::getWidthAsInt() const
728+
{
729+
if ( request().compare( QStringLiteral( "GetLegendGraphic" ), Qt::CaseInsensitive ) != 0 &&
730+
request().compare( QStringLiteral( "GetLegendGraphics" ), Qt::CaseInsensitive ) != 0 )
731+
return widthAsInt();
732+
return srcWidthAsInt();
733+
}
734+
689735
QString QgsWmsParameters::dpi() const
690736
{
691737
return mWmsParameters[ QgsWmsParameter::DPI ].toString();

src/server/services/wms/qgswmsparameters.h

+47-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ namespace QgsWms
176176
WITH_MAPTIP,
177177
WMTVER,
178178
ATLAS_PK,
179-
FORMAT_OPTIONS
179+
FORMAT_OPTIONS,
180+
SRCWIDTH,
181+
SRCHEIGHT
180182
};
181183
Q_ENUM( Name )
182184

@@ -390,6 +392,50 @@ namespace QgsWms
390392
*/
391393
int heightAsInt() const;
392394

395+
/**
396+
* Returns SRCWIDTH parameter or an empty string if not defined.
397+
* \returns srcWidth parameter
398+
*/
399+
QString srcWidth() const;
400+
401+
/**
402+
* Returns SRCWIDTH parameter as an int or its default value if not
403+
* defined. An exception is raised if SRCWIDTH is defined and cannot be
404+
* converted.
405+
* \returns srcWidth parameter
406+
* \throws QgsBadRequestException
407+
*/
408+
int srcWidthAsInt() const;
409+
410+
/**
411+
* Returns SRCHEIGHT parameter or an empty string if not defined.
412+
* \returns srcHeight parameter
413+
*/
414+
QString srcHeight() const;
415+
416+
/**
417+
* Returns SRCHEIGHT parameter as an int or its default value if not
418+
* defined. An exception is raised if SRCHEIGHT is defined and cannot be
419+
* converted.
420+
* \returns srcHeight parameter
421+
* \throws QgsBadRequestException
422+
*/
423+
int srcHeightAsInt() const;
424+
425+
/**
426+
* Returns SRCHEIGHT parameter if it's a GetLegendGraphics request and otherwise HEIGHT parameter
427+
*
428+
* \returns getHeightAsInt parameter
429+
*/
430+
int getHeightAsInt() const;
431+
432+
/**
433+
* Returns SRCWIDTH parameter if it's a GetLegendGraphics request and otherwise WIDTH parameter
434+
*
435+
* \returns getWidthAsInt parameter
436+
*/
437+
int getWidthAsInt() const;
438+
393439
/**
394440
* Returns VERSION parameter if defined or its default value.
395441
* \returns version

src/server/services/wms/qgswmsrenderer.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ namespace QgsWms
187187
if ( !mWmsParameters.bbox().isEmpty() )
188188
{
189189
QgsMapSettings mapSettings;
190-
image.reset( createImage( mWmsParameters.widthAsInt(), mWmsParameters.heightAsInt(), false ) );
190+
image.reset( createImage( mWmsParameters.getWidthAsInt(), mWmsParameters.getHeightAsInt(), false ) );
191191
configureMapSettings( image.get(), mapSettings );
192192
legendSettings.setMapScale( mapSettings.scale() );
193193
legendSettings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
@@ -1045,8 +1045,8 @@ namespace QgsWms
10451045
}
10461046

10471047
// create the mapSettings and the output image
1048-
int imageWidth = mWmsParameters.widthAsInt();
1049-
int imageHeight = mWmsParameters.heightAsInt();
1048+
int imageWidth = mWmsParameters.getWidthAsInt();
1049+
int imageHeight = mWmsParameters.getHeightAsInt();
10501050

10511051
// Provide default image width/height values if format is not image
10521052
if ( !( imageWidth && imageHeight ) && ! mWmsParameters.infoFormatIsImage() )
@@ -1123,10 +1123,10 @@ namespace QgsWms
11231123
QImage *QgsRenderer::createImage( int width, int height, bool useBbox ) const
11241124
{
11251125
if ( width < 0 )
1126-
width = mWmsParameters.widthAsInt();
1126+
width = mWmsParameters.getWidthAsInt();
11271127

11281128
if ( height < 0 )
1129-
height = mWmsParameters.heightAsInt();
1129+
height = mWmsParameters.getHeightAsInt();
11301130

11311131
//Adapt width / height if the aspect ratio does not correspond with the BBOX.
11321132
//Required by WMS spec. 1.3.
@@ -1315,8 +1315,8 @@ namespace QgsWms
13151315
i = mWmsParameters.xAsInt();
13161316
j = mWmsParameters.yAsInt();
13171317
}
1318-
int width = mWmsParameters.widthAsInt();
1319-
int height = mWmsParameters.heightAsInt();
1318+
int width = mWmsParameters.getWidthAsInt();
1319+
int height = mWmsParameters.getHeightAsInt();
13201320
if ( ( i != -1 && j != -1 && width != 0 && height != 0 ) && ( width != outputImage->width() || height != outputImage->height() ) )
13211321
{
13221322
i *= ( outputImage->width() / static_cast<double>( width ) );
@@ -1994,14 +1994,14 @@ namespace QgsWms
19941994
{
19951995
//test if maxWidth / maxHeight set and WIDTH / HEIGHT parameter is in the range
19961996
int wmsMaxWidth = QgsServerProjectUtils::wmsMaxWidth( *mProject );
1997-
int width = mWmsParameters.widthAsInt();
1997+
int width = mWmsParameters.getWidthAsInt();
19981998
if ( wmsMaxWidth != -1 && width > wmsMaxWidth )
19991999
{
20002000
return false;
20012001
}
20022002

20032003
int wmsMaxHeight = QgsServerProjectUtils::wmsMaxHeight( *mProject );
2004-
int height = mWmsParameters.heightAsInt();
2004+
int height = mWmsParameters.getHeightAsInt();
20052005
if ( wmsMaxHeight != -1 && height > wmsMaxHeight )
20062006
{
20072007
return false;
@@ -3206,8 +3206,8 @@ namespace QgsWms
32063206
// WIDTH / HEIGHT parameters. If not, the image has to be scaled (required
32073207
// by WMS spec)
32083208
QImage *scaledImage = nullptr;
3209-
int width = mWmsParameters.widthAsInt();
3210-
int height = mWmsParameters.heightAsInt();
3209+
int width = mWmsParameters.getWidthAsInt();
3210+
int height = mWmsParameters.getHeightAsInt();
32113211
if ( width != image->width() || height != image->height() )
32123212
{
32133213
scaledImage = new QImage( image->scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );

0 commit comments

Comments
 (0)