Skip to content

Commit cf595f9

Browse files
committedMar 27, 2019
use direct widthAsInt/heigtAsInt in GetFeatureInfo
1 parent 61a89af commit cf595f9

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed
 

‎src/server/services/wms/qgswmsparameters.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ namespace QgsWms
395395
/**
396396
* Returns SRCWIDTH parameter or an empty string if not defined.
397397
* \returns srcWidth parameter
398+
* \since QGIS 3.8
398399
*/
399400
QString srcWidth() const;
400401

@@ -404,12 +405,14 @@ namespace QgsWms
404405
* converted.
405406
* \returns srcWidth parameter
406407
* \throws QgsBadRequestException
408+
* \since QGIS 3.8
407409
*/
408410
int srcWidthAsInt() const;
409411

410412
/**
411413
* Returns SRCHEIGHT parameter or an empty string if not defined.
412414
* \returns srcHeight parameter
415+
* \since QGIS 3.8
413416
*/
414417
QString srcHeight() const;
415418

@@ -419,6 +422,7 @@ namespace QgsWms
419422
* converted.
420423
* \returns srcHeight parameter
421424
* \throws QgsBadRequestException
425+
* \since QGIS 3.8
422426
*/
423427
int srcHeightAsInt() const;
424428

‎src/server/services/wms/qgswmsrenderer.cpp

Lines changed: 20 additions & 18 deletions
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( getWidthAsInt(), getHeightAsInt(), false ) );
190+
image.reset( createImage( width(), height(), 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 = getWidthAsInt();
1049-
int imageHeight = getHeightAsInt();
1048+
int imageWidth = mWmsParameters.widthAsInt();
1049+
int imageHeight = mWmsParameters.heightAsInt();
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 = getWidthAsInt();
1126+
width = this->width();
11271127

11281128
if ( height < 0 )
1129-
height = getHeightAsInt();
1129+
height = this->height();
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 = getWidthAsInt();
1319-
int height = getHeightAsInt();
1318+
int width = mWmsParameters.widthAsInt();
1319+
int height = mWmsParameters.heightAsInt();
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 = getWidthAsInt();
1997+
int width = this->width();
19981998
if ( wmsMaxWidth != -1 && width > wmsMaxWidth )
19991999
{
20002000
return false;
20012001
}
20022002

20032003
int wmsMaxHeight = QgsServerProjectUtils::wmsMaxHeight( *mProject );
2004-
int height = getHeightAsInt();
2004+
int height = this->height();
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 = getWidthAsInt();
3210-
int height = getHeightAsInt();
3209+
int width = this->width();
3210+
int height = this->height();
32113211
if ( width != image->width() || height != image->height() )
32123212
{
32133213
scaledImage = new QImage( image->scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
@@ -3418,20 +3418,22 @@ namespace QgsWms
34183418
}
34193419
}
34203420

3421-
int QgsRenderer::getHeightAsInt() const
3421+
int QgsRenderer::height() const
34223422
{
3423-
if ( mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphic" ), Qt::CaseInsensitive ) == 0 ||
3424-
mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphics" ), Qt::CaseInsensitive ) )
3423+
if ( ( mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphic" ), Qt::CaseInsensitive ) == 0 ||
3424+
mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphics" ), Qt::CaseInsensitive ) == 0 ) &&
3425+
mWmsParameters.srcHeightAsInt() > 0 )
34253426
return mWmsParameters.srcHeightAsInt();
34263427
return mWmsParameters.heightAsInt();
34273428
}
34283429

3429-
int QgsRenderer::getWidthAsInt() const
3430+
int QgsRenderer::width() const
34303431
{
3431-
if ( mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphic" ), Qt::CaseInsensitive ) == 0 ||
3432-
mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphics" ), Qt::CaseInsensitive ) )
3432+
if ( ( mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphic" ), Qt::CaseInsensitive ) == 0 ||
3433+
mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphics" ), Qt::CaseInsensitive ) == 0 ) &&
3434+
mWmsParameters.srcWidthAsInt() > 0 )
34333435
return mWmsParameters.srcWidthAsInt();
3434-
return mWmsParameters.heightAsInt();
3436+
return mWmsParameters.widthAsInt();
34353437
}
34363438

34373439
} // namespace QgsWms

‎src/server/services/wms/qgswmsrenderer.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,17 @@ namespace QgsWms
299299

300300
/**
301301
* Returns QgsWmsParameter SRCWIDTH if it's a GetLegendGraphics request and otherwise HEIGHT parameter
302-
* \returns getHeightAsInt parameter
302+
* \returns height parameter
303+
* \since QGIS 3.8
303304
*/
304-
int getHeightAsInt() const;
305+
int height() const;
305306

306307
/**
307308
* Returns QgsWmsParameter SRCWIDTH parameter if it's a GetLegendGraphics request and otherwise WIDTH parameter
308-
* \returns getWidthAsInt parameter
309+
* \returns width parameter
310+
* \since QGIS 3.8
309311
*/
310-
int getWidthAsInt() const;
312+
int width() const;
311313

312314
const QgsWmsParameters &mWmsParameters;
313315

0 commit comments

Comments
 (0)
Please sign in to comment.