Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix [Tests][Server] Add WMS GetPrint group
  • Loading branch information
rldhont committed Apr 22, 2020
1 parent 13434dc commit a06984c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
13 changes: 13 additions & 0 deletions src/server/services/wms/qgswmsrendercontext.cpp
Expand Up @@ -287,6 +287,19 @@ bool QgsWmsRenderContext::isValidLayer( const QString &nickname ) const
return layer( nickname ) != nullptr;
}

QList<QgsMapLayer *> QgsWmsRenderContext::layersFromGroup( const QString &nickname ) const
{
QList<QgsMapLayer *> layers;
if ( mLayerGroups.contains( nickname ) )
{
for ( QgsMapLayer *layer : mLayerGroups[nickname] )
{
layers.append( layer );
}
}
return layers;
}

bool QgsWmsRenderContext::isValidGroup( const QString &name ) const
{
return mLayerGroups.contains( name );
Expand Down
6 changes: 6 additions & 0 deletions src/server/services/wms/qgswmsrendercontext.h
Expand Up @@ -178,6 +178,12 @@ namespace QgsWms
*/
bool isValidLayer( const QString &nickname ) const;

/**
* Returns the group's layers list corresponding to the nickname, or
* an empty list if not found.
*/
QList<QgsMapLayer *> layersFromGroup( const QString &nickname ) const;

/**
* Returns true if \a name is a group.
*/
Expand Down
35 changes: 29 additions & 6 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -611,15 +611,38 @@ namespace QgsWms
QList<QgsMapLayer *> layerSet;
for ( auto layer : cMapParams.mLayers )
{
QgsMapLayer *mlayer = mContext.layer( layer.mNickname );

if ( ! mlayer )
if ( mContext.isValidGroup( layer.mNickname ) )
{
continue;
QList<QgsMapLayer *> layersFromGroup;

for ( QgsMapLayer *layer : mContext.layersFromGroup( layer.mNickname ) )
{

if ( ! layer )
{
continue;
}

layersFromGroup.push_front( layer );
}

if ( !layersFromGroup.isEmpty() )
{
layerSet.append( layersFromGroup );
}
}
else
{
QgsMapLayer *mlayer = mContext.layer( layer.mNickname );

setLayerStyle( mlayer, layer.mStyle );
layerSet << mlayer;
if ( ! mlayer )
{
continue;
}

setLayerStyle( mlayer, layer.mStyle );
layerSet << mlayer;
}
}

layerSet << externalLayers( cMapParams.mExternalLayers );
Expand Down
6 changes: 5 additions & 1 deletion tests/src/python/test_qgsserver_wms_getprint.py
Expand Up @@ -362,6 +362,7 @@ def test_wms_getprint_group(self):
"VERSION": "1.1.1",
"REQUEST": "GetPrint",
"TEMPLATE": "layoutA4",
"FORMAT": "png",
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
"map0:LAYERS": "Country_Diagrams,Country_Labels,Country",
"CRS": "EPSG:3857"
Expand All @@ -375,12 +376,13 @@ def test_wms_getprint_group(self):
"VERSION": "1.1.1",
"REQUEST": "GetPrint",
"TEMPLATE": "layoutA4",
"FORMAT": "png",
"map0:EXTENT": "-33626185.498,-13032965.185,33978427.737,16020257.031",
"map0:LAYERS": "CountryGroup",
"CRS": "EPSG:3857"
}.items())])

r_group, _ = self._result(self._execute_request(qs))
r_group, h = self._result(self._execute_request(qs))

""" Debug check:
f = open('grouped.png', 'wb+')
Expand All @@ -393,6 +395,8 @@ def test_wms_getprint_group(self):

self.assertEqual(r_individual, r_group, 'Individual layers query and group layers query results should be identical')

self._img_diff_error(r_group, h, "WMS_GetPrint_Group")

def test_wms_getprint_legend(self):
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a06984c

Please sign in to comment.