Skip to content
Permalink
Browse files

[Tests][Server] WMS GetPrint group

  • Loading branch information
github-actions authored and rldhont committed Apr 22, 2020
1 parent 2f72542 commit 5401fa4ef09fd1b3e30740e4823ae239efd26313
@@ -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 );
@@ -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.
*/
@@ -589,15 +589,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 );
@@ -355,6 +355,48 @@ def test_wms_getprint_style(self):
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetPrint_StyleCustom")

def test_wms_getprint_group(self):
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectGroupsPath),
"SERVICE": "WMS",
"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"
}.items())])

r_individual, _ = self._result(self._execute_request(qs))

qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectGroupsPath),
"SERVICE": "WMS",
"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, h = self._result(self._execute_request(qs))

""" Debug check:
f = open('grouped.png', 'wb+')
f.write(r_group)
f.close()
f = open('individual.png', 'wb+')
f.write(r_individual)
f.close()
#"""

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),
Binary file not shown.
Binary file not shown.

0 comments on commit 5401fa4

Please sign in to comment.
You can’t perform that action at this time.