Skip to content

Commit 717501d

Browse files
authoredApr 11, 2019
Merge pull request #9727 from signedav/backport_SRCWIDTH
[Backport release-3_6] of SRCHEIGHT/SRCWIDTH for GetLegendGraphic request
2 parents 31eec91 + 16ba9a8 commit 717501d

File tree

7 files changed

+163
-32
lines changed

7 files changed

+163
-32
lines changed
 

‎python/core/auto_generated/qgslegendsettings.sip.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ Returns the factor of map units per pixel for symbols with size given in map uni
200200

201201
.. seealso:: :py:func:`setMapUnitsPerPixel`
202202

203-
.. versionadded:: 3.8
203+
.. versionadded:: 3.4
204204
%End
205205

206206
void setMapUnitsPerPixel( double mapUnitsPerPixel );
@@ -209,7 +209,7 @@ Sets the mmPerMapUnit calculated by ``mapUnitsPerPixel`` mostly taken from the m
209209

210210
.. seealso:: :py:func:`mapUnitsPerPixel`
211211

212-
.. versionadded:: 3.8
212+
.. versionadded:: 3.4
213213
%End
214214

215215
int dpi() const;

‎src/core/qgslegendsettings.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,14 @@ class CORE_EXPORT QgsLegendSettings
181181
/**
182182
* Returns the factor of map units per pixel for symbols with size given in map units calculated by dpi and mmPerMapUnit
183183
* \see setMapUnitsPerPixel()
184-
* \since QGIS 3.8
184+
* \since QGIS 3.4
185185
*/
186186
double mapUnitsPerPixel() const;
187187

188188
/**
189189
* Sets the mmPerMapUnit calculated by \a mapUnitsPerPixel mostly taken from the map settings.
190190
* \see mapUnitsPerPixel()
191-
* \since QGIS 3.8
191+
* \since QGIS 3.4
192192
*/
193193
void setMapUnitsPerPixel( double mapUnitsPerPixel );
194194

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,16 @@ namespace QgsWms
364364
QVariant( 0 ) );
365365
save( pWidth );
366366

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

@@ -683,6 +693,26 @@ namespace QgsWms
683693
return mWmsParameters[ QgsWmsParameter::WIDTH ].toInt();
684694
}
685695

696+
QString QgsWmsParameters::srcHeight() const
697+
{
698+
return mWmsParameters[ QgsWmsParameter::SRCHEIGHT ].toString();
699+
}
700+
701+
QString QgsWmsParameters::srcWidth() const
702+
{
703+
return mWmsParameters[ QgsWmsParameter::SRCWIDTH ].toString();
704+
}
705+
706+
int QgsWmsParameters::srcHeightAsInt() const
707+
{
708+
return mWmsParameters[ QgsWmsParameter::SRCHEIGHT ].toInt();
709+
}
710+
711+
int QgsWmsParameters::srcWidthAsInt() const
712+
{
713+
return mWmsParameters[ QgsWmsParameter::SRCWIDTH ].toInt();
714+
}
715+
686716
QString QgsWmsParameters::dpi() const
687717
{
688718
return mWmsParameters[ QgsWmsParameter::DPI ].toString();

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ namespace QgsWms
167167
WITH_GEOMETRY,
168168
WITH_MAPTIP,
169169
WMTVER,
170-
ATLAS_PK
170+
ATLAS_PK,
171+
SRCWIDTH,
172+
SRCHEIGHT
171173
};
172174
Q_ENUM( Name )
173175

@@ -376,6 +378,40 @@ namespace QgsWms
376378
*/
377379
int heightAsInt() const;
378380

381+
/**
382+
* Returns SRCWIDTH parameter or an empty string if not defined.
383+
* \returns srcWidth parameter
384+
* \since QGIS 3.4
385+
*/
386+
QString srcWidth() const;
387+
388+
/**
389+
* Returns SRCWIDTH parameter as an int or its default value if not
390+
* defined. An exception is raised if SRCWIDTH is defined and cannot be
391+
* converted.
392+
* \returns srcWidth parameter
393+
* \throws QgsBadRequestException
394+
* \since QGIS 3.4
395+
*/
396+
int srcWidthAsInt() const;
397+
398+
/**
399+
* Returns SRCHEIGHT parameter or an empty string if not defined.
400+
* \returns srcHeight parameter
401+
* \since QGIS 3.4
402+
*/
403+
QString srcHeight() const;
404+
405+
/**
406+
* Returns SRCHEIGHT parameter as an int or its default value if not
407+
* defined. An exception is raised if SRCHEIGHT is defined and cannot be
408+
* converted.
409+
* \returns srcHeight parameter
410+
* \throws QgsBadRequestException
411+
* \since QGIS 3.4
412+
*/
413+
int srcHeightAsInt() const;
414+
379415
/**
380416
* Returns VERSION parameter if defined or its default value.
381417
* \returns version

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

Lines changed: 24 additions & 7 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( mWmsParameters.widthAsInt(), mWmsParameters.heightAsInt(), false ) );
190+
image.reset( createImage( width(), height(), false ) );
191191
configureMapSettings( image.get(), mapSettings );
192192
legendSettings.setMapScale( mapSettings.scale() );
193193
legendSettings.setMapUnitsPerPixel( mapSettings.mapUnitsPerPixel() );
@@ -1151,10 +1151,10 @@ namespace QgsWms
11511151
QImage *QgsRenderer::createImage( int width, int height, bool useBbox ) const
11521152
{
11531153
if ( width < 0 )
1154-
width = mWmsParameters.widthAsInt();
1154+
width = this->width();
11551155

11561156
if ( height < 0 )
1157-
height = mWmsParameters.heightAsInt();
1157+
height = this->height();
11581158

11591159
//Adapt width / height if the aspect ratio does not correspond with the BBOX.
11601160
//Required by WMS spec. 1.3.
@@ -2055,14 +2055,14 @@ namespace QgsWms
20552055
{
20562056
//test if maxWidth / maxHeight set and WIDTH / HEIGHT parameter is in the range
20572057
int wmsMaxWidth = QgsServerProjectUtils::wmsMaxWidth( *mProject );
2058-
int width = mWmsParameters.widthAsInt();
2058+
int width = this->width();
20592059
if ( wmsMaxWidth != -1 && width > wmsMaxWidth )
20602060
{
20612061
return false;
20622062
}
20632063

20642064
int wmsMaxHeight = QgsServerProjectUtils::wmsMaxHeight( *mProject );
2065-
int height = mWmsParameters.heightAsInt();
2065+
int height = this->height();
20662066
if ( wmsMaxHeight != -1 && height > wmsMaxHeight )
20672067
{
20682068
return false;
@@ -3277,8 +3277,8 @@ namespace QgsWms
32773277
// WIDTH / HEIGHT parameters. If not, the image has to be scaled (required
32783278
// by WMS spec)
32793279
QImage *scaledImage = nullptr;
3280-
int width = mWmsParameters.widthAsInt();
3281-
int height = mWmsParameters.heightAsInt();
3280+
int width = this->width();
3281+
int height = this->height();
32823282
if ( width != image->width() || height != image->height() )
32833283
{
32843284
scaledImage = new QImage( image->scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
@@ -3526,5 +3526,22 @@ namespace QgsWms
35263526
return result;
35273527
}
35283528

3529+
int QgsRenderer::height() const
3530+
{
3531+
if ( ( mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphic" ), Qt::CaseInsensitive ) == 0 ||
3532+
mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphics" ), Qt::CaseInsensitive ) == 0 ) &&
3533+
mWmsParameters.srcHeightAsInt() > 0 )
3534+
return mWmsParameters.srcHeightAsInt();
3535+
return mWmsParameters.heightAsInt();
3536+
}
3537+
3538+
int QgsRenderer::width() const
3539+
{
3540+
if ( ( mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphic" ), Qt::CaseInsensitive ) == 0 ||
3541+
mWmsParameters.request().compare( QStringLiteral( "GetLegendGraphics" ), Qt::CaseInsensitive ) == 0 ) &&
3542+
mWmsParameters.srcWidthAsInt() > 0 )
3543+
return mWmsParameters.srcWidthAsInt();
3544+
return mWmsParameters.widthAsInt();
3545+
}
35293546

35303547
} // namespace QgsWms

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,19 @@ namespace QgsWms
291291

292292
void handlePrintErrors( const QgsLayout *layout ) const;
293293

294-
private:
294+
/**
295+
* Returns QgsWmsParameter SRCWIDTH if it's a GetLegendGraphics request and otherwise HEIGHT parameter
296+
* \returns height parameter
297+
* \since QGIS 3.4
298+
*/
299+
int height() const;
300+
301+
/**
302+
* Returns QgsWmsParameter SRCWIDTH parameter if it's a GetLegendGraphics request and otherwise WIDTH parameter
303+
* \returns width parameter
304+
* \since QGIS 3.4
305+
*/
306+
int width() const;
295307

296308
const QgsWmsParameters &mWmsParameters;
297309

‎tests/src/python/test_qgsserver_wms_getlegendgraphic.py

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,42 @@ def test_wms_GetLegendGraphic_ItemFont(self):
460460
self._img_diff_error(r, h, "WMS_GetLegendGraphic_ItemFont", max_size_diff=QSize(1, 1))
461461

462462
def test_wms_GetLegendGraphic_BBox(self):
463+
qs = "?" + "&".join(["%s=%s" % i for i in list({
464+
"MAP": urllib.parse.quote(self.projectPath),
465+
"SERVICE": "WMS",
466+
"VERSION": "1.1.1",
467+
"REQUEST": "GetLegendGraphic",
468+
"LAYER": "Country,Hello,db_point",
469+
"LAYERTITLE": "FALSE",
470+
"FORMAT": "image/png",
471+
"SRCHEIGHT": "500",
472+
"SRCWIDTH": "500",
473+
"BBOX": "-151.7,-38.9,51.0,78.0",
474+
"CRS": "EPSG:4326"
475+
}.items())])
476+
477+
r, h = self._result(self._execute_request(qs))
478+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox")
479+
480+
def test_wms_GetLegendGraphic_BBox2(self):
481+
qs = "?" + "&".join(["%s=%s" % i for i in list({
482+
"MAP": urllib.parse.quote(self.projectPath),
483+
"SERVICE": "WMS",
484+
"VERSION": "1.1.1",
485+
"REQUEST": "GetLegendGraphic",
486+
"LAYER": "Country,Hello,db_point",
487+
"LAYERTITLE": "FALSE",
488+
"FORMAT": "image/png",
489+
"SRCHEIGHT": "500",
490+
"SRCWIDTH": "500",
491+
"BBOX": "-76.08,-6.4,-19.38,38.04",
492+
"SRS": "EPSG:4326"
493+
}.items())])
494+
495+
r, h = self._result(self._execute_request(qs))
496+
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox2")
497+
498+
def test_wms_GetLegendGraphic_BBox_Fallback(self):
463499
qs = "?" + "&".join(["%s=%s" % i for i in list({
464500
"MAP": urllib.parse.quote(self.projectPath),
465501
"SERVICE": "WMS",
@@ -477,7 +513,7 @@ def test_wms_GetLegendGraphic_BBox(self):
477513
r, h = self._result(self._execute_request(qs))
478514
self._img_diff_error(r, h, "WMS_GetLegendGraphic_BBox")
479515

480-
def test_wms_GetLegendGraphic_BBox2(self):
516+
def test_wms_GetLegendGraphic_BBox2_Fallback(self):
481517
qs = "?" + "&".join(["%s=%s" % i for i in list({
482518
"MAP": urllib.parse.quote(self.projectPath),
483519
"SERVICE": "WMS",
@@ -503,8 +539,8 @@ def test_wms_GetLegendGraphic_EmptyLegend(self):
503539
"REQUEST": "GetLegendGraphic",
504540
"LAYER": "QGIS%20Server%20Hello%20World",
505541
"FORMAT": "image/png",
506-
"HEIGHT": "840",
507-
"WIDTH": "1226",
542+
"SRCHEIGHT": "840",
543+
"SRCWIDTH": "1226",
508544
"BBOX": "10.38450,-49.6370,73.8183,42.9461",
509545
"SRS": "EPSG:4326",
510546
"SCALE": "15466642"
@@ -525,8 +561,8 @@ def test_wms_GetLegendGraphic_wmsRootName(self):
525561
"REQUEST": "GetLegendGraphic",
526562
"LAYER": "QGIS%20Server%20-%20Grouped%20Layer",
527563
"FORMAT": "image/png",
528-
"HEIGHT": "840",
529-
"WIDTH": "1226",
564+
"SRCHEIGHT": "840",
565+
"SRCWIDTH": "1226",
530566
"BBOX": "609152,5808188,625492,5814318",
531567
"SRS": "EPSG:25832",
532568
"SCALE": "38976"
@@ -544,8 +580,8 @@ def test_wms_GetLegendGraphic_wmsRootName(self):
544580
"REQUEST": "GetLegendGraphic",
545581
"LAYER": "All_grouped_layers",
546582
"FORMAT": "image/png",
547-
"HEIGHT": "840",
548-
"WIDTH": "1226",
583+
"SRCHEIGHT": "840",
584+
"SRCWIDTH": "1226",
549585
"BBOX": "609152,5808188,625492,5814318",
550586
"SRS": "EPSG:25832",
551587
"SCALE": "38976"
@@ -563,8 +599,8 @@ def test_wms_GetLegendGraphic_ScaleSymbol_Min(self):
563599
"REQUEST": "GetLegendGraphic",
564600
"LAYER": "testlayer",
565601
"FORMAT": "image/png",
566-
"HEIGHT": "550",
567-
"WIDTH": "850",
602+
"SRCHEIGHT": "550",
603+
"SRCWIDTH": "850",
568604
"BBOX": "-608.4,-1002.6,698.2,1019.0",
569605
"CRS": "EPSG:4326"
570606
}.items())])
@@ -579,8 +615,8 @@ def test_wms_GetLegendGraphic_ScaleSymbol_Min(self):
579615
"REQUEST": "GetLegendGraphic",
580616
"LAYER": "testlayer",
581617
"FORMAT": "image/png",
582-
"HEIGHT": "550",
583-
"WIDTH": "850",
618+
"SRCHEIGHT": "550",
619+
"SRCWIDTH": "850",
584620
"BBOX": "-1261.7,-2013.5,1351.5,2029.9",
585621
"CRS": "EPSG:4326"
586622
}.items())])
@@ -596,8 +632,8 @@ def test_wms_GetLegendGraphic_ScaleSymbol_Scaled_01(self):
596632
"REQUEST": "GetLegendGraphic",
597633
"LAYER": "testlayer",
598634
"FORMAT": "image/png",
599-
"HEIGHT": "550",
600-
"WIDTH": "850",
635+
"SRCHEIGHT": "550",
636+
"SRCWIDTH": "850",
601637
"BBOX": "31.8,-12.0,58.0,28.4",
602638
"CRS": "EPSG:4326"
603639
}.items())])
@@ -613,8 +649,8 @@ def test_wms_GetLegendGraphic_ScaleSymbol_Scaled_02(self):
613649
"REQUEST": "GetLegendGraphic",
614650
"LAYER": "testlayer",
615651
"FORMAT": "image/png",
616-
"HEIGHT": "550",
617-
"WIDTH": "850",
652+
"SRCHEIGHT": "550",
653+
"SRCWIDTH": "850",
618654
"BBOX": "25.3,-22.1,64.5,38.5",
619655
"CRS": "EPSG:4326"
620656
}.items())])
@@ -630,8 +666,8 @@ def test_wms_GetLegendGraphic_ScaleSymbol_Max(self):
630666
"REQUEST": "GetLegendGraphic",
631667
"LAYER": "testlayer",
632668
"FORMAT": "image/png",
633-
"HEIGHT": "550",
634-
"WIDTH": "850",
669+
"SRCHEIGHT": "550",
670+
"SRCWIDTH": "850",
635671
"BBOX": "44.8,8.0,45.0,8.4",
636672
"CRS": "EPSG:4326"
637673
}.items())])
@@ -646,8 +682,8 @@ def test_wms_GetLegendGraphic_ScaleSymbol_Max(self):
646682
"REQUEST": "GetLegendGraphic",
647683
"LAYER": "testlayer",
648684
"FORMAT": "image/png",
649-
"HEIGHT": "550",
650-
"WIDTH": "850",
685+
"SRCHEIGHT": "550",
686+
"SRCWIDTH": "850",
651687
"BBOX": "43.6,6.2,46.2,10.2",
652688
"CRS": "EPSG:4326"
653689
}.items())])

0 commit comments

Comments
 (0)
Please sign in to comment.