mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
[server] Implement LAYERFONTCOLOR and ITEMFONTCOLOR
Fixes #21871 Fixes #21870 Funded by: Gis3w
This commit is contained in:
parent
3c6299a199
commit
7032db27fa
@ -75,6 +75,30 @@ Returns style
|
||||
QColor fontColor() const;
|
||||
void setFontColor( const QColor &c );
|
||||
|
||||
QColor layerFontColor() const;
|
||||
%Docstring
|
||||
Returns layer font color, defaults to fontColor()
|
||||
|
||||
.. seealso:: :py:func:`setLayerFontColor`
|
||||
|
||||
.. seealso:: :py:func:`fontColor`
|
||||
|
||||
.. versionadded:: 3.4.7
|
||||
%End
|
||||
|
||||
void setLayerFontColor( const QColor &fontColor );
|
||||
%Docstring
|
||||
Sets layer font color to ``fontColor``
|
||||
Overrides fontColor()
|
||||
|
||||
.. seealso:: :py:func:`layerFontColor`
|
||||
|
||||
.. seealso:: :py:func:`fontColor`
|
||||
|
||||
.. versionadded:: 3.4.7
|
||||
%End
|
||||
|
||||
|
||||
QSizeF symbolSize() const;
|
||||
void setSymbolSize( QSizeF s );
|
||||
|
||||
|
@ -661,9 +661,9 @@ QSizeF QgsLegendRenderer::drawLayerTitleInternal( QgsLayerTreeLayer *nodeLayer,
|
||||
double y = point.y();
|
||||
|
||||
if ( context && context->painter() )
|
||||
context->painter()->setPen( mSettings.fontColor() );
|
||||
context->painter()->setPen( mSettings.layerFontColor() );
|
||||
else if ( painter )
|
||||
painter->setPen( mSettings.fontColor() );
|
||||
painter->setPen( mSettings.layerFontColor() );
|
||||
|
||||
QFont layerFont = mSettings.style( nodeLegendStyle( nodeLayer ) ).font();
|
||||
|
||||
|
@ -88,6 +88,24 @@ class CORE_EXPORT QgsLegendSettings
|
||||
QColor fontColor() const {return mFontColor;}
|
||||
void setFontColor( const QColor &c ) {mFontColor = c;}
|
||||
|
||||
/**
|
||||
* Returns layer font color, defaults to fontColor()
|
||||
* \see setLayerFontColor()
|
||||
* \see fontColor()
|
||||
* \since QGIS 3.4.7
|
||||
*/
|
||||
QColor layerFontColor() const {return mLayerFontColor.isValid() ? mLayerFontColor : fontColor() ;}
|
||||
|
||||
/**
|
||||
* Sets layer font color to \a fontColor
|
||||
* Overrides fontColor()
|
||||
* \see layerFontColor()
|
||||
* \see fontColor()
|
||||
* \since QGIS 3.4.7
|
||||
*/
|
||||
void setLayerFontColor( const QColor &fontColor ) {mLayerFontColor = fontColor;}
|
||||
|
||||
|
||||
QSizeF symbolSize() const {return mSymbolSize;}
|
||||
void setSymbolSize( QSizeF s ) {mSymbolSize = s;}
|
||||
|
||||
@ -306,6 +324,9 @@ class CORE_EXPORT QgsLegendSettings
|
||||
|
||||
//! DPI to be used when rendering legend
|
||||
int mDpi = 96;
|
||||
|
||||
//! Font color for layers, overrides font color
|
||||
QColor mLayerFontColor;
|
||||
};
|
||||
|
||||
|
||||
|
@ -1139,6 +1139,16 @@ namespace QgsWms
|
||||
return mWmsParameters[ QgsWmsParameter::ITEMFONTSIZE ].toDouble();
|
||||
}
|
||||
|
||||
QString QgsWmsParameters::itemFontColor() const
|
||||
{
|
||||
return mWmsParameters[ QgsWmsParameter::ITEMFONTCOLOR ].toString();
|
||||
}
|
||||
|
||||
QColor QgsWmsParameters::itemFontColorAsColor() const
|
||||
{
|
||||
return mWmsParameters[ QgsWmsParameter::ITEMFONTCOLOR ].toColor();
|
||||
}
|
||||
|
||||
QFont QgsWmsParameters::layerFont() const
|
||||
{
|
||||
QFont font;
|
||||
@ -1193,6 +1203,18 @@ namespace QgsWms
|
||||
settings.rstyle( QgsLegendStyle::Style::Subgroup ).setMargin( QgsLegendStyle::Side::Bottom, layerTitleSpaceAsDouble() );
|
||||
settings.rstyle( QgsLegendStyle::Style::Subgroup ).setFont( layerFont() );
|
||||
|
||||
if ( !itemFontColor().isEmpty() )
|
||||
{
|
||||
settings.setFontColor( itemFontColorAsColor() );
|
||||
}
|
||||
|
||||
// Ok, this is tricky: because QgsLegendSettings's layerFontColor was added to the API after
|
||||
// fontColor, to fix regressions #21871 and #21870 and the previous behavior was to use fontColor
|
||||
// for the whole legend we need to preserve that behavior.
|
||||
// But, the 2.18 server parameters ITEMFONTCOLOR did not have effect on the layer titles too, so
|
||||
// we set explicitly layerFontColor to black if it's not overridden by LAYERFONTCOLOR argument.
|
||||
settings.setLayerFontColor( layerFontColor().isEmpty() ? QColor( Qt::black ) : layerFontColorAsColor() );
|
||||
|
||||
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() );
|
||||
|
@ -194,7 +194,7 @@ namespace QgsWms
|
||||
/**
|
||||
* Default destructor for QgsWmsParameter.
|
||||
*/
|
||||
virtual ~QgsWmsParameter() = default;
|
||||
virtual ~QgsWmsParameter() override = default;
|
||||
|
||||
/**
|
||||
* Returns TRUE if the parameter is valid, FALSE otherwise.
|
||||
@ -363,7 +363,7 @@ namespace QgsWms
|
||||
*/
|
||||
QgsWmsParameters();
|
||||
|
||||
virtual ~QgsWmsParameters() = default;
|
||||
virtual ~QgsWmsParameters() override = default;
|
||||
|
||||
/**
|
||||
* Returns the parameter corresponding to \a name.
|
||||
|
@ -735,6 +735,76 @@ class TestQgsServerWMSGetLegendGraphic(QgsServerTestBase):
|
||||
|
||||
r, h = self._result(self._execute_request(qs))
|
||||
self._img_diff_error(r, h, "WMS_GetLegendGraphic_ScaleSymbol_DefaultScale_2056", max_size_diff=QSize(15, 15))
|
||||
|
||||
def test_wms_GetLegendGraphic_LAYERFONTCOLOR(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",
|
||||
"CRS": "EPSG:3857",
|
||||
"LAYERFONTCOLOR": "red"
|
||||
}.items())])
|
||||
|
||||
r, h = self._result(self._execute_request(qs))
|
||||
self._img_diff_error(r, h, "WMS_GetLegendGraphic_LAYERFONTCOLOR")
|
||||
|
||||
def test_wms_GetLegendGraphic_ITEMFONTCOLOR(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",
|
||||
"CRS": "EPSG:3857",
|
||||
"ITEMFONTCOLOR": "red",
|
||||
}.items())])
|
||||
|
||||
r, h = self._result(self._execute_request(qs))
|
||||
self._img_diff_error(r, h, "WMS_GetLegendGraphic_ITEMFONTCOLOR")
|
||||
|
||||
def test_wms_GetLegendGraphic_ITEMFONTCOLOR_and_LAYERFONTCOLOR(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",
|
||||
"CRS": "EPSG:3857",
|
||||
"ITEMFONTCOLOR": "red",
|
||||
"LAYERFONTCOLOR": "blue"
|
||||
}.items())])
|
||||
|
||||
r, h = self._result(self._execute_request(qs))
|
||||
self._img_diff_error(r, h, "WMS_GetLegendGraphic_ITEMFONTCOLOR_and_LAYERFONTCOLOR")
|
||||
|
||||
def test_wms_GetLegendGraphic_ITEMFONTCOLOR_and_LAYERFONTCOLOR_hex(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",
|
||||
"CRS": "EPSG:3857",
|
||||
"ITEMFONTCOLOR": r"%23FF0000",
|
||||
"LAYERFONTCOLOR": r"%230000FF"
|
||||
}.items())])
|
||||
|
||||
r, h = self._result(self._execute_request(qs))
|
||||
self._img_diff_error(r, h, "WMS_GetLegendGraphic_ITEMFONTCOLOR_and_LAYERFONTCOLOR")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
Loading…
x
Reference in New Issue
Block a user