Skip to content

Commit

Permalink
[server] Respect layer title space when rendering legends
Browse files Browse the repository at this point in the history
Fixes #20693 - LAYERTITLESPACE in GetLegendGraphic is not taken into account
  • Loading branch information
elpaso committed Jan 4, 2019
1 parent 899dcbf commit d499940
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/core/qgslegendrenderer.cpp
Expand Up @@ -543,6 +543,7 @@ QSizeF QgsLegendRenderer::drawLayerTitle( QgsLayerTreeLayer *nodeLayer, QPainter
}
}
size.rheight() = y - point.y();
size.rheight() += mSettings.style( nodeLegendStyle( nodeLayer ) ).margin( QgsLegendStyle::Side::Bottom );

return size;
}
Expand Down
11 changes: 6 additions & 5 deletions src/server/services/wms/qgswmsparameters.cpp
Expand Up @@ -1109,12 +1109,13 @@ namespace QgsWms
settings.setBoxSpace( boxSpaceAsDouble() );
settings.setSymbolSize( QSizeF( symbolWidthAsDouble(), symbolHeightAsDouble() ) );

settings.rstyle( QgsLegendStyle::Subgroup ).setMargin( QgsLegendStyle::Top, layerSpaceAsDouble() );
settings.rstyle( QgsLegendStyle::Subgroup ).setFont( layerFont() );
settings.rstyle( QgsLegendStyle::Style::Subgroup ).setMargin( QgsLegendStyle::Side::Top, layerSpaceAsDouble() );
settings.rstyle( QgsLegendStyle::Style::Subgroup ).setMargin( QgsLegendStyle::Side::Bottom, layerTitleSpaceAsDouble() );
settings.rstyle( QgsLegendStyle::Style::Subgroup ).setFont( layerFont() );

settings.rstyle( QgsLegendStyle::SymbolLabel ).setFont( itemFont() );
settings.rstyle( QgsLegendStyle::Symbol ).setMargin( QgsLegendStyle::Top, symbolSpaceAsDouble() );
settings.rstyle( QgsLegendStyle::SymbolLabel ).setMargin( QgsLegendStyle::Left, iconLabelSpaceAsDouble() );
settings.rstyle( QgsLegendStyle::Style::SymbolLabel ).setFont( itemFont() );
settings.rstyle( QgsLegendStyle::Style::Symbol ).setMargin( QgsLegendStyle::Side::Top, symbolSpaceAsDouble() );
settings.rstyle( QgsLegendStyle::Style::SymbolLabel ).setMargin( QgsLegendStyle::Side::Left, iconLabelSpaceAsDouble() );

return settings;
}
Expand Down
25 changes: 24 additions & 1 deletion tests/src/python/test_qgsserver_wms_getlegendgraphic.py
Expand Up @@ -40,7 +40,6 @@


class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):

"""QGIS Server WMS Tests for GetLegendGraphic request"""

def test_getLegendGraphics(self):
Expand Down Expand Up @@ -105,6 +104,30 @@ def test_wms_GetLegendGraphic_LayerSpace(self):
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_LayerSpace")

def test_wms_GetLegendGraphic_LayerTitleSpace(self):
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetLegendGraphic",
"LAYER": "Country,Hello",
"FORMAT": "image/png",
# "HEIGHT": "500",
# "WIDTH": "500",
"LAYERTITLESPACE": "20.0",
"LAYERFONTBOLD": "TRUE",
"LAYERFONTSIZE": "30",
"ITEMFONTBOLD": "TRUE",
"ITEMFONTSIZE": "20",
"LAYERFONTFAMILY": self.fontFamily,
"ITEMFONTFAMILY": self.fontFamily,
"LAYERTITLE": "TRUE",
"CRS": "EPSG:3857"
}.items())])

r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetLegendGraphic_LayerTitleSpace")

def test_wms_GetLegendGraphic_ShowFeatureCount(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 d499940

Please sign in to comment.