Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso authored and github-actions[bot] committed Jul 31, 2021
1 parent c8b51ac commit 390f82d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
13 changes: 6 additions & 7 deletions src/server/services/wms/qgswmsrenderer.cpp
Expand Up @@ -699,23 +699,22 @@ namespace QgsWms
QMap<QString, QString> layersStyle;
if ( map->followVisibilityPreset() )
{
QString presetName = map->followVisibilityPresetName();
const QString presetName = map->followVisibilityPresetName();
if ( layerSet.isEmpty() )
{
// Get the layers from the theme
const QgsExpressionContext ex { map->createExpressionContext() };
layerSet = map->layersToRender( &ex );
}
// Unable the theme
// Disable the theme
map->setFollowVisibilityPreset( false );

// Collect the style of each layer in the theme that has been unabled
QList<QgsMapThemeCollection::MapThemeLayerRecord> mapThemeRecords = QgsProject::instance()->mapThemeCollection()->mapThemeState( presetName ).layerRecords();
for ( auto layerMapThemeRecord : mapThemeRecords )
// Collect the style of each layer in the theme that has been disabled
const QList<QgsMapThemeCollection::MapThemeLayerRecord> mapThemeRecords = QgsProject::instance()->mapThemeCollection()->mapThemeState( presetName ).layerRecords();
for ( const auto &layerMapThemeRecord : std::as_const( mapThemeRecords ) )
{
if ( layerSet.contains( layerMapThemeRecord.layer() ) )
{
QString styleName = layerMapThemeRecord.currentStyle;
layersStyle.insert( layerMapThemeRecord.layer()->id(),
layerMapThemeRecord.layer()->styleManager()->style( layerMapThemeRecord.currentStyle ).xmlData() );
}
Expand Down Expand Up @@ -830,7 +829,7 @@ namespace QgsWms
QList<QgsMapLayer *> mapLayers;
if ( map->layers().isEmpty() )
{
// in QGIS desktop, all layers has its legend, including invisible layers
// in QGIS desktop, each layer has its legend, including invisible layers
// and using maptheme, legend items are automatically filtered
mapLayers = mProject->mapLayers( true ).values();
}
Expand Down
28 changes: 14 additions & 14 deletions tests/src/python/test_qgsserver_wms_getprint_legend.py
Expand Up @@ -71,7 +71,7 @@ def test_wms_getprint_legend(self):
# First item : 600 x , 40 y
# Second item : 600 x , 60 y

# blank template, no theme, specified layer is red
# blank template, no theme, no LAYERS, specified map0:LAYERS is red
response = QgsBufferServerResponse()
request = QgsBufferServerRequest('?' + '&'.join(["%s=%s" % i for i in params.items()]))
self.server.handleRequest(request, response, project)
Expand All @@ -81,7 +81,7 @@ def test_wms_getprint_legend(self):
self._assertRed(image.pixelColor(600, 40))
self._assertWhite(image.pixelColor(600, 60))

# blank template, specified layer is green
# blank template, no LAYERS, specified map0:LAYERS is green
params["map0:LAYERS"] = "green"
response = QgsBufferServerResponse()
request = QgsBufferServerRequest('?' + '&'.join(["%s=%s" % i for i in params.items()]))
Expand All @@ -103,7 +103,7 @@ def test_wms_getprint_legend(self):
self._assertRed(image.pixelColor(600, 40))
self._assertGreen(image.pixelColor(600, 60))

# red template, red theme, specified layer is red
# red template, red theme, specified map0:LAYERS is red
params["TEMPLATE"] = "red"
params["map0:LAYERS"] = "red"
response = QgsBufferServerResponse()
Expand All @@ -115,7 +115,7 @@ def test_wms_getprint_legend(self):
self._assertRed(image.pixelColor(600, 40))
self._assertWhite(image.pixelColor(600, 60))

# red template, red theme, specified layer is green
# red template, red theme, specified map0:LAYERS is green
params["map0:LAYERS"] = "green"
response = QgsBufferServerResponse()
request = QgsBufferServerRequest('?' + '&'.join(["%s=%s" % i for i in params.items()]))
Expand All @@ -126,7 +126,7 @@ def test_wms_getprint_legend(self):
self._assertGreen(image.pixelColor(600, 40))
self._assertWhite(image.pixelColor(600, 60))

# red template, red theme
# red template, red theme, no map0:LAYERS
params["map0:LAYERS"] = ""
response = QgsBufferServerResponse()
request = QgsBufferServerRequest('?' + '&'.join(["%s=%s" % i for i in params.items()]))
Expand All @@ -137,7 +137,7 @@ def test_wms_getprint_legend(self):
self._assertRed(image.pixelColor(600, 40))
self._assertWhite(image.pixelColor(600, 60))

# green template, green theme, specified layer is red
# green template, green theme, specified map0:LAYERS is red
params["TEMPLATE"] = "green"
params["map0:LAYERS"] = "red"
response = QgsBufferServerResponse()
Expand All @@ -149,7 +149,7 @@ def test_wms_getprint_legend(self):
self._assertRed(image.pixelColor(600, 40))
self._assertWhite(image.pixelColor(600, 60))

# green template, green theme, specified layer is green
# green template, green theme, specified map0:LAYERS is green
params["map0:LAYERS"] = "green"
response = QgsBufferServerResponse()
request = QgsBufferServerRequest('?' + '&'.join(["%s=%s" % i for i in params.items()]))
Expand All @@ -160,7 +160,7 @@ def test_wms_getprint_legend(self):
self._assertGreen(image.pixelColor(600, 40))
self._assertWhite(image.pixelColor(600, 60))

# green template, green theme
# green template, green theme, no map0:LAYERS
params["map0:LAYERS"] = ""
response = QgsBufferServerResponse()
request = QgsBufferServerRequest('?' + '&'.join(["%s=%s" % i for i in params.items()]))
Expand All @@ -171,7 +171,7 @@ def test_wms_getprint_legend(self):
self._assertGreen(image.pixelColor(600, 40))
self._assertWhite(image.pixelColor(600, 60))

# full template, full theme, specified layer is red
# full template, full theme, specified map0:LAYERS is red
params["TEMPLATE"] = "full"
params["map0:LAYERS"] = "red"
response = QgsBufferServerResponse()
Expand All @@ -183,7 +183,7 @@ def test_wms_getprint_legend(self):
self._assertRed(image.pixelColor(600, 40))
self._assertWhite(image.pixelColor(600, 60))

# full template, full theme, specified layer is green
# full template, full theme, specified map0:LAYERS is green
params["map0:LAYERS"] = "green"
response = QgsBufferServerResponse()
request = QgsBufferServerRequest('?' + '&'.join(["%s=%s" % i for i in params.items()]))
Expand All @@ -194,7 +194,7 @@ def test_wms_getprint_legend(self):
self._assertGreen(image.pixelColor(600, 40))
self._assertWhite(image.pixelColor(600, 60))

# full template, full theme
# full template, full theme, no map0:LAYERS
params["map0:LAYERS"] = ""
response = QgsBufferServerResponse()
request = QgsBufferServerRequest('?' + '&'.join(["%s=%s" % i for i in params.items()]))
Expand All @@ -205,7 +205,7 @@ def test_wms_getprint_legend(self):
self._assertRed(image.pixelColor(600, 40))
self._assertGreen(image.pixelColor(600, 60))

# falsegreen template, falsegreen theme (green layer is blue), specified layer is red
# falsegreen template, falsegreen theme (green layer is blue), specified map0:LAYERS is red
params["TEMPLATE"] = "falsegreen"
params["map0:LAYERS"] = "red"
response = QgsBufferServerResponse()
Expand All @@ -217,7 +217,7 @@ def test_wms_getprint_legend(self):
self._assertRed(image.pixelColor(600, 40))
self._assertWhite(image.pixelColor(600, 60))

# full template, full theme, specified layer is green
# full template, full theme, specified map0:LAYERS is green
params["map0:LAYERS"] = "green"
response = QgsBufferServerResponse()
request = QgsBufferServerRequest('?' + '&'.join(["%s=%s" % i for i in params.items()]))
Expand All @@ -228,7 +228,7 @@ def test_wms_getprint_legend(self):
self._assertBlue(image.pixelColor(600, 40))
self._assertWhite(image.pixelColor(600, 60))

# full template, full theme
# full template, full theme, no map0:LAYERS
params["map0:LAYERS"] = ""
response = QgsBufferServerResponse()
request = QgsBufferServerRequest('?' + '&'.join(["%s=%s" % i for i in params.items()]))
Expand Down

0 comments on commit 390f82d

Please sign in to comment.