Move QgsLegendStyle::Style enum to Qgis, rename to LegendComponent

This commit is contained in:
Nyall Dawson 2025-02-18 11:26:12 +10:00
parent b2f27a8529
commit 8911a5b726
30 changed files with 457 additions and 380 deletions

View File

@ -7749,6 +7749,46 @@ Qgis.LayerTreeFilterFlag.baseClass = Qgis
Qgis.LayerTreeFilterFlags = lambda flags=0: Qgis.LayerTreeFilterFlag(flags) Qgis.LayerTreeFilterFlags = lambda flags=0: Qgis.LayerTreeFilterFlag(flags)
Qgis.LayerTreeFilterFlags.baseClass = Qgis Qgis.LayerTreeFilterFlags.baseClass = Qgis
LayerTreeFilterFlags = Qgis # dirty hack since SIP seems to introduce the flags in module LayerTreeFilterFlags = Qgis # dirty hack since SIP seems to introduce the flags in module
QgsLegendStyle.Style = Qgis.LegendComponent
# monkey patching scoped based enum
QgsLegendStyle.Undefined = Qgis.LegendComponent.Undefined
QgsLegendStyle.Undefined.is_monkey_patched = True
QgsLegendStyle.Undefined.__doc__ = "Should not happen, only if corrupted project file"
QgsLegendStyle.Hidden = Qgis.LegendComponent.Hidden
QgsLegendStyle.Hidden.is_monkey_patched = True
QgsLegendStyle.Hidden.__doc__ = "Special style, item is hidden including margins around"
QgsLegendStyle.Title = Qgis.LegendComponent.Title
QgsLegendStyle.Title.is_monkey_patched = True
QgsLegendStyle.Title.__doc__ = "Legend title"
QgsLegendStyle.Group = Qgis.LegendComponent.Group
QgsLegendStyle.Group.is_monkey_patched = True
QgsLegendStyle.Group.__doc__ = "Legend group title"
QgsLegendStyle.Subgroup = Qgis.LegendComponent.Subgroup
QgsLegendStyle.Subgroup.is_monkey_patched = True
QgsLegendStyle.Subgroup.__doc__ = "Legend subgroup title"
QgsLegendStyle.Symbol = Qgis.LegendComponent.Symbol
QgsLegendStyle.Symbol.is_monkey_patched = True
QgsLegendStyle.Symbol.__doc__ = "Symbol icon (excluding label)"
QgsLegendStyle.SymbolLabel = Qgis.LegendComponent.SymbolLabel
QgsLegendStyle.SymbolLabel.is_monkey_patched = True
QgsLegendStyle.SymbolLabel.__doc__ = "Symbol label (excluding icon)"
Qgis.LegendComponent.__doc__ = """Component of legends which can be styled.
Prior to QGIS 3.42 this was available as :py:class:`QgsLegendStyle`.Style
.. versionadded:: 3.42
* ``Undefined``: Should not happen, only if corrupted project file
* ``Hidden``: Special style, item is hidden including margins around
* ``Title``: Legend title
* ``Group``: Legend group title
* ``Subgroup``: Legend subgroup title
* ``Symbol``: Symbol icon (excluding label)
* ``SymbolLabel``: Symbol label (excluding icon)
"""
# --
Qgis.LegendComponent.baseClass = Qgis
# monkey patching scoped based enum # monkey patching scoped based enum
Qgis.LegendJsonRenderFlag.ShowRuleDetails.__doc__ = "If set, the rule expression of a rule based renderer legend item will be added to the JSON" Qgis.LegendJsonRenderFlag.ShowRuleDetails.__doc__ = "If set, the rule expression of a rule based renderer legend item will be added to the JSON"
Qgis.LegendJsonRenderFlag.__doc__ = """Legend JSON export flags. Qgis.LegendJsonRenderFlag.__doc__ = """Legend JSON export flags.

View File

@ -1,11 +1,4 @@
# The following has been generated automatically from src/core/qgslegendstyle.h # The following has been generated automatically from src/core/qgslegendstyle.h
QgsLegendStyle.Undefined = QgsLegendStyle.Style.Undefined
QgsLegendStyle.Hidden = QgsLegendStyle.Style.Hidden
QgsLegendStyle.Title = QgsLegendStyle.Style.Title
QgsLegendStyle.Group = QgsLegendStyle.Style.Group
QgsLegendStyle.Subgroup = QgsLegendStyle.Style.Subgroup
QgsLegendStyle.Symbol = QgsLegendStyle.Style.Symbol
QgsLegendStyle.SymbolLabel = QgsLegendStyle.Style.SymbolLabel
QgsLegendStyle.Top = QgsLegendStyle.Side.Top QgsLegendStyle.Top = QgsLegendStyle.Side.Top
QgsLegendStyle.Bottom = QgsLegendStyle.Side.Bottom QgsLegendStyle.Bottom = QgsLegendStyle.Side.Bottom
QgsLegendStyle.Left = QgsLegendStyle.Side.Left QgsLegendStyle.Left = QgsLegendStyle.Side.Left

View File

@ -196,22 +196,22 @@ Sets the ``alignment`` of the legend title.
.. seealso:: :py:func:`titleAlignment` .. seealso:: :py:func:`titleAlignment`
%End %End
QgsLegendStyle &rstyle( QgsLegendStyle::Style s ); QgsLegendStyle &rstyle( Qgis::LegendComponent s );
%Docstring %Docstring
Returns reference to modifiable legend style. Returns reference to modifiable legend style.
%End %End
QgsLegendStyle style( QgsLegendStyle::Style s ) const; QgsLegendStyle style( Qgis::LegendComponent s ) const;
%Docstring %Docstring
Returns legend style. Returns legend style.
%End %End
void setStyle( QgsLegendStyle::Style component, const QgsLegendStyle &style ); void setStyle( Qgis::LegendComponent component, const QgsLegendStyle &style );
%Docstring %Docstring
Sets the style of ``component`` to ``style`` for the legend. Sets the style of ``component`` to ``style`` for the legend.
%End %End
QFont styleFont( QgsLegendStyle::Style component ) const /Deprecated="Since 3.40. Use QgsLegendStyle.textFormat() from style() instead."/; QFont styleFont( Qgis::LegendComponent component ) const /Deprecated="Since 3.40. Use QgsLegendStyle.textFormat() from style() instead."/;
%Docstring %Docstring
Returns the font settings for a legend ``component``. Returns the font settings for a legend ``component``.
@ -222,7 +222,7 @@ Returns the font settings for a legend ``component``.
Use :py:func:`QgsLegendStyle.textFormat()` from :py:func:`~QgsLayoutItemLegend.style` instead. Use :py:func:`QgsLegendStyle.textFormat()` from :py:func:`~QgsLayoutItemLegend.style` instead.
%End %End
void setStyleFont( QgsLegendStyle::Style component, const QFont &font ) /Deprecated="Since 3.40. Use QgsLegendStyle.setTextFormat() from style() instead."/; void setStyleFont( Qgis::LegendComponent component, const QFont &font ) /Deprecated="Since 3.40. Use QgsLegendStyle.setTextFormat() from style() instead."/;
%Docstring %Docstring
Sets the style ``font`` for a legend ``component``. Sets the style ``font`` for a legend ``component``.
@ -233,12 +233,12 @@ Sets the style ``font`` for a legend ``component``.
Use :py:func:`QgsLegendStyle.setTextFormat()` from :py:func:`~QgsLayoutItemLegend.style` instead. Use :py:func:`QgsLegendStyle.setTextFormat()` from :py:func:`~QgsLayoutItemLegend.style` instead.
%End %End
void setStyleMargin( QgsLegendStyle::Style component, double margin ); void setStyleMargin( Qgis::LegendComponent component, double margin );
%Docstring %Docstring
Set the ``margin`` for a legend ``component``. Set the ``margin`` for a legend ``component``.
%End %End
void setStyleMargin( QgsLegendStyle::Style component, QgsLegendStyle::Side side, double margin ); void setStyleMargin( Qgis::LegendComponent component, QgsLegendStyle::Side side, double margin );
%Docstring %Docstring
Set the ``margin`` for a particular ``side`` of a legend ``component``. Set the ``margin`` for a particular ``side`` of a legend ``component``.
%End %End

View File

@ -2432,6 +2432,16 @@ The development version
typedef QFlags<Qgis::LayerTreeFilterFlag> LayerTreeFilterFlags; typedef QFlags<Qgis::LayerTreeFilterFlag> LayerTreeFilterFlags;
enum class LegendComponent /BaseType=IntEnum/
{
Undefined,
Hidden,
Title,
Group,
Subgroup,
Symbol,
SymbolLabel,
};
enum class LegendJsonRenderFlag /BaseType=IntFlag/ enum class LegendJsonRenderFlag /BaseType=IntFlag/
{ {

View File

@ -100,14 +100,14 @@ Renders the legend in a ``json`` object.
.. versionadded:: 3.8 .. versionadded:: 3.8
%End %End
static void setNodeLegendStyle( QgsLayerTreeNode *node, QgsLegendStyle::Style style ); static void setNodeLegendStyle( QgsLayerTreeNode *node, Qgis::LegendComponent style );
%Docstring %Docstring
Sets the ``style`` of a ``node``. Sets the ``style`` of a ``node``.
.. seealso:: :py:func:`nodeLegendStyle` .. seealso:: :py:func:`nodeLegendStyle`
%End %End
static QgsLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode *node, QgsLayerTreeModel *model ); static Qgis::LegendComponent nodeLegendStyle( QgsLayerTreeNode *node, QgsLayerTreeModel *model );
%Docstring %Docstring
Returns the style for the given ``node``, within the specified ``model``. Returns the style for the given ``node``, within the specified ``model``.

View File

@ -63,14 +63,14 @@ Sets the ``alignment`` of the legend title.
%End %End
QgsLegendStyle style( QgsLegendStyle::Style s ) const; QgsLegendStyle style( Qgis::LegendComponent s ) const;
%Docstring %Docstring
Returns the style for a legend component. Returns the style for a legend component.
.. seealso:: :py:func:`setStyle` .. seealso:: :py:func:`setStyle`
%End %End
void setStyle( QgsLegendStyle::Style s, const QgsLegendStyle &style ); void setStyle( Qgis::LegendComponent s, const QgsLegendStyle &style );
%Docstring %Docstring
Sets the ``style`` for a legend component. Sets the ``style`` for a legend component.

View File

@ -21,17 +21,6 @@ Contains detailed styling information relating to how a layout legend should be
%End %End
public: public:
enum Style /BaseType=IntEnum/
{
Undefined,
Hidden,
Title,
Group,
Subgroup,
Symbol,
SymbolLabel,
};
enum Side /BaseType=IntEnum/ enum Side /BaseType=IntEnum/
{ {
@ -171,7 +160,7 @@ render ``context``.
.. versionadded:: 3.42 .. versionadded:: 3.42
%End %End
static QString styleName( Style s ); static QString styleName( Qgis::LegendComponent s );
%Docstring %Docstring
Returns the name for a style component as a string. Returns the name for a style component as a string.
@ -182,14 +171,14 @@ This is a non-localised version, for internal use.
.. seealso:: :py:func:`styleLabel` .. seealso:: :py:func:`styleLabel`
%End %End
static Style styleFromName( const QString &styleName ); static Qgis::LegendComponent styleFromName( const QString &styleName );
%Docstring %Docstring
Returns the style from name string. Returns the style from name string.
.. seealso:: :py:func:`styleName` .. seealso:: :py:func:`styleName`
%End %End
static QString styleLabel( Style s ); static QString styleLabel( Qgis::LegendComponent s );
%Docstring %Docstring
Returns a translated string representing a style component, for use in UI. Returns a translated string representing a style component, for use in UI.

View File

@ -7675,6 +7675,46 @@ Qgis.LayerTreeFilterFlag.__doc__ = """Layer tree filter flags.
Qgis.LayerTreeFilterFlag.baseClass = Qgis Qgis.LayerTreeFilterFlag.baseClass = Qgis
Qgis.LayerTreeFilterFlags.baseClass = Qgis Qgis.LayerTreeFilterFlags.baseClass = Qgis
LayerTreeFilterFlags = Qgis # dirty hack since SIP seems to introduce the flags in module LayerTreeFilterFlags = Qgis # dirty hack since SIP seems to introduce the flags in module
QgsLegendStyle.Style = Qgis.LegendComponent
# monkey patching scoped based enum
QgsLegendStyle.Undefined = Qgis.LegendComponent.Undefined
QgsLegendStyle.Undefined.is_monkey_patched = True
QgsLegendStyle.Undefined.__doc__ = "Should not happen, only if corrupted project file"
QgsLegendStyle.Hidden = Qgis.LegendComponent.Hidden
QgsLegendStyle.Hidden.is_monkey_patched = True
QgsLegendStyle.Hidden.__doc__ = "Special style, item is hidden including margins around"
QgsLegendStyle.Title = Qgis.LegendComponent.Title
QgsLegendStyle.Title.is_monkey_patched = True
QgsLegendStyle.Title.__doc__ = "Legend title"
QgsLegendStyle.Group = Qgis.LegendComponent.Group
QgsLegendStyle.Group.is_monkey_patched = True
QgsLegendStyle.Group.__doc__ = "Legend group title"
QgsLegendStyle.Subgroup = Qgis.LegendComponent.Subgroup
QgsLegendStyle.Subgroup.is_monkey_patched = True
QgsLegendStyle.Subgroup.__doc__ = "Legend subgroup title"
QgsLegendStyle.Symbol = Qgis.LegendComponent.Symbol
QgsLegendStyle.Symbol.is_monkey_patched = True
QgsLegendStyle.Symbol.__doc__ = "Symbol icon (excluding label)"
QgsLegendStyle.SymbolLabel = Qgis.LegendComponent.SymbolLabel
QgsLegendStyle.SymbolLabel.is_monkey_patched = True
QgsLegendStyle.SymbolLabel.__doc__ = "Symbol label (excluding icon)"
Qgis.LegendComponent.__doc__ = """Component of legends which can be styled.
Prior to QGIS 3.42 this was available as :py:class:`QgsLegendStyle`.Style
.. versionadded:: 3.42
* ``Undefined``: Should not happen, only if corrupted project file
* ``Hidden``: Special style, item is hidden including margins around
* ``Title``: Legend title
* ``Group``: Legend group title
* ``Subgroup``: Legend subgroup title
* ``Symbol``: Symbol icon (excluding label)
* ``SymbolLabel``: Symbol label (excluding icon)
"""
# --
Qgis.LegendComponent.baseClass = Qgis
# monkey patching scoped based enum # monkey patching scoped based enum
Qgis.LegendJsonRenderFlag.ShowRuleDetails.__doc__ = "If set, the rule expression of a rule based renderer legend item will be added to the JSON" Qgis.LegendJsonRenderFlag.ShowRuleDetails.__doc__ = "If set, the rule expression of a rule based renderer legend item will be added to the JSON"
Qgis.LegendJsonRenderFlag.__doc__ = """Legend JSON export flags. Qgis.LegendJsonRenderFlag.__doc__ = """Legend JSON export flags.

View File

@ -196,22 +196,22 @@ Sets the ``alignment`` of the legend title.
.. seealso:: :py:func:`titleAlignment` .. seealso:: :py:func:`titleAlignment`
%End %End
QgsLegendStyle &rstyle( QgsLegendStyle::Style s ); QgsLegendStyle &rstyle( Qgis::LegendComponent s );
%Docstring %Docstring
Returns reference to modifiable legend style. Returns reference to modifiable legend style.
%End %End
QgsLegendStyle style( QgsLegendStyle::Style s ) const; QgsLegendStyle style( Qgis::LegendComponent s ) const;
%Docstring %Docstring
Returns legend style. Returns legend style.
%End %End
void setStyle( QgsLegendStyle::Style component, const QgsLegendStyle &style ); void setStyle( Qgis::LegendComponent component, const QgsLegendStyle &style );
%Docstring %Docstring
Sets the style of ``component`` to ``style`` for the legend. Sets the style of ``component`` to ``style`` for the legend.
%End %End
QFont styleFont( QgsLegendStyle::Style component ) const /Deprecated="Since 3.40. Use QgsLegendStyle.textFormat() from style() instead."/; QFont styleFont( Qgis::LegendComponent component ) const /Deprecated="Since 3.40. Use QgsLegendStyle.textFormat() from style() instead."/;
%Docstring %Docstring
Returns the font settings for a legend ``component``. Returns the font settings for a legend ``component``.
@ -222,7 +222,7 @@ Returns the font settings for a legend ``component``.
Use :py:func:`QgsLegendStyle.textFormat()` from :py:func:`~QgsLayoutItemLegend.style` instead. Use :py:func:`QgsLegendStyle.textFormat()` from :py:func:`~QgsLayoutItemLegend.style` instead.
%End %End
void setStyleFont( QgsLegendStyle::Style component, const QFont &font ) /Deprecated="Since 3.40. Use QgsLegendStyle.setTextFormat() from style() instead."/; void setStyleFont( Qgis::LegendComponent component, const QFont &font ) /Deprecated="Since 3.40. Use QgsLegendStyle.setTextFormat() from style() instead."/;
%Docstring %Docstring
Sets the style ``font`` for a legend ``component``. Sets the style ``font`` for a legend ``component``.
@ -233,12 +233,12 @@ Sets the style ``font`` for a legend ``component``.
Use :py:func:`QgsLegendStyle.setTextFormat()` from :py:func:`~QgsLayoutItemLegend.style` instead. Use :py:func:`QgsLegendStyle.setTextFormat()` from :py:func:`~QgsLayoutItemLegend.style` instead.
%End %End
void setStyleMargin( QgsLegendStyle::Style component, double margin ); void setStyleMargin( Qgis::LegendComponent component, double margin );
%Docstring %Docstring
Set the ``margin`` for a legend ``component``. Set the ``margin`` for a legend ``component``.
%End %End
void setStyleMargin( QgsLegendStyle::Style component, QgsLegendStyle::Side side, double margin ); void setStyleMargin( Qgis::LegendComponent component, QgsLegendStyle::Side side, double margin );
%Docstring %Docstring
Set the ``margin`` for a particular ``side`` of a legend ``component``. Set the ``margin`` for a particular ``side`` of a legend ``component``.
%End %End

View File

@ -2432,6 +2432,16 @@ The development version
typedef QFlags<Qgis::LayerTreeFilterFlag> LayerTreeFilterFlags; typedef QFlags<Qgis::LayerTreeFilterFlag> LayerTreeFilterFlags;
enum class LegendComponent
{
Undefined,
Hidden,
Title,
Group,
Subgroup,
Symbol,
SymbolLabel,
};
enum class LegendJsonRenderFlag enum class LegendJsonRenderFlag
{ {

View File

@ -100,14 +100,14 @@ Renders the legend in a ``json`` object.
.. versionadded:: 3.8 .. versionadded:: 3.8
%End %End
static void setNodeLegendStyle( QgsLayerTreeNode *node, QgsLegendStyle::Style style ); static void setNodeLegendStyle( QgsLayerTreeNode *node, Qgis::LegendComponent style );
%Docstring %Docstring
Sets the ``style`` of a ``node``. Sets the ``style`` of a ``node``.
.. seealso:: :py:func:`nodeLegendStyle` .. seealso:: :py:func:`nodeLegendStyle`
%End %End
static QgsLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode *node, QgsLayerTreeModel *model ); static Qgis::LegendComponent nodeLegendStyle( QgsLayerTreeNode *node, QgsLayerTreeModel *model );
%Docstring %Docstring
Returns the style for the given ``node``, within the specified ``model``. Returns the style for the given ``node``, within the specified ``model``.

View File

@ -63,14 +63,14 @@ Sets the ``alignment`` of the legend title.
%End %End
QgsLegendStyle style( QgsLegendStyle::Style s ) const; QgsLegendStyle style( Qgis::LegendComponent s ) const;
%Docstring %Docstring
Returns the style for a legend component. Returns the style for a legend component.
.. seealso:: :py:func:`setStyle` .. seealso:: :py:func:`setStyle`
%End %End
void setStyle( QgsLegendStyle::Style s, const QgsLegendStyle &style ); void setStyle( Qgis::LegendComponent s, const QgsLegendStyle &style );
%Docstring %Docstring
Sets the ``style`` for a legend component. Sets the ``style`` for a legend component.

View File

@ -21,17 +21,6 @@ Contains detailed styling information relating to how a layout legend should be
%End %End
public: public:
enum Style
{
Undefined,
Hidden,
Title,
Group,
Subgroup,
Symbol,
SymbolLabel,
};
enum Side enum Side
{ {
@ -171,7 +160,7 @@ render ``context``.
.. versionadded:: 3.42 .. versionadded:: 3.42
%End %End
static QString styleName( Style s ); static QString styleName( Qgis::LegendComponent s );
%Docstring %Docstring
Returns the name for a style component as a string. Returns the name for a style component as a string.
@ -182,14 +171,14 @@ This is a non-localised version, for internal use.
.. seealso:: :py:func:`styleLabel` .. seealso:: :py:func:`styleLabel`
%End %End
static Style styleFromName( const QString &styleName ); static Qgis::LegendComponent styleFromName( const QString &styleName );
%Docstring %Docstring
Returns the style from name string. Returns the style from name string.
.. seealso:: :py:func:`styleName` .. seealso:: :py:func:`styleName`
%End %End
static QString styleLabel( Style s ); static QString styleLabel( Qgis::LegendComponent s );
%Docstring %Docstring
Returns a translated string representing a style component, for use in UI. Returns a translated string representing a style component, for use in UI.

View File

@ -222,7 +222,7 @@ QSizeF QgsColorRampLegendNode::drawSymbol( const QgsLegendSettings &settings, It
context = tempRenderContext.get(); context = tempRenderContext.get();
} }
const QgsTextFormat format = mSettings.textFormat().isValid() ? mSettings.textFormat() : settings.style( QgsLegendStyle::SymbolLabel ).textFormat(); const QgsTextFormat format = mSettings.textFormat().isValid() ? mSettings.textFormat() : settings.style( Qgis::LegendComponent::SymbolLabel ).textFormat();
const QString minLabel = labelForMinimum(); const QString minLabel = labelForMinimum();
const QString maxLabel = labelForMaximum(); const QString maxLabel = labelForMaximum();
@ -351,8 +351,8 @@ QSizeF QgsColorRampLegendNode::drawSymbol( const QgsLegendSettings &settings, It
// NOTE -- while the below calculations use the flipped margins from the style, that's only done because // NOTE -- while the below calculations use the flipped margins from the style, that's only done because
// those are the only margins we expose and use for now! (and we expose them as generic margins, not side-specific // those are the only margins we expose and use for now! (and we expose them as generic margins, not side-specific
// ones) TODO when/if we expose other margin settings, these should be reversed... // ones) TODO when/if we expose other margin settings, these should be reversed...
const double labelYMin = currentYCoord + rampHeight + settings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Right ) const double labelYMin = currentYCoord + rampHeight + settings.style( Qgis::LegendComponent::Symbol ).margin( QgsLegendStyle::Right )
+ settings.style( QgsLegendStyle::SymbolLabel ).margin( QgsLegendStyle::Left ); + settings.style( Qgis::LegendComponent::SymbolLabel ).margin( QgsLegendStyle::Left );
const double labelHeight = std::max( QgsTextRenderer::textHeight( *context, format, QStringList() << minLabel ), const double labelHeight = std::max( QgsTextRenderer::textHeight( *context, format, QStringList() << minLabel ),
QgsTextRenderer::textHeight( *context, format, QStringList() << maxLabel ) ) / dotsPerMM; QgsTextRenderer::textHeight( *context, format, QStringList() << maxLabel ) ) / dotsPerMM;
switch ( settings.symbolAlignment() ) switch ( settings.symbolAlignment() )
@ -382,8 +382,8 @@ QSizeF QgsColorRampLegendNode::drawSymbol( const QgsLegendSettings &settings, It
// we only need this when we are calculating the size of the node, not at render time // we only need this when we are calculating the size of the node, not at render time
labelHeight = std::max( QgsTextRenderer::textHeight( *context, format, QStringList() << minLabel ), labelHeight = std::max( QgsTextRenderer::textHeight( *context, format, QStringList() << minLabel ),
QgsTextRenderer::textHeight( *context, format, QStringList() << maxLabel ) ) / context->scaleFactor() QgsTextRenderer::textHeight( *context, format, QStringList() << maxLabel ) ) / context->scaleFactor()
+ settings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Right ) + settings.style( Qgis::LegendComponent::Symbol ).margin( QgsLegendStyle::Right )
+ settings.style( QgsLegendStyle::SymbolLabel ).margin( QgsLegendStyle::Left ); + settings.style( Qgis::LegendComponent::SymbolLabel ).margin( QgsLegendStyle::Left );
} }
} }
@ -422,7 +422,7 @@ QSizeF QgsColorRampLegendNode::drawSymbolText( const QgsLegendSettings &settings
context = tempRenderContext.get(); context = tempRenderContext.get();
} }
const QgsTextFormat format = mSettings.textFormat().isValid() ? mSettings.textFormat() : settings.style( QgsLegendStyle::SymbolLabel ).textFormat(); const QgsTextFormat format = mSettings.textFormat().isValid() ? mSettings.textFormat() : settings.style( Qgis::LegendComponent::SymbolLabel ).textFormat();
const QString minLabel = labelForMinimum(); const QString minLabel = labelForMinimum();
const QString maxLabel = labelForMaximum(); const QString maxLabel = labelForMaximum();
@ -452,8 +452,8 @@ QSizeF QgsColorRampLegendNode::drawSymbolText( const QgsLegendSettings &settings
case Qt::AlignLeft: case Qt::AlignLeft:
default: default:
labelXMin = ctx->columnLeft + std::max( rampWidth, ctx->maxSiblingSymbolWidth ) labelXMin = ctx->columnLeft + std::max( rampWidth, ctx->maxSiblingSymbolWidth )
+ settings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Right ) + settings.style( Qgis::LegendComponent::Symbol ).margin( QgsLegendStyle::Right )
+ settings.style( QgsLegendStyle::SymbolLabel ).margin( QgsLegendStyle::Left ); + settings.style( Qgis::LegendComponent::SymbolLabel ).margin( QgsLegendStyle::Left );
labelXMax = ctx->columnRight; labelXMax = ctx->columnRight;
break; break;
@ -463,16 +463,16 @@ QSizeF QgsColorRampLegendNode::drawSymbolText( const QgsLegendSettings &settings
// those are the only margins we expose and use for now! (and we expose them as generic margins, not side-specific // those are the only margins we expose and use for now! (and we expose them as generic margins, not side-specific
// ones) TODO when/if we expose other margin settings, these should be reversed... // ones) TODO when/if we expose other margin settings, these should be reversed...
labelXMax = ctx->columnRight - std::max( rampWidth, ctx->maxSiblingSymbolWidth ) labelXMax = ctx->columnRight - std::max( rampWidth, ctx->maxSiblingSymbolWidth )
- settings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Right ) - settings.style( Qgis::LegendComponent::Symbol ).margin( QgsLegendStyle::Right )
- settings.style( QgsLegendStyle::SymbolLabel ).margin( QgsLegendStyle::Left ); - settings.style( Qgis::LegendComponent::SymbolLabel ).margin( QgsLegendStyle::Left );
break; break;
} }
const QRectF textRect( labelXMin * dotsPerMM, currentYCoord * dotsPerMM, ( labelXMax - labelXMin ) * dotsPerMM, rampHeight * dotsPerMM ); const QRectF textRect( labelXMin * dotsPerMM, currentYCoord * dotsPerMM, ( labelXMax - labelXMin ) * dotsPerMM, rampHeight * dotsPerMM );
QgsTextRenderer::drawText( textRect, 0, QgsTextRenderer::convertQtHAlignment( settings.style( QgsLegendStyle::SymbolLabel ).alignment() ), QgsTextRenderer::drawText( textRect, 0, QgsTextRenderer::convertQtHAlignment( settings.style( Qgis::LegendComponent::SymbolLabel ).alignment() ),
QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel ), QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? maxLabel : minLabel ),
*context, format, true, Qgis::TextVerticalAlignment::Top ); *context, format, true, Qgis::TextVerticalAlignment::Top );
QgsTextRenderer::drawText( textRect, 0, QgsTextRenderer::convertQtHAlignment( settings.style( QgsLegendStyle::SymbolLabel ).alignment() ), QgsTextRenderer::drawText( textRect, 0, QgsTextRenderer::convertQtHAlignment( settings.style( Qgis::LegendComponent::SymbolLabel ).alignment() ),
QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel ), QStringList() << ( mSettings.direction() == QgsColorRampLegendNodeSettings::MinimumToMaximum ? minLabel : maxLabel ),
*context, format, true, Qgis::TextVerticalAlignment::Bottom ); *context, format, true, Qgis::TextVerticalAlignment::Bottom );
} }

View File

@ -87,7 +87,7 @@ void QgsLayerTreeModelLegendNode::setUserPatchSize( QSizeF size )
QgsLayerTreeModelLegendNode::ItemMetrics QgsLayerTreeModelLegendNode::draw( const QgsLegendSettings &settings, ItemContext *ctx ) QgsLayerTreeModelLegendNode::ItemMetrics QgsLayerTreeModelLegendNode::draw( const QgsLegendSettings &settings, ItemContext *ctx )
{ {
const QgsTextFormat f = settings.style( QgsLegendStyle::SymbolLabel ).textFormat(); const QgsTextFormat f = settings.style( Qgis::LegendComponent::SymbolLabel ).textFormat();
const QStringList lines = settings.evaluateItemText( data( Qt::DisplayRole ).toString(), ctx->context->expressionContext() ); const QStringList lines = settings.evaluateItemText( data( Qt::DisplayRole ).toString(), ctx->context->expressionContext() );
@ -195,7 +195,7 @@ QSizeF QgsLayerTreeModelLegendNode::drawSymbolText( const QgsLegendSettings &set
context = tempContext.get(); context = tempContext.get();
} }
const QgsTextFormat format = settings.style( QgsLegendStyle::SymbolLabel ).textFormat(); const QgsTextFormat format = settings.style( Qgis::LegendComponent::SymbolLabel ).textFormat();
// TODO QGIS 4.0 -- make these all mandatory // TODO QGIS 4.0 -- make these all mandatory
std::optional< QgsTextDocument > tempDocument; std::optional< QgsTextDocument > tempDocument;
@ -231,8 +231,8 @@ QSizeF QgsLayerTreeModelLegendNode::drawSymbolText( const QgsLegendSettings &set
case Qt::AlignLeft: case Qt::AlignLeft:
default: default:
labelXMin = ctx->columnLeft + std::max( static_cast< double >( symbolSizeMM.width() ), ctx->maxSiblingSymbolWidth ) labelXMin = ctx->columnLeft + std::max( static_cast< double >( symbolSizeMM.width() ), ctx->maxSiblingSymbolWidth )
+ settings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Right ) + settings.style( Qgis::LegendComponent::Symbol ).margin( QgsLegendStyle::Right )
+ settings.style( QgsLegendStyle::SymbolLabel ).margin( QgsLegendStyle::Left ); + settings.style( Qgis::LegendComponent::SymbolLabel ).margin( QgsLegendStyle::Left );
labelXMax = ctx->columnRight; labelXMax = ctx->columnRight;
break; break;
@ -242,8 +242,8 @@ QSizeF QgsLayerTreeModelLegendNode::drawSymbolText( const QgsLegendSettings &set
// those are the only margins we expose and use for now! (and we expose them as generic margins, not side-specific // those are the only margins we expose and use for now! (and we expose them as generic margins, not side-specific
// ones) TODO when/if we expose other margin settings, these should be reversed... // ones) TODO when/if we expose other margin settings, these should be reversed...
labelXMax = ctx->columnRight - std::max( static_cast< double >( symbolSizeMM.width() ), ctx->maxSiblingSymbolWidth ) labelXMax = ctx->columnRight - std::max( static_cast< double >( symbolSizeMM.width() ), ctx->maxSiblingSymbolWidth )
- settings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Right ) - settings.style( Qgis::LegendComponent::Symbol ).margin( QgsLegendStyle::Right )
- settings.style( QgsLegendStyle::SymbolLabel ).margin( QgsLegendStyle::Left ); - settings.style( Qgis::LegendComponent::SymbolLabel ).margin( QgsLegendStyle::Left );
break; break;
} }
@ -256,8 +256,8 @@ QSizeF QgsLayerTreeModelLegendNode::drawSymbolText( const QgsLegendSettings &set
if ( context->painter() ) if ( context->painter() )
{ {
Qgis::TextHorizontalAlignment halign = settings.style( QgsLegendStyle::SymbolLabel ).alignment() == Qt::AlignLeft ? Qgis::TextHorizontalAlignment::Left : Qgis::TextHorizontalAlignment halign = settings.style( Qgis::LegendComponent::SymbolLabel ).alignment() == Qt::AlignLeft ? Qgis::TextHorizontalAlignment::Left :
settings.style( QgsLegendStyle::SymbolLabel ).alignment() == Qt::AlignRight ? Qgis::TextHorizontalAlignment::Right : Qgis::TextHorizontalAlignment::Center; settings.style( Qgis::LegendComponent::SymbolLabel ).alignment() == Qt::AlignRight ? Qgis::TextHorizontalAlignment::Right : Qgis::TextHorizontalAlignment::Center;
QgsTextRenderer::drawDocument( QRectF( labelXMin * dotsPerMM, std::round( labelYMM * dotsPerMM ), QgsTextRenderer::drawDocument( QRectF( labelXMin * dotsPerMM, std::round( labelYMM * dotsPerMM ),
@ -1550,8 +1550,8 @@ QgsLayerTreeModelLegendNode::ItemMetrics QgsDataDefinedSizeLegendNode::draw( con
} }
QgsDataDefinedSizeLegend ddsLegend( *mSettings ); QgsDataDefinedSizeLegend ddsLegend( *mSettings );
ddsLegend.setFont( settings.style( QgsLegendStyle::SymbolLabel ).textFormat().toQFont() ); ddsLegend.setFont( settings.style( Qgis::LegendComponent::SymbolLabel ).textFormat().toQFont() );
ddsLegend.setTextColor( settings.style( QgsLegendStyle::SymbolLabel ).textFormat().color() ); ddsLegend.setTextColor( settings.style( Qgis::LegendComponent::SymbolLabel ).textFormat().color() );
QSizeF contentSize; QSizeF contentSize;
double labelXOffset; double labelXOffset;

View File

@ -1278,12 +1278,12 @@ bool QgsCompositionConverter::readLegendXml( QgsLayoutItemLegend *layoutItem, co
QgsLegendStyle style; QgsLegendStyle style;
style.readXml( styleElem, QDomDocument() ); style.readXml( styleElem, QDomDocument() );
const QString name = styleElem.attribute( QStringLiteral( "name" ) ); const QString name = styleElem.attribute( QStringLiteral( "name" ) );
QgsLegendStyle::Style s; Qgis::LegendComponent s;
if ( name == QLatin1String( "title" ) ) s = QgsLegendStyle::Title; if ( name == QLatin1String( "title" ) ) s = Qgis::LegendComponent::Title;
else if ( name == QLatin1String( "group" ) ) s = QgsLegendStyle::Group; else if ( name == QLatin1String( "group" ) ) s = Qgis::LegendComponent::Group;
else if ( name == QLatin1String( "subgroup" ) ) s = QgsLegendStyle::Subgroup; else if ( name == QLatin1String( "subgroup" ) ) s = Qgis::LegendComponent::Subgroup;
else if ( name == QLatin1String( "symbol" ) ) s = QgsLegendStyle::Symbol; else if ( name == QLatin1String( "symbol" ) ) s = Qgis::LegendComponent::Symbol;
else if ( name == QLatin1String( "symbolLabel" ) ) s = QgsLegendStyle::SymbolLabel; else if ( name == QLatin1String( "symbolLabel" ) ) s = Qgis::LegendComponent::SymbolLabel;
else continue; else continue;
layoutItem->setStyle( s, style ); layoutItem->setStyle( s, style );
} }
@ -1292,10 +1292,10 @@ bool QgsCompositionConverter::readLegendXml( QgsLayoutItemLegend *layoutItem, co
//font color //font color
QColor fontClr; QColor fontClr;
fontClr.setNamedColor( itemElem.attribute( QStringLiteral( "fontColor" ), QStringLiteral( "#000000" ) ) ); fontClr.setNamedColor( itemElem.attribute( QStringLiteral( "fontColor" ), QStringLiteral( "#000000" ) ) );
layoutItem->rstyle( QgsLegendStyle::Title ).textFormat().setColor( fontClr ); layoutItem->rstyle( Qgis::LegendComponent::Title ).textFormat().setColor( fontClr );
layoutItem->rstyle( QgsLegendStyle::Group ).textFormat().setColor( fontClr ); layoutItem->rstyle( Qgis::LegendComponent::Group ).textFormat().setColor( fontClr );
layoutItem->rstyle( QgsLegendStyle::Subgroup ).textFormat().setColor( fontClr ); layoutItem->rstyle( Qgis::LegendComponent::Subgroup ).textFormat().setColor( fontClr );
layoutItem->rstyle( QgsLegendStyle::SymbolLabel ).textFormat().setColor( fontClr ); layoutItem->rstyle( Qgis::LegendComponent::SymbolLabel ).textFormat().setColor( fontClr );
//spaces //spaces
layoutItem->setBoxSpace( itemElem.attribute( QStringLiteral( "boxSpace" ), QStringLiteral( "2.0" ) ).toDouble() ); layoutItem->setBoxSpace( itemElem.attribute( QStringLiteral( "boxSpace" ), QStringLiteral( "2.0" ) ).toDouble() );

View File

@ -408,41 +408,41 @@ void QgsLayoutItemLegend::setTitleAlignment( Qt::AlignmentFlag alignment )
mSettings.setTitleAlignment( alignment ); mSettings.setTitleAlignment( alignment );
} }
QgsLegendStyle &QgsLayoutItemLegend::rstyle( QgsLegendStyle::Style s ) QgsLegendStyle &QgsLayoutItemLegend::rstyle( Qgis::LegendComponent s )
{ {
return mSettings.rstyle( s ); return mSettings.rstyle( s );
} }
QgsLegendStyle QgsLayoutItemLegend::style( QgsLegendStyle::Style s ) const QgsLegendStyle QgsLayoutItemLegend::style( Qgis::LegendComponent s ) const
{ {
return mSettings.style( s ); return mSettings.style( s );
} }
void QgsLayoutItemLegend::setStyle( QgsLegendStyle::Style s, const QgsLegendStyle &style ) void QgsLayoutItemLegend::setStyle( Qgis::LegendComponent s, const QgsLegendStyle &style )
{ {
mSettings.setStyle( s, style ); mSettings.setStyle( s, style );
} }
QFont QgsLayoutItemLegend::styleFont( QgsLegendStyle::Style s ) const QFont QgsLayoutItemLegend::styleFont( Qgis::LegendComponent s ) const
{ {
Q_NOWARN_DEPRECATED_PUSH Q_NOWARN_DEPRECATED_PUSH
return mSettings.style( s ).font(); return mSettings.style( s ).font();
Q_NOWARN_DEPRECATED_POP Q_NOWARN_DEPRECATED_POP
} }
void QgsLayoutItemLegend::setStyleFont( QgsLegendStyle::Style s, const QFont &f ) void QgsLayoutItemLegend::setStyleFont( Qgis::LegendComponent s, const QFont &f )
{ {
Q_NOWARN_DEPRECATED_PUSH Q_NOWARN_DEPRECATED_PUSH
rstyle( s ).setFont( f ); rstyle( s ).setFont( f );
Q_NOWARN_DEPRECATED_POP Q_NOWARN_DEPRECATED_POP
} }
void QgsLayoutItemLegend::setStyleMargin( QgsLegendStyle::Style s, double margin ) void QgsLayoutItemLegend::setStyleMargin( Qgis::LegendComponent s, double margin )
{ {
rstyle( s ).setMargin( margin ); rstyle( s ).setMargin( margin );
} }
void QgsLayoutItemLegend::setStyleMargin( QgsLegendStyle::Style s, QgsLegendStyle::Side side, double margin ) void QgsLayoutItemLegend::setStyleMargin( Qgis::LegendComponent s, QgsLegendStyle::Side side, double margin )
{ {
rstyle( s ).setMargin( side, margin ); rstyle( s ).setMargin( side, margin );
} }
@ -696,11 +696,11 @@ bool QgsLayoutItemLegend::writePropertiesToElement( QDomElement &legendElem, QDo
QDomElement legendStyles = doc.createElement( QStringLiteral( "styles" ) ); QDomElement legendStyles = doc.createElement( QStringLiteral( "styles" ) );
legendElem.appendChild( legendStyles ); legendElem.appendChild( legendStyles );
style( QgsLegendStyle::Title ).writeXml( QStringLiteral( "title" ), legendStyles, doc, context ); style( Qgis::LegendComponent::Title ).writeXml( QStringLiteral( "title" ), legendStyles, doc, context );
style( QgsLegendStyle::Group ).writeXml( QStringLiteral( "group" ), legendStyles, doc, context ); style( Qgis::LegendComponent::Group ).writeXml( QStringLiteral( "group" ), legendStyles, doc, context );
style( QgsLegendStyle::Subgroup ).writeXml( QStringLiteral( "subgroup" ), legendStyles, doc, context ); style( Qgis::LegendComponent::Subgroup ).writeXml( QStringLiteral( "subgroup" ), legendStyles, doc, context );
style( QgsLegendStyle::Symbol ).writeXml( QStringLiteral( "symbol" ), legendStyles, doc, context ); style( Qgis::LegendComponent::Symbol ).writeXml( QStringLiteral( "symbol" ), legendStyles, doc, context );
style( QgsLegendStyle::SymbolLabel ).writeXml( QStringLiteral( "symbolLabel" ), legendStyles, doc, context ); style( Qgis::LegendComponent::SymbolLabel ).writeXml( QStringLiteral( "symbolLabel" ), legendStyles, doc, context );
if ( mCustomLayerTree ) if ( mCustomLayerTree )
{ {
@ -743,12 +743,12 @@ bool QgsLayoutItemLegend::readPropertiesFromElement( const QDomElement &itemElem
QgsLegendStyle style; QgsLegendStyle style;
style.readXml( styleElem, doc, context ); style.readXml( styleElem, doc, context );
const QString name = styleElem.attribute( QStringLiteral( "name" ) ); const QString name = styleElem.attribute( QStringLiteral( "name" ) );
QgsLegendStyle::Style s; Qgis::LegendComponent s;
if ( name == QLatin1String( "title" ) ) s = QgsLegendStyle::Title; if ( name == QLatin1String( "title" ) ) s = Qgis::LegendComponent::Title;
else if ( name == QLatin1String( "group" ) ) s = QgsLegendStyle::Group; else if ( name == QLatin1String( "group" ) ) s = Qgis::LegendComponent::Group;
else if ( name == QLatin1String( "subgroup" ) ) s = QgsLegendStyle::Subgroup; else if ( name == QLatin1String( "subgroup" ) ) s = Qgis::LegendComponent::Subgroup;
else if ( name == QLatin1String( "symbol" ) ) s = QgsLegendStyle::Symbol; else if ( name == QLatin1String( "symbol" ) ) s = Qgis::LegendComponent::Symbol;
else if ( name == QLatin1String( "symbolLabel" ) ) s = QgsLegendStyle::SymbolLabel; else if ( name == QLatin1String( "symbolLabel" ) ) s = Qgis::LegendComponent::SymbolLabel;
else continue; else continue;
setStyle( s, style ); setStyle( s, style );
} }
@ -759,10 +759,10 @@ bool QgsLayoutItemLegend::readPropertiesFromElement( const QDomElement &itemElem
{ {
QColor fontClr; QColor fontClr;
fontClr.setNamedColor( itemElem.attribute( QStringLiteral( "fontColor" ), QStringLiteral( "#000000" ) ) ); fontClr.setNamedColor( itemElem.attribute( QStringLiteral( "fontColor" ), QStringLiteral( "#000000" ) ) );
rstyle( QgsLegendStyle::Title ).textFormat().setColor( fontClr ); rstyle( Qgis::LegendComponent::Title ).textFormat().setColor( fontClr );
rstyle( QgsLegendStyle::Group ).textFormat().setColor( fontClr ); rstyle( Qgis::LegendComponent::Group ).textFormat().setColor( fontClr );
rstyle( QgsLegendStyle::Subgroup ).textFormat().setColor( fontClr ); rstyle( Qgis::LegendComponent::Subgroup ).textFormat().setColor( fontClr );
rstyle( QgsLegendStyle::SymbolLabel ).textFormat().setColor( fontClr ); rstyle( Qgis::LegendComponent::SymbolLabel ).textFormat().setColor( fontClr );
} }
//spaces //spaces
@ -781,26 +781,26 @@ bool QgsLayoutItemLegend::readPropertiesFromElement( const QDomElement &itemElem
{ {
const double spacing = itemElem.attribute( QStringLiteral( "lineSpacing" ), QStringLiteral( "1.0" ) ).toDouble(); const double spacing = itemElem.attribute( QStringLiteral( "lineSpacing" ), QStringLiteral( "1.0" ) ).toDouble();
// line spacing *was* a fixed amount (in mm) added between each line of text. // line spacing *was* a fixed amount (in mm) added between each line of text.
QgsTextFormat f = rstyle( QgsLegendStyle::Title ).textFormat(); QgsTextFormat f = rstyle( Qgis::LegendComponent::Title ).textFormat();
// assume font sizes in points, since that was what we always had from before this method was deprecated // assume font sizes in points, since that was what we always had from before this method was deprecated
f.setLineHeight( f.size() * 0.352778 + spacing ); f.setLineHeight( f.size() * 0.352778 + spacing );
f.setLineHeightUnit( Qgis::RenderUnit::Millimeters ); f.setLineHeightUnit( Qgis::RenderUnit::Millimeters );
rstyle( QgsLegendStyle::Title ).setTextFormat( f ); rstyle( Qgis::LegendComponent::Title ).setTextFormat( f );
f = rstyle( QgsLegendStyle::Group ).textFormat(); f = rstyle( Qgis::LegendComponent::Group ).textFormat();
f.setLineHeight( f.size() * 0.352778 + spacing ); f.setLineHeight( f.size() * 0.352778 + spacing );
f.setLineHeightUnit( Qgis::RenderUnit::Millimeters ); f.setLineHeightUnit( Qgis::RenderUnit::Millimeters );
rstyle( QgsLegendStyle::Group ).setTextFormat( f ); rstyle( Qgis::LegendComponent::Group ).setTextFormat( f );
f = rstyle( QgsLegendStyle::Subgroup ).textFormat(); f = rstyle( Qgis::LegendComponent::Subgroup ).textFormat();
f.setLineHeight( f.size() * 0.352778 + spacing ); f.setLineHeight( f.size() * 0.352778 + spacing );
f.setLineHeightUnit( Qgis::RenderUnit::Millimeters ); f.setLineHeightUnit( Qgis::RenderUnit::Millimeters );
rstyle( QgsLegendStyle::Subgroup ).setTextFormat( f ); rstyle( Qgis::LegendComponent::Subgroup ).setTextFormat( f );
f = rstyle( QgsLegendStyle::SymbolLabel ).textFormat(); f = rstyle( Qgis::LegendComponent::SymbolLabel ).textFormat();
f.setLineHeight( f.size() * 0.352778 + spacing ); f.setLineHeight( f.size() * 0.352778 + spacing );
f.setLineHeightUnit( Qgis::RenderUnit::Millimeters ); f.setLineHeightUnit( Qgis::RenderUnit::Millimeters );
rstyle( QgsLegendStyle::SymbolLabel ).setTextFormat( f ); rstyle( Qgis::LegendComponent::SymbolLabel ).setTextFormat( f );
} }
mSettings.setDrawRasterStroke( itemElem.attribute( QStringLiteral( "rasterBorder" ), QStringLiteral( "1" ) ) != QLatin1String( "0" ) ); mSettings.setDrawRasterStroke( itemElem.attribute( QStringLiteral( "rasterBorder" ), QStringLiteral( "1" ) ) != QLatin1String( "0" ) );

View File

@ -231,17 +231,17 @@ class CORE_EXPORT QgsLayoutItemLegend : public QgsLayoutItem
/** /**
* Returns reference to modifiable legend style. * Returns reference to modifiable legend style.
*/ */
QgsLegendStyle &rstyle( QgsLegendStyle::Style s ); QgsLegendStyle &rstyle( Qgis::LegendComponent s );
/** /**
* Returns legend style. * Returns legend style.
*/ */
QgsLegendStyle style( QgsLegendStyle::Style s ) const; QgsLegendStyle style( Qgis::LegendComponent s ) const;
/** /**
* Sets the style of \a component to \a style for the legend. * Sets the style of \a component to \a style for the legend.
*/ */
void setStyle( QgsLegendStyle::Style component, const QgsLegendStyle &style ); void setStyle( Qgis::LegendComponent component, const QgsLegendStyle &style );
/** /**
* Returns the font settings for a legend \a component. * Returns the font settings for a legend \a component.
@ -249,7 +249,7 @@ class CORE_EXPORT QgsLayoutItemLegend : public QgsLayoutItem
* *
* \deprecated QGIS 3.40. Use QgsLegendStyle::textFormat() from style() instead. * \deprecated QGIS 3.40. Use QgsLegendStyle::textFormat() from style() instead.
*/ */
Q_DECL_DEPRECATED QFont styleFont( QgsLegendStyle::Style component ) const SIP_DEPRECATED; Q_DECL_DEPRECATED QFont styleFont( Qgis::LegendComponent component ) const SIP_DEPRECATED;
/** /**
* Sets the style \a font for a legend \a component. * Sets the style \a font for a legend \a component.
@ -257,17 +257,17 @@ class CORE_EXPORT QgsLayoutItemLegend : public QgsLayoutItem
* *
* \deprecated QGIS 3.40. Use QgsLegendStyle::setTextFormat() from style() instead. * \deprecated QGIS 3.40. Use QgsLegendStyle::setTextFormat() from style() instead.
*/ */
Q_DECL_DEPRECATED void setStyleFont( QgsLegendStyle::Style component, const QFont &font ) SIP_DEPRECATED; Q_DECL_DEPRECATED void setStyleFont( Qgis::LegendComponent component, const QFont &font ) SIP_DEPRECATED;
/** /**
* Set the \a margin for a legend \a component. * Set the \a margin for a legend \a component.
*/ */
void setStyleMargin( QgsLegendStyle::Style component, double margin ); void setStyleMargin( Qgis::LegendComponent component, double margin );
/** /**
* Set the \a margin for a particular \a side of a legend \a component. * Set the \a margin for a particular \a side of a legend \a component.
*/ */
void setStyleMargin( QgsLegendStyle::Style component, QgsLegendStyle::Side side, double margin ); void setStyleMargin( Qgis::LegendComponent component, QgsLegendStyle::Side side, double margin );
/** /**
* Returns the spacing in-between lines in layout units. * Returns the spacing in-between lines in layout units.

View File

@ -4331,6 +4331,24 @@ class CORE_EXPORT Qgis
Q_DECLARE_FLAGS( LayerTreeFilterFlags, LayerTreeFilterFlag ) Q_DECLARE_FLAGS( LayerTreeFilterFlags, LayerTreeFilterFlag )
Q_FLAG( LayerTreeFilterFlags ) Q_FLAG( LayerTreeFilterFlags )
/**
* Component of legends which can be styled.
*
* Prior to QGIS 3.42 this was available as QgsLegendStyle::Style
*
* \since QGIS 3.42
*/
enum class LegendComponent SIP_MONKEYPATCH_SCOPEENUM_UNNEST( QgsLegendStyle, Style ) : int
{
Undefined, //!< Should not happen, only if corrupted project file
Hidden, //!< Special style, item is hidden including margins around
Title, //!< Legend title
Group, //!< Legend group title
Subgroup, //!< Legend subgroup title
Symbol, //!< Symbol icon (excluding label)
SymbolLabel, //!< Symbol label (excluding icon)
};
Q_ENUM( LegendComponent )
/** /**
* Legend JSON export flags. * Legend JSON export flags.

View File

@ -120,7 +120,7 @@ QJsonObject QgsLegendRenderer::exportLegendToJson( const QgsRenderContext &conte
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node ); QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
QString text; QString text;
if ( nodeLegendStyle( nodeLayer ) != QgsLegendStyle::Hidden ) if ( nodeLegendStyle( nodeLayer ) != Qgis::LegendComponent::Hidden )
{ {
const QModelIndex idx = mLegendModel->node2index( nodeLayer ); const QModelIndex idx = mLegendModel->node2index( nodeLayer );
text = mLegendModel->data( idx, Qt::DisplayRole ).toString(); text = mLegendModel->data( idx, Qt::DisplayRole ).toString();
@ -243,7 +243,7 @@ QSizeF QgsLegendRenderer::paintAndDetermineSize( QgsRenderContext &context )
QSizeF titleSize = drawTitle( context, 0 ); QSizeF titleSize = drawTitle( context, 0 );
//add title margin to size of title text //add title margin to size of title text
titleSize.rwidth() += mSettings.boxSpace() * 2.0; titleSize.rwidth() += mSettings.boxSpace() * 2.0;
double columnTop = mSettings.boxSpace() + titleSize.height() + mSettings.style( QgsLegendStyle::Title ).margin( QgsLegendStyle::Bottom ); double columnTop = mSettings.boxSpace() + titleSize.height() + mSettings.style( Qgis::LegendComponent::Title ).margin( QgsLegendStyle::Bottom );
noPainter.reset(); noPainter.reset();
@ -347,11 +347,11 @@ QList<QgsLegendRenderer::LegendComponentGroup> QgsLegendRenderer::createComponen
double newIndent = indent; double newIndent = indent;
if ( style == QLatin1String( "subgroup" ) ) if ( style == QLatin1String( "subgroup" ) )
{ {
newIndent += mSettings.style( QgsLegendStyle::Subgroup ).indent( ); newIndent += mSettings.style( Qgis::LegendComponent::Subgroup ).indent( );
} }
else else
{ {
newIndent += mSettings.style( QgsLegendStyle::Group ).indent( ); newIndent += mSettings.style( Qgis::LegendComponent::Group ).indent( );
} }
// Group subitems // Group subitems
@ -359,7 +359,7 @@ QList<QgsLegendRenderer::LegendComponentGroup> QgsLegendRenderer::createComponen
bool hasSubItems = !subgroups.empty(); bool hasSubItems = !subgroups.empty();
if ( nodeLegendStyle( nodeGroup ) != QgsLegendStyle::Hidden ) if ( nodeLegendStyle( nodeGroup ) != Qgis::LegendComponent::Hidden )
{ {
LegendComponent component; LegendComponent component;
component.item = node; component.item = node;
@ -399,7 +399,7 @@ QList<QgsLegendRenderer::LegendComponentGroup> QgsLegendRenderer::createComponen
else if ( QgsLayerTree::isLayer( node ) ) else if ( QgsLayerTree::isLayer( node ) )
{ {
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node ); QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
QgsLegendStyle::Style layerStyle = nodeLegendStyle( nodeLayer ); Qgis::LegendComponent layerStyle = nodeLegendStyle( nodeLayer );
bool allowColumnSplit = false; bool allowColumnSplit = false;
switch ( nodeLayer->legendSplitBehavior() ) switch ( nodeLayer->legendSplitBehavior() )
{ {
@ -417,7 +417,7 @@ QList<QgsLegendRenderer::LegendComponentGroup> QgsLegendRenderer::createComponen
LegendComponentGroup group; LegendComponentGroup group;
group.placeColumnBreakBeforeGroup = nodeLayer->customProperty( QStringLiteral( "legend/column-break" ) ).toInt(); group.placeColumnBreakBeforeGroup = nodeLayer->customProperty( QStringLiteral( "legend/column-break" ) ).toInt();
if ( layerStyle != QgsLegendStyle::Hidden ) if ( layerStyle != Qgis::LegendComponent::Hidden )
{ {
LegendComponent component; LegendComponent component;
component.item = node; component.item = node;
@ -443,8 +443,8 @@ QList<QgsLegendRenderer::LegendComponentGroup> QgsLegendRenderer::createComponen
double symbolIndent = indent; double symbolIndent = indent;
switch ( layerStyle ) switch ( layerStyle )
{ {
case QgsLegendStyle::Subgroup: case Qgis::LegendComponent::Subgroup:
case QgsLegendStyle::Group: case Qgis::LegendComponent::Group:
symbolIndent += mSettings.style( layerStyle ).indent( ); symbolIndent += mSettings.style( layerStyle ).indent( );
break; break;
default: default:
@ -479,7 +479,7 @@ QList<QgsLegendRenderer::LegendComponentGroup> QgsLegendRenderer::createComponen
if ( !group.components.isEmpty() ) if ( !group.components.isEmpty() )
{ {
// TODO: for now we keep Symbol and SymbolLabel Top margin in sync // TODO: for now we keep Symbol and SymbolLabel Top margin in sync
group.size.rheight() += mSettings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Top ); group.size.rheight() += mSettings.style( Qgis::LegendComponent::Symbol ).margin( QgsLegendStyle::Top );
} }
group.size.rheight() += symbolComponent.size.height(); group.size.rheight() += symbolComponent.size.height();
symbolComponent.indent = symbolIndent; symbolComponent.indent = symbolIndent;
@ -744,8 +744,8 @@ int QgsLegendRenderer::setColumns( QList<LegendComponentGroup> &componentGroups
if ( QgsLayerTreeModelLegendNode *legendNode = qobject_cast<QgsLayerTreeModelLegendNode *>( group.components.at( j ).item ) ) if ( QgsLayerTreeModelLegendNode *legendNode = qobject_cast<QgsLayerTreeModelLegendNode *>( group.components.at( j ).item ) )
{ {
QString key = QStringLiteral( "%1-%2" ).arg( reinterpret_cast< qulonglong >( legendNode->layerNode() ) ).arg( group.column ); QString key = QStringLiteral( "%1-%2" ).arg( reinterpret_cast< qulonglong >( legendNode->layerNode() ) ).arg( group.column );
double space = mSettings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Right ) + double space = mSettings.style( Qgis::LegendComponent::Symbol ).margin( QgsLegendStyle::Right ) +
mSettings.style( QgsLegendStyle::SymbolLabel ).margin( QgsLegendStyle::Left ); mSettings.style( Qgis::LegendComponent::SymbolLabel ).margin( QgsLegendStyle::Left );
group.components[j].labelXOffset = maxSymbolWidth[key] + space; group.components[j].labelXOffset = maxSymbolWidth[key] + space;
group.components[j].maxSiblingSymbolWidth = maxSymbolWidth[key]; group.components[j].maxSiblingSymbolWidth = maxSymbolWidth[key];
group.components[j].size.rwidth() = maxSymbolWidth[key] + space + group.components.at( j ).labelSize.width(); group.components[j].size.rwidth() = maxSymbolWidth[key] + space + group.components.at( j ).labelSize.width();
@ -770,7 +770,7 @@ QSizeF QgsLegendRenderer::drawTitle( QgsRenderContext &context, double top, Qt::
double textBoxLeft; double textBoxLeft;
widthAndOffsetForTitleText( halignment, legendWidth, textBoxWidth, textBoxLeft ); widthAndOffsetForTitleText( halignment, legendWidth, textBoxWidth, textBoxLeft );
const QgsTextFormat titleFormat = mSettings.style( QgsLegendStyle::Title ).textFormat(); const QgsTextFormat titleFormat = mSettings.style( Qgis::LegendComponent::Title ).textFormat();
const double dotsPerMM = context.scaleFactor(); const double dotsPerMM = context.scaleFactor();
double overallTextHeight = 0; double overallTextHeight = 0;
@ -818,7 +818,7 @@ double QgsLegendRenderer::spaceAboveGroup( const LegendComponentGroup &group )
else if ( qobject_cast<QgsLayerTreeModelLegendNode *>( component.item ) ) else if ( qobject_cast<QgsLayerTreeModelLegendNode *>( component.item ) )
{ {
// TODO: use Symbol or SymbolLabel Top margin // TODO: use Symbol or SymbolLabel Top margin
return mSettings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Top ); return mSettings.style( Qgis::LegendComponent::Symbol ).margin( QgsLegendStyle::Top );
} }
return 0; return 0;
@ -833,8 +833,8 @@ QSizeF QgsLegendRenderer::drawGroup( const LegendComponentGroup &group, QgsRende
{ {
if ( QgsLayerTreeGroup *groupItem = qobject_cast<QgsLayerTreeGroup *>( component.item ) ) if ( QgsLayerTreeGroup *groupItem = qobject_cast<QgsLayerTreeGroup *>( component.item ) )
{ {
QgsLegendStyle::Style s = nodeLegendStyle( groupItem ); Qgis::LegendComponent s = nodeLegendStyle( groupItem );
if ( s != QgsLegendStyle::Hidden ) if ( s != Qgis::LegendComponent::Hidden )
{ {
if ( !first ) if ( !first )
{ {
@ -843,21 +843,21 @@ QSizeF QgsLegendRenderer::drawGroup( const LegendComponentGroup &group, QgsRende
QSizeF groupSize; QSizeF groupSize;
ColumnContext columnContextForItem = columnContext; ColumnContext columnContextForItem = columnContext;
double indentWidth = component.indent; double indentWidth = component.indent;
if ( s == QgsLegendStyle::Subgroup ) if ( s == Qgis::LegendComponent::Subgroup )
{ {
// Remove indent - the subgroup items should be indented, not the subgroup title // Remove indent - the subgroup items should be indented, not the subgroup title
indentWidth -= mSettings.style( QgsLegendStyle::Subgroup ).indent( ); indentWidth -= mSettings.style( Qgis::LegendComponent::Subgroup ).indent( );
} }
else else
{ {
// Remove indent - the group items should be indented, not the group title // Remove indent - the group items should be indented, not the group title
indentWidth -= mSettings.style( QgsLegendStyle::Group ).indent( ); indentWidth -= mSettings.style( Qgis::LegendComponent::Group ).indent( );
} }
if ( mSettings.style( QgsLegendStyle::SymbolLabel ).alignment() == Qt::AlignLeft ) if ( mSettings.style( Qgis::LegendComponent::SymbolLabel ).alignment() == Qt::AlignLeft )
{ {
columnContextForItem.left += indentWidth; columnContextForItem.left += indentWidth;
} }
if ( mSettings.style( QgsLegendStyle::SymbolLabel ).alignment() == Qt::AlignRight ) if ( mSettings.style( Qgis::LegendComponent::SymbolLabel ).alignment() == Qt::AlignRight )
{ {
columnContextForItem.right -= indentWidth; columnContextForItem.right -= indentWidth;
} }
@ -867,8 +867,8 @@ QSizeF QgsLegendRenderer::drawGroup( const LegendComponentGroup &group, QgsRende
} }
else if ( QgsLayerTreeLayer *layerItem = qobject_cast<QgsLayerTreeLayer *>( component.item ) ) else if ( QgsLayerTreeLayer *layerItem = qobject_cast<QgsLayerTreeLayer *>( component.item ) )
{ {
QgsLegendStyle::Style s = nodeLegendStyle( layerItem ); Qgis::LegendComponent s = nodeLegendStyle( layerItem );
if ( s != QgsLegendStyle::Hidden ) if ( s != Qgis::LegendComponent::Hidden )
{ {
if ( !first ) if ( !first )
{ {
@ -887,17 +887,17 @@ QSizeF QgsLegendRenderer::drawGroup( const LegendComponentGroup &group, QgsRende
{ {
if ( !first ) if ( !first )
{ {
currentY += mSettings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Top ); currentY += mSettings.style( Qgis::LegendComponent::Symbol ).margin( QgsLegendStyle::Top );
} }
ColumnContext columnContextForItem = columnContext; ColumnContext columnContextForItem = columnContext;
double indentWidth = 0; double indentWidth = 0;
indentWidth = component.indent; indentWidth = component.indent;
if ( mSettings.style( QgsLegendStyle::SymbolLabel ).alignment() == Qt::AlignLeft ) if ( mSettings.style( Qgis::LegendComponent::SymbolLabel ).alignment() == Qt::AlignLeft )
{ {
columnContextForItem.left += indentWidth; columnContextForItem.left += indentWidth;
} }
if ( mSettings.style( QgsLegendStyle::SymbolLabel ).alignment() == Qt::AlignRight ) if ( mSettings.style( Qgis::LegendComponent::SymbolLabel ).alignment() == Qt::AlignRight )
{ {
columnContextForItem.right -= indentWidth; columnContextForItem.right -= indentWidth;
} }
@ -940,11 +940,11 @@ QgsLegendRenderer::LegendComponent QgsLegendRenderer::drawSymbolItem( QgsLayerTr
{ {
case Qt::AlignLeft: case Qt::AlignLeft:
default: default:
ctx.columnLeft += mSettings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Left ); ctx.columnLeft += mSettings.style( Qgis::LegendComponent::Symbol ).margin( QgsLegendStyle::Left );
break; break;
case Qt::AlignRight: case Qt::AlignRight:
ctx.columnRight -= mSettings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Left ); ctx.columnRight -= mSettings.style( Qgis::LegendComponent::Symbol ).margin( QgsLegendStyle::Left );
break; break;
} }
@ -977,9 +977,9 @@ QgsLegendRenderer::LegendComponent QgsLegendRenderer::drawSymbolItem( QgsLayerTr
// ideally we could (should?) expose all these margins as settings, and then adapt the below to respect the current symbol/text alignment // ideally we could (should?) expose all these margins as settings, and then adapt the below to respect the current symbol/text alignment
// and consider the correct margin sides... // and consider the correct margin sides...
double width = std::max( static_cast< double >( im.symbolSize.width() ), maxSiblingSymbolWidth ) double width = std::max( static_cast< double >( im.symbolSize.width() ), maxSiblingSymbolWidth )
+ mSettings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Left ) + mSettings.style( Qgis::LegendComponent::Symbol ).margin( QgsLegendStyle::Left )
+ mSettings.style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Right ) + mSettings.style( Qgis::LegendComponent::Symbol ).margin( QgsLegendStyle::Right )
+ mSettings.style( QgsLegendStyle::SymbolLabel ).margin( QgsLegendStyle::Left ) + mSettings.style( Qgis::LegendComponent::SymbolLabel ).margin( QgsLegendStyle::Left )
+ im.labelSize.width(); + im.labelSize.width();
double height = std::max( im.symbolSize.height(), im.labelSize.height() ); double height = std::max( im.symbolSize.height(), im.labelSize.height() );
@ -1082,30 +1082,30 @@ QSizeF QgsLegendRenderer::drawGroupTitle( QgsLayerTreeGroup *nodeGroup, QgsRende
return size; return size;
} }
QgsLegendStyle::Style QgsLegendRenderer::nodeLegendStyle( QgsLayerTreeNode *node, QgsLayerTreeModel *model ) Qgis::LegendComponent QgsLegendRenderer::nodeLegendStyle( QgsLayerTreeNode *node, QgsLayerTreeModel *model )
{ {
QString style = node->customProperty( QStringLiteral( "legend/title-style" ) ).toString(); QString style = node->customProperty( QStringLiteral( "legend/title-style" ) ).toString();
if ( style == QLatin1String( "hidden" ) ) if ( style == QLatin1String( "hidden" ) )
return QgsLegendStyle::Hidden; return Qgis::LegendComponent::Hidden;
else if ( style == QLatin1String( "group" ) ) else if ( style == QLatin1String( "group" ) )
return QgsLegendStyle::Group; return Qgis::LegendComponent::Group;
else if ( style == QLatin1String( "subgroup" ) ) else if ( style == QLatin1String( "subgroup" ) )
return QgsLegendStyle::Subgroup; return Qgis::LegendComponent::Subgroup;
// use a default otherwise // use a default otherwise
if ( QgsLayerTree::isGroup( node ) ) if ( QgsLayerTree::isGroup( node ) )
return QgsLegendStyle::Group; return Qgis::LegendComponent::Group;
else if ( QgsLayerTree::isLayer( node ) ) else if ( QgsLayerTree::isLayer( node ) )
{ {
if ( model->legendNodeEmbeddedInParent( QgsLayerTree::toLayer( node ) ) ) if ( model->legendNodeEmbeddedInParent( QgsLayerTree::toLayer( node ) ) )
return QgsLegendStyle::Hidden; return Qgis::LegendComponent::Hidden;
return QgsLegendStyle::Subgroup; return Qgis::LegendComponent::Subgroup;
} }
return QgsLegendStyle::Undefined; // should not happen, only if corrupted project file return Qgis::LegendComponent::Undefined; // should not happen, only if corrupted project file
} }
QgsLegendStyle::Style QgsLegendRenderer::nodeLegendStyle( QgsLayerTreeNode *node ) Qgis::LegendComponent QgsLegendRenderer::nodeLegendStyle( QgsLayerTreeNode *node )
{ {
return nodeLegendStyle( node, mLegendModel ); return nodeLegendStyle( node, mLegendModel );
} }
@ -1115,18 +1115,18 @@ QgsLayerTreeFilterProxyModel *QgsLegendRenderer::proxyModel()
return mProxyModel.get(); return mProxyModel.get();
} }
void QgsLegendRenderer::setNodeLegendStyle( QgsLayerTreeNode *node, QgsLegendStyle::Style style ) void QgsLegendRenderer::setNodeLegendStyle( QgsLayerTreeNode *node, Qgis::LegendComponent style )
{ {
QString str; QString str;
switch ( style ) switch ( style )
{ {
case QgsLegendStyle::Hidden: case Qgis::LegendComponent::Hidden:
str = QStringLiteral( "hidden" ); str = QStringLiteral( "hidden" );
break; break;
case QgsLegendStyle::Group: case Qgis::LegendComponent::Group:
str = QStringLiteral( "group" ); str = QStringLiteral( "group" );
break; break;
case QgsLegendStyle::Subgroup: case Qgis::LegendComponent::Subgroup:
str = QStringLiteral( "subgroup" ); str = QStringLiteral( "subgroup" );
break; break;
default: default:

View File

@ -125,14 +125,14 @@ class CORE_EXPORT QgsLegendRenderer
* *
* \see nodeLegendStyle() * \see nodeLegendStyle()
*/ */
static void setNodeLegendStyle( QgsLayerTreeNode *node, QgsLegendStyle::Style style ); static void setNodeLegendStyle( QgsLayerTreeNode *node, Qgis::LegendComponent style );
/** /**
* Returns the style for the given \a node, within the specified \a model. * Returns the style for the given \a node, within the specified \a model.
* *
* \see setNodeLegendStyle() * \see setNodeLegendStyle()
*/ */
static QgsLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode *node, QgsLayerTreeModel *model ); static Qgis::LegendComponent nodeLegendStyle( QgsLayerTreeNode *node, QgsLayerTreeModel *model );
private: private:
@ -311,7 +311,7 @@ class CORE_EXPORT QgsLegendRenderer
/** /**
* Returns the style of the given \a node. * Returns the style of the given \a node.
*/ */
QgsLegendStyle::Style nodeLegendStyle( QgsLayerTreeNode *node ); Qgis::LegendComponent nodeLegendStyle( QgsLayerTreeNode *node );
QgsLayerTreeModel *mLegendModel = nullptr; QgsLayerTreeModel *mLegendModel = nullptr;
std::unique_ptr< QgsLayerTreeFilterProxyModel >mProxyModel; std::unique_ptr< QgsLayerTreeFilterProxyModel >mProxyModel;

View File

@ -25,75 +25,75 @@ QgsLegendSettings::QgsLegendSettings()
, mWmsLegendSize( 50, 25 ) , mWmsLegendSize( 50, 25 )
, mRasterStrokeColor( Qt::black ) , mRasterStrokeColor( Qt::black )
{ {
rstyle( QgsLegendStyle::Title ).setMargin( QgsLegendStyle::Bottom, 3.5 ); rstyle( Qgis::LegendComponent::Title ).setMargin( QgsLegendStyle::Bottom, 3.5 );
rstyle( QgsLegendStyle::Group ).setMargin( QgsLegendStyle::Top, 3 ); rstyle( Qgis::LegendComponent::Group ).setMargin( QgsLegendStyle::Top, 3 );
rstyle( QgsLegendStyle::Subgroup ).setMargin( QgsLegendStyle::Top, 3 ); rstyle( Qgis::LegendComponent::Subgroup ).setMargin( QgsLegendStyle::Top, 3 );
rstyle( QgsLegendStyle::Symbol ).setMargin( QgsLegendStyle::Top, 2.5 ); rstyle( Qgis::LegendComponent::Symbol ).setMargin( QgsLegendStyle::Top, 2.5 );
rstyle( QgsLegendStyle::SymbolLabel ).setMargin( QgsLegendStyle::Top, 2 ); rstyle( Qgis::LegendComponent::SymbolLabel ).setMargin( QgsLegendStyle::Top, 2 );
rstyle( QgsLegendStyle::SymbolLabel ).setMargin( QgsLegendStyle::Left, 2 ); rstyle( Qgis::LegendComponent::SymbolLabel ).setMargin( QgsLegendStyle::Left, 2 );
rstyle( QgsLegendStyle::Group ).setIndent( 0.0 ); rstyle( Qgis::LegendComponent::Group ).setIndent( 0.0 );
rstyle( QgsLegendStyle::Subgroup ).setIndent( 0.0 ); rstyle( Qgis::LegendComponent::Subgroup ).setIndent( 0.0 );
QgsTextFormat f = rstyle( QgsLegendStyle::Title ).textFormat(); QgsTextFormat f = rstyle( Qgis::LegendComponent::Title ).textFormat();
f.setSize( 16.0 ); f.setSize( 16.0 );
f.setSizeUnit( Qgis::RenderUnit::Points ); f.setSizeUnit( Qgis::RenderUnit::Points );
// these default line heights are not ideal, but needed to maintain api // these default line heights are not ideal, but needed to maintain api
f.setLineHeight( 1.1 ); f.setLineHeight( 1.1 );
f.setLineHeightUnit( Qgis::RenderUnit::Percentage ); f.setLineHeightUnit( Qgis::RenderUnit::Percentage );
rstyle( QgsLegendStyle::Title ).setTextFormat( f ); rstyle( Qgis::LegendComponent::Title ).setTextFormat( f );
f = rstyle( QgsLegendStyle::Group ).textFormat(); f = rstyle( Qgis::LegendComponent::Group ).textFormat();
f.setSize( 14.0 ); f.setSize( 14.0 );
f.setSizeUnit( Qgis::RenderUnit::Points ); f.setSizeUnit( Qgis::RenderUnit::Points );
f.setLineHeight( 1.1 ); f.setLineHeight( 1.1 );
f.setLineHeightUnit( Qgis::RenderUnit::Percentage ); f.setLineHeightUnit( Qgis::RenderUnit::Percentage );
rstyle( QgsLegendStyle::Group ).setTextFormat( f ); rstyle( Qgis::LegendComponent::Group ).setTextFormat( f );
f = rstyle( QgsLegendStyle::Subgroup ).textFormat(); f = rstyle( Qgis::LegendComponent::Subgroup ).textFormat();
f.setSize( 12.0 ); f.setSize( 12.0 );
f.setSizeUnit( Qgis::RenderUnit::Points ); f.setSizeUnit( Qgis::RenderUnit::Points );
f.setLineHeight( 1.1 ); f.setLineHeight( 1.1 );
f.setLineHeightUnit( Qgis::RenderUnit::Percentage ); f.setLineHeightUnit( Qgis::RenderUnit::Percentage );
rstyle( QgsLegendStyle::Subgroup ).setTextFormat( f ); rstyle( Qgis::LegendComponent::Subgroup ).setTextFormat( f );
f = rstyle( QgsLegendStyle::SymbolLabel ).textFormat(); f = rstyle( Qgis::LegendComponent::SymbolLabel ).textFormat();
f.setSize( 12.0 ); f.setSize( 12.0 );
f.setSizeUnit( Qgis::RenderUnit::Points ); f.setSizeUnit( Qgis::RenderUnit::Points );
f.setLineHeight( 1.1 ); f.setLineHeight( 1.1 );
f.setLineHeightUnit( Qgis::RenderUnit::Percentage ); f.setLineHeightUnit( Qgis::RenderUnit::Percentage );
rstyle( QgsLegendStyle::SymbolLabel ).setTextFormat( f ); rstyle( Qgis::LegendComponent::SymbolLabel ).setTextFormat( f );
} }
void QgsLegendSettings::updateDataDefinedProperties( QgsRenderContext &context ) void QgsLegendSettings::updateDataDefinedProperties( QgsRenderContext &context )
{ {
rstyle( QgsLegendStyle::Title ).updateDataDefinedProperties( context ); rstyle( Qgis::LegendComponent::Title ).updateDataDefinedProperties( context );
rstyle( QgsLegendStyle::Group ).updateDataDefinedProperties( context ); rstyle( Qgis::LegendComponent::Group ).updateDataDefinedProperties( context );
rstyle( QgsLegendStyle::Subgroup ).updateDataDefinedProperties( context ); rstyle( Qgis::LegendComponent::Subgroup ).updateDataDefinedProperties( context );
rstyle( QgsLegendStyle::SymbolLabel ).updateDataDefinedProperties( context ); rstyle( Qgis::LegendComponent::SymbolLabel ).updateDataDefinedProperties( context );
} }
QColor QgsLegendSettings::fontColor() const QColor QgsLegendSettings::fontColor() const
{ {
return style( QgsLegendStyle::SymbolLabel ).textFormat().color(); return style( Qgis::LegendComponent::SymbolLabel ).textFormat().color();
} }
void QgsLegendSettings::setFontColor( const QColor &c ) void QgsLegendSettings::setFontColor( const QColor &c )
{ {
rstyle( QgsLegendStyle::Title ).textFormat().setColor( c ); rstyle( Qgis::LegendComponent::Title ).textFormat().setColor( c );
rstyle( QgsLegendStyle::Group ).textFormat().setColor( c ); rstyle( Qgis::LegendComponent::Group ).textFormat().setColor( c );
rstyle( QgsLegendStyle::Subgroup ).textFormat().setColor( c ); rstyle( Qgis::LegendComponent::Subgroup ).textFormat().setColor( c );
rstyle( QgsLegendStyle::SymbolLabel ).textFormat().setColor( c ); rstyle( Qgis::LegendComponent::SymbolLabel ).textFormat().setColor( c );
} }
QColor QgsLegendSettings::layerFontColor() const QColor QgsLegendSettings::layerFontColor() const
{ {
return style( QgsLegendStyle::Subgroup ).textFormat().color(); return style( Qgis::LegendComponent::Subgroup ).textFormat().color();
} }
void QgsLegendSettings::setLayerFontColor( const QColor &fontColor ) void QgsLegendSettings::setLayerFontColor( const QColor &fontColor )
{ {
rstyle( QgsLegendStyle::Group ).textFormat().setColor( fontColor ); rstyle( Qgis::LegendComponent::Group ).textFormat().setColor( fontColor );
rstyle( QgsLegendStyle::Subgroup ).textFormat().setColor( fontColor ); rstyle( Qgis::LegendComponent::Subgroup ).textFormat().setColor( fontColor );
} }
void QgsLegendSettings::setLineSpacing( double s ) SIP_DEPRECATED void QgsLegendSettings::setLineSpacing( double s ) SIP_DEPRECATED
@ -101,26 +101,26 @@ void QgsLegendSettings::setLineSpacing( double s ) SIP_DEPRECATED
// line spacing *was* a fixed amount (in mm) added between each line of text. // line spacing *was* a fixed amount (in mm) added between each line of text.
mLineSpacing = s; mLineSpacing = s;
QgsTextFormat f = rstyle( QgsLegendStyle::Title ).textFormat(); QgsTextFormat f = rstyle( Qgis::LegendComponent::Title ).textFormat();
// assume font sizes in points, since that was what we always had from before this method was deprecated // assume font sizes in points, since that was what we always had from before this method was deprecated
f.setLineHeight( f.size() * 0.352778 + s ); f.setLineHeight( f.size() * 0.352778 + s );
f.setLineHeightUnit( Qgis::RenderUnit::Millimeters ); f.setLineHeightUnit( Qgis::RenderUnit::Millimeters );
rstyle( QgsLegendStyle::Title ).setTextFormat( f ); rstyle( Qgis::LegendComponent::Title ).setTextFormat( f );
f = rstyle( QgsLegendStyle::Group ).textFormat(); f = rstyle( Qgis::LegendComponent::Group ).textFormat();
f.setLineHeight( f.size() * 0.352778 + s ); f.setLineHeight( f.size() * 0.352778 + s );
f.setLineHeightUnit( Qgis::RenderUnit::Millimeters ); f.setLineHeightUnit( Qgis::RenderUnit::Millimeters );
rstyle( QgsLegendStyle::Group ).setTextFormat( f ); rstyle( Qgis::LegendComponent::Group ).setTextFormat( f );
f = rstyle( QgsLegendStyle::Subgroup ).textFormat(); f = rstyle( Qgis::LegendComponent::Subgroup ).textFormat();
f.setLineHeight( f.size() * 0.352778 + s ); f.setLineHeight( f.size() * 0.352778 + s );
f.setLineHeightUnit( Qgis::RenderUnit::Millimeters ); f.setLineHeightUnit( Qgis::RenderUnit::Millimeters );
rstyle( QgsLegendStyle::Subgroup ).setTextFormat( f ); rstyle( Qgis::LegendComponent::Subgroup ).setTextFormat( f );
f = rstyle( QgsLegendStyle::SymbolLabel ).textFormat(); f = rstyle( Qgis::LegendComponent::SymbolLabel ).textFormat();
f.setLineHeight( f.size() * 0.352778 + s ); f.setLineHeight( f.size() * 0.352778 + s );
f.setLineHeightUnit( Qgis::RenderUnit::Millimeters ); f.setLineHeightUnit( Qgis::RenderUnit::Millimeters );
rstyle( QgsLegendStyle::SymbolLabel ).setTextFormat( f ); rstyle( Qgis::LegendComponent::SymbolLabel ).setTextFormat( f );
} }
double QgsLegendSettings::mmPerMapUnit() const double QgsLegendSettings::mmPerMapUnit() const

View File

@ -78,21 +78,21 @@ class CORE_EXPORT QgsLegendSettings
* *
* \note Not available in Python bindings. * \note Not available in Python bindings.
*/ */
SIP_SKIP QgsLegendStyle &rstyle( QgsLegendStyle::Style s ) SIP_SKIP { return mStyleMap[s]; } SIP_SKIP QgsLegendStyle &rstyle( Qgis::LegendComponent s ) SIP_SKIP { return mStyleMap[s]; }
/** /**
* Returns the style for a legend component. * Returns the style for a legend component.
* *
* \see setStyle() * \see setStyle()
*/ */
QgsLegendStyle style( QgsLegendStyle::Style s ) const { return mStyleMap.value( s ); } QgsLegendStyle style( Qgis::LegendComponent s ) const { return mStyleMap.value( s ); }
/** /**
* Sets the \a style for a legend component. * Sets the \a style for a legend component.
* *
* \see style() * \see style()
*/ */
void setStyle( QgsLegendStyle::Style s, const QgsLegendStyle &style ) { mStyleMap[s] = style; } void setStyle( Qgis::LegendComponent s, const QgsLegendStyle &style ) { mStyleMap[s] = style; }
/** /**
* Returns the legend box space (in millimeters), which is the empty margin around the inside of the legend's * Returns the legend box space (in millimeters), which is the empty margin around the inside of the legend's
@ -579,7 +579,7 @@ class CORE_EXPORT QgsLegendSettings
QColor mRasterStrokeColor; QColor mRasterStrokeColor;
double mRasterStrokeWidth = 0.0; double mRasterStrokeWidth = 0.0;
QMap<QgsLegendStyle::Style, QgsLegendStyle> mStyleMap; QMap<Qgis::LegendComponent, QgsLegendStyle> mStyleMap;
//! Conversion ratio between millimeters and map units - for symbols with size given in map units //! Conversion ratio between millimeters and map units - for symbols with size given in map units
double mMmPerMapUnit = 1; double mMmPerMapUnit = 1;

View File

@ -118,62 +118,62 @@ void QgsLegendStyle::updateDataDefinedProperties( QgsRenderContext &context )
} }
QString QgsLegendStyle::styleName( Style s ) QString QgsLegendStyle::styleName( Qgis::LegendComponent s )
{ {
switch ( s ) switch ( s )
{ {
case Undefined: case Qgis::LegendComponent::Undefined:
return QString(); return QString();
case Hidden: case Qgis::LegendComponent::Hidden:
return QStringLiteral( "hidden" ); return QStringLiteral( "hidden" );
case Title: case Qgis::LegendComponent::Title:
return QStringLiteral( "title" ); return QStringLiteral( "title" );
case Group: case Qgis::LegendComponent::Group:
return QStringLiteral( "group" ); return QStringLiteral( "group" );
case Subgroup: case Qgis::LegendComponent::Subgroup:
return QStringLiteral( "subgroup" ); return QStringLiteral( "subgroup" );
case Symbol: case Qgis::LegendComponent::Symbol:
return QStringLiteral( "symbol" ); return QStringLiteral( "symbol" );
case SymbolLabel: case Qgis::LegendComponent::SymbolLabel:
return QStringLiteral( "symbolLabel" ); return QStringLiteral( "symbolLabel" );
} }
return QString(); return QString();
} }
QgsLegendStyle::Style QgsLegendStyle::styleFromName( const QString &styleName ) Qgis::LegendComponent QgsLegendStyle::styleFromName( const QString &styleName )
{ {
if ( styleName == QLatin1String( "hidden" ) ) if ( styleName == QLatin1String( "hidden" ) )
return Hidden; return Qgis::LegendComponent::Hidden;
else if ( styleName == QLatin1String( "title" ) ) else if ( styleName == QLatin1String( "title" ) )
return Title; return Qgis::LegendComponent::Title;
else if ( styleName == QLatin1String( "group" ) ) else if ( styleName == QLatin1String( "group" ) )
return Group; return Qgis::LegendComponent::Group;
else if ( styleName == QLatin1String( "subgroup" ) ) else if ( styleName == QLatin1String( "subgroup" ) )
return Subgroup; return Qgis::LegendComponent::Subgroup;
else if ( styleName == QLatin1String( "symbol" ) ) else if ( styleName == QLatin1String( "symbol" ) )
return Symbol; return Qgis::LegendComponent::Symbol;
else if ( styleName == QLatin1String( "symbolLabel" ) ) else if ( styleName == QLatin1String( "symbolLabel" ) )
return SymbolLabel; return Qgis::LegendComponent::SymbolLabel;
return Undefined; return Qgis::LegendComponent::Undefined;
} }
QString QgsLegendStyle::styleLabel( Style s ) QString QgsLegendStyle::styleLabel( Qgis::LegendComponent s )
{ {
switch ( s ) switch ( s )
{ {
case Undefined: case Qgis::LegendComponent::Undefined:
return QObject::tr( "Undefined" ); return QObject::tr( "Undefined" );
case Hidden: case Qgis::LegendComponent::Hidden:
return QObject::tr( "Hidden" ); return QObject::tr( "Hidden" );
case Title: case Qgis::LegendComponent::Title:
return QObject::tr( "Title" ); return QObject::tr( "Title" );
case Group: case Qgis::LegendComponent::Group:
return QObject::tr( "Group" ); return QObject::tr( "Group" );
case Subgroup: case Qgis::LegendComponent::Subgroup:
return QObject::tr( "Subgroup" ); return QObject::tr( "Subgroup" );
case Symbol: case Qgis::LegendComponent::Symbol:
return QObject::tr( "Symbol" ); return QObject::tr( "Symbol" );
case SymbolLabel: case Qgis::LegendComponent::SymbolLabel:
return QObject::tr( "Symbol label" ); return QObject::tr( "Symbol label" );
} }
return QString(); return QString();

View File

@ -37,18 +37,6 @@ class CORE_EXPORT QgsLegendStyle
{ {
public: public:
//! Component of legends which can be styled
enum Style
{
Undefined, //!< Should not happen, only if corrupted project file
Hidden, //!< Special style, item is hidden including margins around
Title, //!< Legend title
Group, //!< Legend group title
Subgroup, //!< Legend subgroup title
Symbol, //!< Symbol icon (excluding label)
SymbolLabel, //!< Symbol label (excluding icon)
};
// TODO QGIS 4.0 - use Qt enum instead // TODO QGIS 4.0 - use Qt enum instead
//! Margin sides //! Margin sides
@ -181,19 +169,19 @@ class CORE_EXPORT QgsLegendStyle
* \see styleFromName() * \see styleFromName()
* \see styleLabel() * \see styleLabel()
*/ */
static QString styleName( Style s ); static QString styleName( Qgis::LegendComponent s );
/** /**
* Returns the style from name string. * Returns the style from name string.
* \see styleName() * \see styleName()
*/ */
static Style styleFromName( const QString &styleName ); static Qgis::LegendComponent styleFromName( const QString &styleName );
/** /**
* Returns a translated string representing a style component, for use in UI. * Returns a translated string representing a style component, for use in UI.
* \see styleName() * \see styleName()
*/ */
static QString styleLabel( Style s ); static QString styleLabel( Qgis::LegendComponent s );
private: private:
QgsTextFormat mTextFormat; QgsTextFormat mTextFormat;

View File

@ -251,9 +251,9 @@ void QgsLayoutGuiUtils::registerGuiForKnownItemTypes( QgsMapCanvas *mapCanvas )
{ {
// for right-to-left locales, use an appropriate default layout // for right-to-left locales, use an appropriate default layout
legend->setSymbolAlignment( Qt::AlignRight ); legend->setSymbolAlignment( Qt::AlignRight );
legend->rstyle( QgsLegendStyle::Group ).setAlignment( Qt::AlignRight ); legend->rstyle( Qgis::LegendComponent::Group ).setAlignment( Qt::AlignRight );
legend->rstyle( QgsLegendStyle::Subgroup ).setAlignment( Qt::AlignRight ); legend->rstyle( Qgis::LegendComponent::Subgroup ).setAlignment( Qt::AlignRight );
legend->rstyle( QgsLegendStyle::SymbolLabel ).setAlignment( Qt::AlignRight ); legend->rstyle( Qgis::LegendComponent::SymbolLabel ).setAlignment( Qt::AlignRight );
legend->setTitleAlignment( Qt::AlignRight ); legend->setTitleAlignment( Qt::AlignRight );
} }
@ -265,21 +265,21 @@ void QgsLayoutGuiUtils::registerGuiForKnownItemTypes( QgsMapCanvas *mapCanvas )
QFont font; QFont font;
QgsFontUtils::setFontFamily( font, defaultFontString ); QgsFontUtils::setFontFamily( font, defaultFontString );
QgsTextFormat f = legend->rstyle( QgsLegendStyle::Title ).textFormat(); QgsTextFormat f = legend->rstyle( Qgis::LegendComponent::Title ).textFormat();
f.setFont( font ); f.setFont( font );
legend->rstyle( QgsLegendStyle::Title ).setTextFormat( f ); legend->rstyle( Qgis::LegendComponent::Title ).setTextFormat( f );
f = legend->rstyle( QgsLegendStyle::Group ).textFormat(); f = legend->rstyle( Qgis::LegendComponent::Group ).textFormat();
f.setFont( font ); f.setFont( font );
legend->rstyle( QgsLegendStyle::Group ).setTextFormat( f ); legend->rstyle( Qgis::LegendComponent::Group ).setTextFormat( f );
f = legend->rstyle( QgsLegendStyle::Subgroup ).textFormat(); f = legend->rstyle( Qgis::LegendComponent::Subgroup ).textFormat();
f.setFont( font ); f.setFont( font );
legend->rstyle( QgsLegendStyle::Subgroup ).setTextFormat( f ); legend->rstyle( Qgis::LegendComponent::Subgroup ).setTextFormat( f );
f = legend->rstyle( QgsLegendStyle::SymbolLabel ).textFormat(); f = legend->rstyle( Qgis::LegendComponent::SymbolLabel ).textFormat();
f.setFont( font ); f.setFont( font );
legend->rstyle( QgsLegendStyle::SymbolLabel ).setTextFormat( f ); legend->rstyle( Qgis::LegendComponent::SymbolLabel ).setTextFormat( f );
} }
legend->updateLegend(); legend->updateLegend();

View File

@ -262,9 +262,9 @@ void QgsLayoutLegendWidget::setGuiElements()
blockAllSignals( true ); blockAllSignals( true );
mTitleLineEdit->setText( mLegend->title() ); mTitleLineEdit->setText( mLegend->title() );
whileBlocking( mTitleAlignCombo )->setCurrentAlignment( mLegend->titleAlignment() ); whileBlocking( mTitleAlignCombo )->setCurrentAlignment( mLegend->titleAlignment() );
whileBlocking( mGroupAlignCombo )->setCurrentAlignment( mLegend->style( QgsLegendStyle::Group ).alignment() ); whileBlocking( mGroupAlignCombo )->setCurrentAlignment( mLegend->style( Qgis::LegendComponent::Group ).alignment() );
whileBlocking( mSubgroupAlignCombo )->setCurrentAlignment( mLegend->style( QgsLegendStyle::Subgroup ).alignment() ); whileBlocking( mSubgroupAlignCombo )->setCurrentAlignment( mLegend->style( Qgis::LegendComponent::Subgroup ).alignment() );
whileBlocking( mItemAlignCombo )->setCurrentAlignment( mLegend->style( QgsLegendStyle::SymbolLabel ).alignment() ); whileBlocking( mItemAlignCombo )->setCurrentAlignment( mLegend->style( Qgis::LegendComponent::SymbolLabel ).alignment() );
whileBlocking( mArrangementCombo )->setCurrentAlignment( mLegend->symbolAlignment() ); whileBlocking( mArrangementCombo )->setCurrentAlignment( mLegend->symbolAlignment() );
mFilterByMapCheckBox->setChecked( mLegend->legendFilterByMapEnabled() ); mFilterByMapCheckBox->setChecked( mLegend->legendFilterByMapEnabled() );
mButtonLinkedMaps->setEnabled( mLegend->legendFilterByMapEnabled() ); mButtonLinkedMaps->setEnabled( mLegend->legendFilterByMapEnabled() );
@ -277,19 +277,19 @@ void QgsLayoutLegendWidget::setGuiElements()
mMinSymbolSizeSpinBox->setValue( mLegend->minimumSymbolSize() ); mMinSymbolSizeSpinBox->setValue( mLegend->minimumSymbolSize() );
mWmsLegendWidthSpinBox->setValue( mLegend->wmsLegendWidth() ); mWmsLegendWidthSpinBox->setValue( mLegend->wmsLegendWidth() );
mWmsLegendHeightSpinBox->setValue( mLegend->wmsLegendHeight() ); mWmsLegendHeightSpinBox->setValue( mLegend->wmsLegendHeight() );
mTitleSpaceBottomSpinBox->setValue( mLegend->style( QgsLegendStyle::Title ).margin( QgsLegendStyle::Bottom ) ); mTitleSpaceBottomSpinBox->setValue( mLegend->style( Qgis::LegendComponent::Title ).margin( QgsLegendStyle::Bottom ) );
mGroupSpaceSpinBox->setValue( mLegend->style( QgsLegendStyle::Group ).margin( QgsLegendStyle::Top ) ); mGroupSpaceSpinBox->setValue( mLegend->style( Qgis::LegendComponent::Group ).margin( QgsLegendStyle::Top ) );
mGroupIndentSpinBox->setValue( mLegend->style( QgsLegendStyle::Group ).indent() ); mGroupIndentSpinBox->setValue( mLegend->style( Qgis::LegendComponent::Group ).indent() );
mSubgroupIndentSpinBox->setValue( mLegend->style( QgsLegendStyle::Subgroup ).indent() ); mSubgroupIndentSpinBox->setValue( mLegend->style( Qgis::LegendComponent::Subgroup ).indent() );
mGroupSideSpinBox->setValue( mLegend->style( QgsLegendStyle::Group ).margin( QgsLegendStyle::Left ) ); mGroupSideSpinBox->setValue( mLegend->style( Qgis::LegendComponent::Group ).margin( QgsLegendStyle::Left ) );
mSpaceBelowGroupHeadingSpinBox->setValue( mLegend->style( QgsLegendStyle::Group ).margin( QgsLegendStyle::Bottom ) ); mSpaceBelowGroupHeadingSpinBox->setValue( mLegend->style( Qgis::LegendComponent::Group ).margin( QgsLegendStyle::Bottom ) );
mLayerSpaceSpinBox->setValue( mLegend->style( QgsLegendStyle::Subgroup ).margin( QgsLegendStyle::Top ) ); mLayerSpaceSpinBox->setValue( mLegend->style( Qgis::LegendComponent::Subgroup ).margin( QgsLegendStyle::Top ) );
mSpaceBelowSubgroupHeadingSpinBox->setValue( mLegend->style( QgsLegendStyle::Subgroup ).margin( QgsLegendStyle::Bottom ) ); mSpaceBelowSubgroupHeadingSpinBox->setValue( mLegend->style( Qgis::LegendComponent::Subgroup ).margin( QgsLegendStyle::Bottom ) );
mSubgroupSideSpinBox->setValue( mLegend->style( QgsLegendStyle::Subgroup ).margin( QgsLegendStyle::Left ) ); mSubgroupSideSpinBox->setValue( mLegend->style( Qgis::LegendComponent::Subgroup ).margin( QgsLegendStyle::Left ) );
// We keep Symbol and SymbolLabel Top in sync for now // We keep Symbol and SymbolLabel Top in sync for now
mSymbolSpaceSpinBox->setValue( mLegend->style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Top ) ); mSymbolSpaceSpinBox->setValue( mLegend->style( Qgis::LegendComponent::Symbol ).margin( QgsLegendStyle::Top ) );
mIconLabelSpaceSpinBox->setValue( mLegend->style( QgsLegendStyle::SymbolLabel ).margin( QgsLegendStyle::Left ) ); mIconLabelSpaceSpinBox->setValue( mLegend->style( Qgis::LegendComponent::SymbolLabel ).margin( QgsLegendStyle::Left ) );
mSymbolSideSpaceSpinBox->setValue( mLegend->style( QgsLegendStyle::Symbol ).margin( QgsLegendStyle::Left ) ); mSymbolSideSpaceSpinBox->setValue( mLegend->style( Qgis::LegendComponent::Symbol ).margin( QgsLegendStyle::Left ) );
mBoxSpaceSpinBox->setValue( mLegend->boxSpace() ); mBoxSpaceSpinBox->setValue( mLegend->boxSpace() );
mColumnSpaceSpinBox->setValue( mLegend->columnSpace() ); mColumnSpaceSpinBox->setValue( mLegend->columnSpace() );
@ -305,10 +305,10 @@ void QgsLayoutLegendWidget::setGuiElements()
QgsLayoutItemMap *map = mLegend->linkedMap(); QgsLayoutItemMap *map = mLegend->linkedMap();
mMapComboBox->setItem( map ); mMapComboBox->setItem( map );
mTitleFontButton->setTextFormat( mLegend->style( QgsLegendStyle::Title ).textFormat() ); mTitleFontButton->setTextFormat( mLegend->style( Qgis::LegendComponent::Title ).textFormat() );
mGroupFontButton->setTextFormat( mLegend->style( QgsLegendStyle::Group ).textFormat() ); mGroupFontButton->setTextFormat( mLegend->style( Qgis::LegendComponent::Group ).textFormat() );
mLayerFontButton->setTextFormat( mLegend->style( QgsLegendStyle::Subgroup ).textFormat() ); mLayerFontButton->setTextFormat( mLegend->style( Qgis::LegendComponent::Subgroup ).textFormat() );
mItemFontButton->setTextFormat( mLegend->style( QgsLegendStyle::SymbolLabel ).textFormat() ); mItemFontButton->setTextFormat( mLegend->style( Qgis::LegendComponent::SymbolLabel ).textFormat() );
blockAllSignals( false ); blockAllSignals( false );
@ -358,7 +358,7 @@ void QgsLayoutLegendWidget::groupAlignmentChanged()
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Group Alignment" ) ); mLegend->beginCommand( tr( "Change Group Alignment" ) );
mLegend->rstyle( QgsLegendStyle::Group ).setAlignment( mGroupAlignCombo->currentAlignment() ); mLegend->rstyle( Qgis::LegendComponent::Group ).setAlignment( mGroupAlignCombo->currentAlignment() );
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
} }
@ -369,7 +369,7 @@ void QgsLayoutLegendWidget::subgroupAlignmentChanged()
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Subgroup Alignment" ) ); mLegend->beginCommand( tr( "Change Subgroup Alignment" ) );
mLegend->rstyle( QgsLegendStyle::Subgroup ).setAlignment( mSubgroupAlignCombo->currentAlignment() ); mLegend->rstyle( Qgis::LegendComponent::Subgroup ).setAlignment( mSubgroupAlignCombo->currentAlignment() );
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
} }
@ -380,7 +380,7 @@ void QgsLayoutLegendWidget::itemAlignmentChanged()
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Item Alignment" ) ); mLegend->beginCommand( tr( "Change Item Alignment" ) );
mLegend->rstyle( QgsLegendStyle::SymbolLabel ).setAlignment( mItemAlignCombo->currentAlignment() ); mLegend->rstyle( Qgis::LegendComponent::SymbolLabel ).setAlignment( mItemAlignCombo->currentAlignment() );
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
} }
@ -513,7 +513,7 @@ void QgsLayoutLegendWidget::mTitleSpaceBottomSpinBox_valueChanged( double d )
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Title Space" ), QgsLayoutItem::UndoLegendTitleSpaceBottom ); mLegend->beginCommand( tr( "Change Title Space" ), QgsLayoutItem::UndoLegendTitleSpaceBottom );
mLegend->rstyle( QgsLegendStyle::Title ).setMargin( QgsLegendStyle::Bottom, d ); mLegend->rstyle( Qgis::LegendComponent::Title ).setMargin( QgsLegendStyle::Bottom, d );
mLegend->adjustBoxSize(); mLegend->adjustBoxSize();
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
@ -525,7 +525,7 @@ void QgsLayoutLegendWidget::mGroupSpaceSpinBox_valueChanged( double d )
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Group Space" ), QgsLayoutItem::UndoLegendGroupSpace ); mLegend->beginCommand( tr( "Change Group Space" ), QgsLayoutItem::UndoLegendGroupSpace );
mLegend->rstyle( QgsLegendStyle::Group ).setMargin( QgsLegendStyle::Top, d ); mLegend->rstyle( Qgis::LegendComponent::Group ).setMargin( QgsLegendStyle::Top, d );
mLegend->adjustBoxSize(); mLegend->adjustBoxSize();
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
@ -537,7 +537,7 @@ void QgsLayoutLegendWidget::mGroupIndentSpinBox_valueChanged( double d )
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Group Indent" ), QgsLayoutItem::UndoLegendGroupIndent ); mLegend->beginCommand( tr( "Change Group Indent" ), QgsLayoutItem::UndoLegendGroupIndent );
mLegend->rstyle( QgsLegendStyle::Group ).setIndent( d ); mLegend->rstyle( Qgis::LegendComponent::Group ).setIndent( d );
mLegend->adjustBoxSize(); mLegend->adjustBoxSize();
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
@ -549,7 +549,7 @@ void QgsLayoutLegendWidget::mSubgroupIndentSpinBox_valueChanged( double d )
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Subgroup Indent" ), QgsLayoutItem::UndoLegendSubgroupIndent ); mLegend->beginCommand( tr( "Change Subgroup Indent" ), QgsLayoutItem::UndoLegendSubgroupIndent );
mLegend->rstyle( QgsLegendStyle::Subgroup ).setIndent( d ); mLegend->rstyle( Qgis::LegendComponent::Subgroup ).setIndent( d );
mLegend->adjustBoxSize(); mLegend->adjustBoxSize();
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
@ -561,7 +561,7 @@ void QgsLayoutLegendWidget::spaceBelowGroupHeadingChanged( double space )
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Group Space" ), QgsLayoutItem::UndoLegendGroupSpace ); mLegend->beginCommand( tr( "Change Group Space" ), QgsLayoutItem::UndoLegendGroupSpace );
mLegend->rstyle( QgsLegendStyle::Group ).setMargin( QgsLegendStyle::Bottom, space ); mLegend->rstyle( Qgis::LegendComponent::Group ).setMargin( QgsLegendStyle::Bottom, space );
mLegend->adjustBoxSize(); mLegend->adjustBoxSize();
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
@ -573,7 +573,7 @@ void QgsLayoutLegendWidget::spaceGroupSideChanged( double space )
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Side of Group Space" ), QgsLayoutItem::UndoLegendGroupSpace ); mLegend->beginCommand( tr( "Change Side of Group Space" ), QgsLayoutItem::UndoLegendGroupSpace );
mLegend->rstyle( QgsLegendStyle::Group ).setMargin( QgsLegendStyle::Left, space ); mLegend->rstyle( Qgis::LegendComponent::Group ).setMargin( QgsLegendStyle::Left, space );
mLegend->adjustBoxSize(); mLegend->adjustBoxSize();
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
@ -585,7 +585,7 @@ void QgsLayoutLegendWidget::spaceSubGroupSideChanged( double space )
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Side of Subgroup Space" ), QgsLayoutItem::UndoLegendLayerSpace ); mLegend->beginCommand( tr( "Change Side of Subgroup Space" ), QgsLayoutItem::UndoLegendLayerSpace );
mLegend->rstyle( QgsLegendStyle::Subgroup ).setMargin( QgsLegendStyle::Left, space ); mLegend->rstyle( Qgis::LegendComponent::Subgroup ).setMargin( QgsLegendStyle::Left, space );
mLegend->adjustBoxSize(); mLegend->adjustBoxSize();
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
@ -597,7 +597,7 @@ void QgsLayoutLegendWidget::spaceSymbolSideChanged( double space )
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Side of Symbol Space" ), QgsLayoutItem::UndoLegendSymbolSpace ); mLegend->beginCommand( tr( "Change Side of Symbol Space" ), QgsLayoutItem::UndoLegendSymbolSpace );
mLegend->rstyle( QgsLegendStyle::Symbol ).setMargin( QgsLegendStyle::Left, space ); mLegend->rstyle( Qgis::LegendComponent::Symbol ).setMargin( QgsLegendStyle::Left, space );
mLegend->adjustBoxSize(); mLegend->adjustBoxSize();
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
@ -609,7 +609,7 @@ void QgsLayoutLegendWidget::mLayerSpaceSpinBox_valueChanged( double d )
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Subgroup Space" ), QgsLayoutItem::UndoLegendLayerSpace ); mLegend->beginCommand( tr( "Change Subgroup Space" ), QgsLayoutItem::UndoLegendLayerSpace );
mLegend->rstyle( QgsLegendStyle::Subgroup ).setMargin( QgsLegendStyle::Top, d ); mLegend->rstyle( Qgis::LegendComponent::Subgroup ).setMargin( QgsLegendStyle::Top, d );
mLegend->adjustBoxSize(); mLegend->adjustBoxSize();
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
@ -622,8 +622,8 @@ void QgsLayoutLegendWidget::mSymbolSpaceSpinBox_valueChanged( double d )
{ {
mLegend->beginCommand( tr( "Change Symbol Space" ), QgsLayoutItem::UndoLegendSymbolSpace ); mLegend->beginCommand( tr( "Change Symbol Space" ), QgsLayoutItem::UndoLegendSymbolSpace );
// We keep Symbol and SymbolLabel Top in sync for now // We keep Symbol and SymbolLabel Top in sync for now
mLegend->rstyle( QgsLegendStyle::Symbol ).setMargin( QgsLegendStyle::Top, d ); mLegend->rstyle( Qgis::LegendComponent::Symbol ).setMargin( QgsLegendStyle::Top, d );
mLegend->rstyle( QgsLegendStyle::SymbolLabel ).setMargin( QgsLegendStyle::Top, d ); mLegend->rstyle( Qgis::LegendComponent::SymbolLabel ).setMargin( QgsLegendStyle::Top, d );
mLegend->adjustBoxSize(); mLegend->adjustBoxSize();
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
@ -635,7 +635,7 @@ void QgsLayoutLegendWidget::mIconLabelSpaceSpinBox_valueChanged( double d )
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Label Space" ), QgsLayoutItem::UndoLegendIconSymbolSpace ); mLegend->beginCommand( tr( "Change Label Space" ), QgsLayoutItem::UndoLegendIconSymbolSpace );
mLegend->rstyle( QgsLegendStyle::SymbolLabel ).setMargin( QgsLegendStyle::Left, d ); mLegend->rstyle( Qgis::LegendComponent::SymbolLabel ).setMargin( QgsLegendStyle::Left, d );
mLegend->adjustBoxSize(); mLegend->adjustBoxSize();
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
@ -647,7 +647,7 @@ void QgsLayoutLegendWidget::titleFontChanged()
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Title Font" ), QgsLayoutItem::UndoLegendTitleFont ); mLegend->beginCommand( tr( "Change Title Font" ), QgsLayoutItem::UndoLegendTitleFont );
mLegend->rstyle( QgsLegendStyle::Title ).setTextFormat( mTitleFontButton->textFormat() ); mLegend->rstyle( Qgis::LegendComponent::Title ).setTextFormat( mTitleFontButton->textFormat() );
mLegend->adjustBoxSize(); mLegend->adjustBoxSize();
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
@ -659,7 +659,7 @@ void QgsLayoutLegendWidget::groupFontChanged()
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Group Font" ), QgsLayoutItem::UndoLegendGroupFont ); mLegend->beginCommand( tr( "Change Group Font" ), QgsLayoutItem::UndoLegendGroupFont );
mLegend->rstyle( QgsLegendStyle::Group ).setTextFormat( mGroupFontButton->textFormat() ); mLegend->rstyle( Qgis::LegendComponent::Group ).setTextFormat( mGroupFontButton->textFormat() );
mLegend->adjustBoxSize(); mLegend->adjustBoxSize();
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
@ -671,7 +671,7 @@ void QgsLayoutLegendWidget::layerFontChanged()
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Layer Font" ), QgsLayoutItem::UndoLegendLayerFont ); mLegend->beginCommand( tr( "Change Layer Font" ), QgsLayoutItem::UndoLegendLayerFont );
mLegend->rstyle( QgsLegendStyle::Subgroup ).setTextFormat( mLayerFontButton->textFormat() ); mLegend->rstyle( Qgis::LegendComponent::Subgroup ).setTextFormat( mLayerFontButton->textFormat() );
mLegend->adjustBoxSize(); mLegend->adjustBoxSize();
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
@ -683,7 +683,7 @@ void QgsLayoutLegendWidget::itemFontChanged()
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Item Font" ), QgsLayoutItem::UndoLegendItemFont ); mLegend->beginCommand( tr( "Change Item Font" ), QgsLayoutItem::UndoLegendItemFont );
mLegend->rstyle( QgsLegendStyle::SymbolLabel ).setTextFormat( mItemFontButton->textFormat() ); mLegend->rstyle( Qgis::LegendComponent::SymbolLabel ).setTextFormat( mItemFontButton->textFormat() );
mLegend->adjustBoxSize(); mLegend->adjustBoxSize();
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
@ -695,7 +695,7 @@ void QgsLayoutLegendWidget::spaceBelowSubGroupHeadingChanged( double space )
if ( mLegend ) if ( mLegend )
{ {
mLegend->beginCommand( tr( "Change Subgroup Space" ), QgsLayoutItem::UndoLegendLayerSpace ); mLegend->beginCommand( tr( "Change Subgroup Space" ), QgsLayoutItem::UndoLegendLayerSpace );
mLegend->rstyle( QgsLegendStyle::Subgroup ).setMargin( QgsLegendStyle::Bottom, space ); mLegend->rstyle( Qgis::LegendComponent::Subgroup ).setMargin( QgsLegendStyle::Bottom, space );
mLegend->adjustBoxSize(); mLegend->adjustBoxSize();
mLegend->update(); mLegend->update();
mLegend->endCommand(); mLegend->endCommand();
@ -1404,7 +1404,7 @@ void QgsLayoutLegendWidget::setCurrentNodeStyleFromAction()
if ( !a || !mItemTreeView->currentNode() ) if ( !a || !mItemTreeView->currentNode() )
return; return;
QgsLegendRenderer::setNodeLegendStyle( mItemTreeView->currentNode(), static_cast<QgsLegendStyle::Style>( a->data().toInt() ) ); QgsLegendRenderer::setNodeLegendStyle( mItemTreeView->currentNode(), static_cast<Qgis::LegendComponent>( a->data().toInt() ) );
mLegend->update(); mLegend->update();
} }
@ -1481,14 +1481,14 @@ QMenu *QgsLayoutLegendMenuProvider::createContextMenu()
menu->addSeparator(); menu->addSeparator();
} }
QgsLegendStyle::Style currentStyle = QgsLegendRenderer::nodeLegendStyle( mView->currentNode(), mView->layerTreeModel() ); Qgis::LegendComponent currentStyle = QgsLegendRenderer::nodeLegendStyle( mView->currentNode(), mView->layerTreeModel() );
QActionGroup *styleGroup = new QActionGroup { mWidget }; QActionGroup *styleGroup = new QActionGroup { mWidget };
styleGroup->setExclusive( true ); styleGroup->setExclusive( true );
QList<QgsLegendStyle::Style> lst; QList<Qgis::LegendComponent> lst;
lst << QgsLegendStyle::Hidden << QgsLegendStyle::Group << QgsLegendStyle::Subgroup; lst << Qgis::LegendComponent::Hidden << Qgis::LegendComponent::Group << Qgis::LegendComponent::Subgroup;
for ( QgsLegendStyle::Style style : std::as_const( lst ) ) for ( Qgis::LegendComponent style : std::as_const( lst ) )
{ {
QAction *action = menu->addAction( QgsLegendStyle::styleLabel( style ), mWidget, &QgsLayoutLegendWidget::setCurrentNodeStyleFromAction ); QAction *action = menu->addAction( QgsLegendStyle::styleLabel( style ), mWidget, &QgsLayoutLegendWidget::setCurrentNodeStyleFromAction );
action->setActionGroup( styleGroup ); action->setActionGroup( styleGroup );

View File

@ -293,7 +293,7 @@ namespace QgsWms
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node ); QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
// layer titles - hidden or not // layer titles - hidden or not
QgsLegendRenderer::setNodeLegendStyle( nodeLayer, parameters.layerTitleAsBool() ? QgsLegendStyle::Subgroup : QgsLegendStyle::Hidden ); QgsLegendRenderer::setNodeLegendStyle( nodeLayer, parameters.layerTitleAsBool() ? Qgis::LegendComponent::Subgroup : Qgis::LegendComponent::Hidden );
// rule item titles // rule item titles
if ( !parameters.ruleLabelAsBool() ) if ( !parameters.ruleLabelAsBool() )
{ {

View File

@ -1207,19 +1207,19 @@ namespace QgsWms
settings.setBoxSpace( boxSpaceAsDouble() ); settings.setBoxSpace( boxSpaceAsDouble() );
settings.setSymbolSize( QSizeF( symbolWidthAsDouble(), symbolHeightAsDouble() ) ); settings.setSymbolSize( QSizeF( symbolWidthAsDouble(), symbolHeightAsDouble() ) );
settings.rstyle( QgsLegendStyle::Style::Subgroup ).setMargin( QgsLegendStyle::Side::Top, layerSpaceAsDouble() ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setMargin( QgsLegendStyle::Side::Top, layerSpaceAsDouble() );
settings.rstyle( QgsLegendStyle::Style::Subgroup ).setMargin( QgsLegendStyle::Side::Bottom, layerTitleSpaceAsDouble() ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setMargin( QgsLegendStyle::Side::Bottom, layerTitleSpaceAsDouble() );
// text format must be set before setting the format's colors // text format must be set before setting the format's colors
settings.rstyle( QgsLegendStyle::Style::Subgroup ).setTextFormat( QgsTextFormat::fromQFont( layerFont() ) ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setTextFormat( QgsTextFormat::fromQFont( layerFont() ) );
settings.rstyle( QgsLegendStyle::Style::SymbolLabel ).setTextFormat( QgsTextFormat::fromQFont( itemFont() ) ); settings.rstyle( Qgis::LegendComponent::SymbolLabel ).setTextFormat( QgsTextFormat::fromQFont( itemFont() ) );
if ( !itemFontColor().isEmpty() ) if ( !itemFontColor().isEmpty() )
{ {
settings.rstyle( QgsLegendStyle::Title ).textFormat().setColor( itemFontColorAsColor() ); settings.rstyle( Qgis::LegendComponent::Title ).textFormat().setColor( itemFontColorAsColor() );
settings.rstyle( QgsLegendStyle::Group ).textFormat().setColor( itemFontColorAsColor() ); settings.rstyle( Qgis::LegendComponent::Group ).textFormat().setColor( itemFontColorAsColor() );
settings.rstyle( QgsLegendStyle::Subgroup ).textFormat().setColor( itemFontColorAsColor() ); settings.rstyle( Qgis::LegendComponent::Subgroup ).textFormat().setColor( itemFontColorAsColor() );
settings.rstyle( QgsLegendStyle::SymbolLabel ).textFormat().setColor( itemFontColorAsColor() ); settings.rstyle( Qgis::LegendComponent::SymbolLabel ).textFormat().setColor( itemFontColorAsColor() );
} }
// Ok, this is tricky: because QgsLegendSettings's layerFontColor was added to the API after // Ok, this is tricky: because QgsLegendSettings's layerFontColor was added to the API after
@ -1227,11 +1227,11 @@ namespace QgsWms
// for the whole legend we need to preserve that behavior. // 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 // 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. // we set explicitly layerFontColor to black if it's not overridden by LAYERFONTCOLOR argument.
settings.rstyle( QgsLegendStyle::Group ).textFormat().setColor( layerFontColor().isEmpty() ? QColor( Qt::black ) : layerFontColorAsColor() ); settings.rstyle( Qgis::LegendComponent::Group ).textFormat().setColor( layerFontColor().isEmpty() ? QColor( Qt::black ) : layerFontColorAsColor() );
settings.rstyle( QgsLegendStyle::Subgroup ).textFormat().setColor( layerFontColor().isEmpty() ? QColor( Qt::black ) : layerFontColorAsColor() ); settings.rstyle( Qgis::LegendComponent::Subgroup ).textFormat().setColor( layerFontColor().isEmpty() ? QColor( Qt::black ) : layerFontColorAsColor() );
settings.rstyle( QgsLegendStyle::Style::Symbol ).setMargin( QgsLegendStyle::Side::Top, symbolSpaceAsDouble() ); settings.rstyle( Qgis::LegendComponent::Symbol ).setMargin( QgsLegendStyle::Side::Top, symbolSpaceAsDouble() );
settings.rstyle( QgsLegendStyle::Style::SymbolLabel ).setMargin( QgsLegendStyle::Side::Left, iconLabelSpaceAsDouble() ); settings.rstyle( Qgis::LegendComponent::SymbolLabel ).setMargin( QgsLegendStyle::Side::Left, iconLabelSpaceAsDouble() );
// When processing a request involving an upstream WMS server, any responses from such a remote // When processing a request involving an upstream WMS server, any responses from such a remote
// server must be awaited. This was not the case for GetLegendGraphic requests (#42063). If not, // server must be awaited. This was not the case for GetLegendGraphic requests (#42063). If not,

View File

@ -172,12 +172,12 @@ class TestQgsLegendRenderer : public QgsTest
static void setStandardTestFont( QgsLegendSettings &settings, const QString &style = QStringLiteral( "Roman" ) ) static void setStandardTestFont( QgsLegendSettings &settings, const QString &style = QStringLiteral( "Roman" ) )
{ {
for ( const QgsLegendStyle::Style st : for ( const Qgis::LegendComponent st :
{ {
QgsLegendStyle::Title, Qgis::LegendComponent::Title,
QgsLegendStyle::Group, Qgis::LegendComponent::Group,
QgsLegendStyle::Subgroup, Qgis::LegendComponent::Subgroup,
QgsLegendStyle::SymbolLabel Qgis::LegendComponent::SymbolLabel
} ) } )
{ {
QFont font( QgsFontUtils::getStandardTestFont( style ) ); QFont font( QgsFontUtils::getStandardTestFont( style ) );
@ -463,8 +463,8 @@ void TestQgsLegendRenderer::testOverrideSizeSmall()
legendModel.refreshLayerLegend( layer ); legendModel.refreshLayerLegend( layer );
QgsLegendSettings settings; QgsLegendSettings settings;
settings.rstyle( QgsLegendStyle::Symbol ).setMargin( QgsLegendStyle::Top, 0 ); settings.rstyle( Qgis::LegendComponent::Symbol ).setMargin( QgsLegendStyle::Top, 0 );
settings.rstyle( QgsLegendStyle::Symbol ).setMargin( QgsLegendStyle::Bottom, 0 ); settings.rstyle( Qgis::LegendComponent::Symbol ).setMargin( QgsLegendStyle::Bottom, 0 );
settings.setMinimumSymbolSize( 5 ); settings.setMinimumSymbolSize( 5 );
settings.setMaximumSymbolSize( 9 ); settings.setMaximumSymbolSize( 9 );
setStandardTestFont( settings, QStringLiteral( "Bold" ) ); setStandardTestFont( settings, QStringLiteral( "Bold" ) );
@ -485,20 +485,20 @@ void TestQgsLegendRenderer::testSpacing()
QgsLayerTreeModel legendModel( mRoot ); QgsLayerTreeModel legendModel( mRoot );
QgsLegendSettings settings; QgsLegendSettings settings;
settings.rstyle( QgsLegendStyle::Group ).setMargin( QgsLegendStyle::Left, 7 ); settings.rstyle( Qgis::LegendComponent::Group ).setMargin( QgsLegendStyle::Left, 7 );
settings.rstyle( QgsLegendStyle::Subgroup ).setMargin( QgsLegendStyle::Left, 11 ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setMargin( QgsLegendStyle::Left, 11 );
settings.rstyle( QgsLegendStyle::Symbol ).setMargin( QgsLegendStyle::Left, 5 ); settings.rstyle( Qgis::LegendComponent::Symbol ).setMargin( QgsLegendStyle::Left, 5 );
setStandardTestFont( settings, QStringLiteral( "Bold" ) ); setStandardTestFont( settings, QStringLiteral( "Bold" ) );
settings.rstyle( QgsLegendStyle::Group ).setAlignment( Qt::AlignLeft ); settings.rstyle( Qgis::LegendComponent::Group ).setAlignment( Qt::AlignLeft );
settings.rstyle( QgsLegendStyle::Subgroup ).setAlignment( Qt::AlignLeft ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setAlignment( Qt::AlignLeft );
settings.rstyle( QgsLegendStyle::SymbolLabel ).setAlignment( Qt::AlignLeft ); settings.rstyle( Qgis::LegendComponent::SymbolLabel ).setAlignment( Qt::AlignLeft );
QImage res = renderLegend( &legendModel, settings ); QImage res = renderLegend( &legendModel, settings );
QVERIFY( _verifyImage( res, QStringLiteral( "legend_left_align_side_space" ) ) ); QVERIFY( _verifyImage( res, QStringLiteral( "legend_left_align_side_space" ) ) );
settings.rstyle( QgsLegendStyle::Group ).setAlignment( Qt::AlignRight ); settings.rstyle( Qgis::LegendComponent::Group ).setAlignment( Qt::AlignRight );
settings.rstyle( QgsLegendStyle::Subgroup ).setAlignment( Qt::AlignRight ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setAlignment( Qt::AlignRight );
settings.setSymbolAlignment( Qt::AlignRight ); settings.setSymbolAlignment( Qt::AlignRight );
res = renderLegend( &legendModel, settings ); res = renderLegend( &legendModel, settings );
@ -648,9 +648,9 @@ void TestQgsLegendRenderer::testCenterAlignText()
QgsLayerTreeModel legendModel( mRoot ); QgsLayerTreeModel legendModel( mRoot );
QgsLegendSettings settings; QgsLegendSettings settings;
settings.rstyle( QgsLegendStyle::Group ).setAlignment( Qt::AlignHCenter ); settings.rstyle( Qgis::LegendComponent::Group ).setAlignment( Qt::AlignHCenter );
settings.rstyle( QgsLegendStyle::Subgroup ).setAlignment( Qt::AlignHCenter ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setAlignment( Qt::AlignHCenter );
settings.rstyle( QgsLegendStyle::SymbolLabel ).setAlignment( Qt::AlignHCenter ); settings.rstyle( Qgis::LegendComponent::SymbolLabel ).setAlignment( Qt::AlignHCenter );
setStandardTestFont( settings, QStringLiteral( "Bold" ) ); setStandardTestFont( settings, QStringLiteral( "Bold" ) );
QImage res = renderLegend( &legendModel, settings ); QImage res = renderLegend( &legendModel, settings );
@ -673,9 +673,9 @@ void TestQgsLegendRenderer::testLeftAlignTextRightAlignSymbol()
QgsLayerTreeModel legendModel( mRoot ); QgsLayerTreeModel legendModel( mRoot );
QgsLegendSettings settings; QgsLegendSettings settings;
settings.rstyle( QgsLegendStyle::Group ).setAlignment( Qt::AlignLeft ); settings.rstyle( Qgis::LegendComponent::Group ).setAlignment( Qt::AlignLeft );
settings.rstyle( QgsLegendStyle::Subgroup ).setAlignment( Qt::AlignLeft ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setAlignment( Qt::AlignLeft );
settings.rstyle( QgsLegendStyle::SymbolLabel ).setAlignment( Qt::AlignLeft ); settings.rstyle( Qgis::LegendComponent::SymbolLabel ).setAlignment( Qt::AlignLeft );
settings.setSymbolAlignment( Qt::AlignRight ); settings.setSymbolAlignment( Qt::AlignRight );
setStandardTestFont( settings, QStringLiteral( "Bold" ) ); setStandardTestFont( settings, QStringLiteral( "Bold" ) );
@ -699,9 +699,9 @@ void TestQgsLegendRenderer::testCenterAlignTextRightAlignSymbol()
QgsLayerTreeModel legendModel( mRoot ); QgsLayerTreeModel legendModel( mRoot );
QgsLegendSettings settings; QgsLegendSettings settings;
settings.rstyle( QgsLegendStyle::Group ).setAlignment( Qt::AlignHCenter ); settings.rstyle( Qgis::LegendComponent::Group ).setAlignment( Qt::AlignHCenter );
settings.rstyle( QgsLegendStyle::Subgroup ).setAlignment( Qt::AlignHCenter ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setAlignment( Qt::AlignHCenter );
settings.rstyle( QgsLegendStyle::SymbolLabel ).setAlignment( Qt::AlignHCenter ); settings.rstyle( Qgis::LegendComponent::SymbolLabel ).setAlignment( Qt::AlignHCenter );
settings.setSymbolAlignment( Qt::AlignRight ); settings.setSymbolAlignment( Qt::AlignRight );
setStandardTestFont( settings, QStringLiteral( "Bold" ) ); setStandardTestFont( settings, QStringLiteral( "Bold" ) );
@ -725,9 +725,9 @@ void TestQgsLegendRenderer::testRightAlignTextRightAlignSymbol()
QgsLayerTreeModel legendModel( mRoot ); QgsLayerTreeModel legendModel( mRoot );
QgsLegendSettings settings; QgsLegendSettings settings;
settings.rstyle( QgsLegendStyle::Group ).setAlignment( Qt::AlignRight ); settings.rstyle( Qgis::LegendComponent::Group ).setAlignment( Qt::AlignRight );
settings.rstyle( QgsLegendStyle::Subgroup ).setAlignment( Qt::AlignRight ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setAlignment( Qt::AlignRight );
settings.rstyle( QgsLegendStyle::SymbolLabel ).setAlignment( Qt::AlignRight ); settings.rstyle( Qgis::LegendComponent::SymbolLabel ).setAlignment( Qt::AlignRight );
settings.setSymbolAlignment( Qt::AlignRight ); settings.setSymbolAlignment( Qt::AlignRight );
setStandardTestFont( settings, QStringLiteral( "Bold" ) ); setStandardTestFont( settings, QStringLiteral( "Bold" ) );
@ -753,17 +753,17 @@ void TestQgsLegendRenderer::testDataDefinedTextFormat()
QgsLegendSettings settings; QgsLegendSettings settings;
setStandardTestFont( settings, QStringLiteral( "Bold" ) ); setStandardTestFont( settings, QStringLiteral( "Bold" ) );
QgsTextFormat format = settings.style( QgsLegendStyle::Group ).textFormat(); QgsTextFormat format = settings.style( Qgis::LegendComponent::Group ).textFormat();
format.dataDefinedProperties().setProperty( QgsPalLayerSettings::Property::Color, QgsProperty::fromExpression( "@text_color_group" ) ); format.dataDefinedProperties().setProperty( QgsPalLayerSettings::Property::Color, QgsProperty::fromExpression( "@text_color_group" ) );
settings.rstyle( QgsLegendStyle::Group ).setTextFormat( format ); settings.rstyle( Qgis::LegendComponent::Group ).setTextFormat( format );
format = settings.style( QgsLegendStyle::Subgroup ).textFormat(); format = settings.style( Qgis::LegendComponent::Subgroup ).textFormat();
format.dataDefinedProperties().setProperty( QgsPalLayerSettings::Property::Color, QgsProperty::fromExpression( "@text_color_subgroup" ) ); format.dataDefinedProperties().setProperty( QgsPalLayerSettings::Property::Color, QgsProperty::fromExpression( "@text_color_subgroup" ) );
settings.rstyle( QgsLegendStyle::Subgroup ).setTextFormat( format ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setTextFormat( format );
format = settings.style( QgsLegendStyle::SymbolLabel ).textFormat(); format = settings.style( Qgis::LegendComponent::SymbolLabel ).textFormat();
format.dataDefinedProperties().setProperty( QgsPalLayerSettings::Property::Color, QgsProperty::fromExpression( "@text_color_symbol_label" ) ); format.dataDefinedProperties().setProperty( QgsPalLayerSettings::Property::Color, QgsProperty::fromExpression( "@text_color_symbol_label" ) );
settings.rstyle( QgsLegendStyle::SymbolLabel ).setTextFormat( format ); settings.rstyle( Qgis::LegendComponent::SymbolLabel ).setTextFormat( format );
QgsExpressionContext context; QgsExpressionContext context;
QgsExpressionContextScope *scope = new QgsExpressionContextScope(); QgsExpressionContextScope *scope = new QgsExpressionContextScope();
@ -791,10 +791,10 @@ void TestQgsLegendRenderer::testGroupHeadingSpacing()
QgsLayerTreeModel legendModel( mRoot ); QgsLayerTreeModel legendModel( mRoot );
QgsLegendSettings settings; QgsLegendSettings settings;
settings.rstyle( QgsLegendStyle::Group ).setMargin( QgsLegendStyle::Top, 5 ); settings.rstyle( Qgis::LegendComponent::Group ).setMargin( QgsLegendStyle::Top, 5 );
settings.rstyle( QgsLegendStyle::Group ).setMargin( QgsLegendStyle::Bottom, 17 ); settings.rstyle( Qgis::LegendComponent::Group ).setMargin( QgsLegendStyle::Bottom, 17 );
settings.rstyle( QgsLegendStyle::Subgroup ).setMargin( QgsLegendStyle::Top, 13 ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setMargin( QgsLegendStyle::Top, 13 );
settings.rstyle( QgsLegendStyle::Subgroup ).setMargin( QgsLegendStyle::Bottom, 9 ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setMargin( QgsLegendStyle::Bottom, 9 );
settings.setSymbolAlignment( Qt::AlignRight ); settings.setSymbolAlignment( Qt::AlignRight );
setStandardTestFont( settings, QStringLiteral( "Bold" ) ); setStandardTestFont( settings, QStringLiteral( "Bold" ) );
@ -829,8 +829,8 @@ void TestQgsLegendRenderer::testGroupIndentDefault()
catRenderer->updateCategorySymbol( 0, sym ); catRenderer->updateCategorySymbol( 0, sym );
QgsLayerTreeModel legendModel( mRoot ); QgsLayerTreeModel legendModel( mRoot );
QgsLegendSettings settings; QgsLegendSettings settings;
settings.rstyle( QgsLegendStyle::Group ).setIndent( 10 ); settings.rstyle( Qgis::LegendComponent::Group ).setIndent( 10 );
settings.rstyle( QgsLegendStyle::Subgroup ).setIndent( 5 ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setIndent( 5 );
setStandardTestFont( settings, QStringLiteral( "Bold" ) ); setStandardTestFont( settings, QStringLiteral( "Bold" ) );
QImage res = renderLegend( &legendModel, settings ); QImage res = renderLegend( &legendModel, settings );
@ -848,12 +848,12 @@ void TestQgsLegendRenderer::testGroupIndentRT()
catRenderer->updateCategorySymbol( 0, sym ); catRenderer->updateCategorySymbol( 0, sym );
QgsLayerTreeModel legendModel( mRoot ); QgsLayerTreeModel legendModel( mRoot );
QgsLegendSettings settings; QgsLegendSettings settings;
settings.rstyle( QgsLegendStyle::Group ).setIndent( 10 ); settings.rstyle( Qgis::LegendComponent::Group ).setIndent( 10 );
settings.rstyle( QgsLegendStyle::Subgroup ).setIndent( 5 ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setIndent( 5 );
setStandardTestFont( settings, QStringLiteral( "Bold" ) ); setStandardTestFont( settings, QStringLiteral( "Bold" ) );
settings.rstyle( QgsLegendStyle::Group ).setAlignment( Qt::AlignRight ); settings.rstyle( Qgis::LegendComponent::Group ).setAlignment( Qt::AlignRight );
settings.rstyle( QgsLegendStyle::Subgroup ).setAlignment( Qt::AlignRight ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setAlignment( Qt::AlignRight );
settings.rstyle( QgsLegendStyle::SymbolLabel ).setAlignment( Qt::AlignRight ); settings.rstyle( Qgis::LegendComponent::SymbolLabel ).setAlignment( Qt::AlignRight );
QImage res = renderLegend( &legendModel, settings ); QImage res = renderLegend( &legendModel, settings );
QVERIFY( _verifyImage( res, QStringLiteral( "legend_group_indent_right_align_text" ) ) ); QVERIFY( _verifyImage( res, QStringLiteral( "legend_group_indent_right_align_text" ) ) );
@ -870,12 +870,12 @@ void TestQgsLegendRenderer::testGroupIndentRS()
catRenderer->updateCategorySymbol( 0, sym ); catRenderer->updateCategorySymbol( 0, sym );
QgsLayerTreeModel legendModel( mRoot ); QgsLayerTreeModel legendModel( mRoot );
QgsLegendSettings settings; QgsLegendSettings settings;
settings.rstyle( QgsLegendStyle::Group ).setIndent( 10 ); settings.rstyle( Qgis::LegendComponent::Group ).setIndent( 10 );
settings.rstyle( QgsLegendStyle::Subgroup ).setIndent( 5 ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setIndent( 5 );
setStandardTestFont( settings, QStringLiteral( "Bold" ) ); setStandardTestFont( settings, QStringLiteral( "Bold" ) );
settings.rstyle( QgsLegendStyle::Group ).setAlignment( Qt::AlignLeft ); settings.rstyle( Qgis::LegendComponent::Group ).setAlignment( Qt::AlignLeft );
settings.rstyle( QgsLegendStyle::Subgroup ).setAlignment( Qt::AlignLeft ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setAlignment( Qt::AlignLeft );
settings.rstyle( QgsLegendStyle::SymbolLabel ).setAlignment( Qt::AlignLeft ); settings.rstyle( Qgis::LegendComponent::SymbolLabel ).setAlignment( Qt::AlignLeft );
settings.setSymbolAlignment( Qt::AlignRight ); settings.setSymbolAlignment( Qt::AlignRight );
QImage res = renderLegend( &legendModel, settings ); QImage res = renderLegend( &legendModel, settings );
@ -893,12 +893,12 @@ void TestQgsLegendRenderer::testGroupIndentRSRT()
catRenderer->updateCategorySymbol( 0, sym ); catRenderer->updateCategorySymbol( 0, sym );
QgsLayerTreeModel legendModel( mRoot ); QgsLayerTreeModel legendModel( mRoot );
QgsLegendSettings settings; QgsLegendSettings settings;
settings.rstyle( QgsLegendStyle::Group ).setIndent( 10 ); settings.rstyle( Qgis::LegendComponent::Group ).setIndent( 10 );
settings.rstyle( QgsLegendStyle::Subgroup ).setIndent( 5 ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setIndent( 5 );
setStandardTestFont( settings, QStringLiteral( "Bold" ) ); setStandardTestFont( settings, QStringLiteral( "Bold" ) );
settings.rstyle( QgsLegendStyle::Group ).setAlignment( Qt::AlignRight ); settings.rstyle( Qgis::LegendComponent::Group ).setAlignment( Qt::AlignRight );
settings.rstyle( QgsLegendStyle::Subgroup ).setAlignment( Qt::AlignRight ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setAlignment( Qt::AlignRight );
settings.rstyle( QgsLegendStyle::SymbolLabel ).setAlignment( Qt::AlignRight ); settings.rstyle( Qgis::LegendComponent::SymbolLabel ).setAlignment( Qt::AlignRight );
settings.setSymbolAlignment( Qt::AlignRight ); settings.setSymbolAlignment( Qt::AlignRight );
QImage res = renderLegend( &legendModel, settings ); QImage res = renderLegend( &legendModel, settings );
@ -916,9 +916,9 @@ void TestQgsLegendRenderer::testRightAlignText()
QgsLayerTreeModel legendModel( mRoot ); QgsLayerTreeModel legendModel( mRoot );
QgsLegendSettings settings; QgsLegendSettings settings;
settings.rstyle( QgsLegendStyle::Group ).setAlignment( Qt::AlignRight ); settings.rstyle( Qgis::LegendComponent::Group ).setAlignment( Qt::AlignRight );
settings.rstyle( QgsLegendStyle::Subgroup ).setAlignment( Qt::AlignRight ); settings.rstyle( Qgis::LegendComponent::Subgroup ).setAlignment( Qt::AlignRight );
settings.rstyle( QgsLegendStyle::SymbolLabel ).setAlignment( Qt::AlignRight ); settings.rstyle( Qgis::LegendComponent::SymbolLabel ).setAlignment( Qt::AlignRight );
setStandardTestFont( settings, QStringLiteral( "Bold" ) ); setStandardTestFont( settings, QStringLiteral( "Bold" ) );
QImage res = renderLegend( &legendModel, settings ); QImage res = renderLegend( &legendModel, settings );
@ -1158,7 +1158,7 @@ bool TestQgsLegendRenderer::_testLegendColumns( int itemCount, int columnCount,
QgsLayerTreeModel legendModel( root.get() ); QgsLayerTreeModel legendModel( root.get() );
QgsLegendSettings settings; QgsLegendSettings settings;
settings.setColumnCount( columnCount ); settings.setColumnCount( columnCount );
settings.rstyle( QgsLegendStyle::Style::Symbol ).setMargin( QgsLegendStyle::Side::Top, symbolSpacing ); settings.rstyle( Qgis::LegendComponent::Symbol ).setMargin( QgsLegendStyle::Side::Top, symbolSpacing );
setStandardTestFont( settings, QStringLiteral( "Bold" ) ); setStandardTestFont( settings, QStringLiteral( "Bold" ) );
const QImage res = renderLegend( &legendModel, settings ); const QImage res = renderLegend( &legendModel, settings );
const bool result = _verifyImage( res, testName ); const bool result = _verifyImage( res, testName );
@ -1983,7 +1983,7 @@ void TestQgsLegendRenderer::testColumnsMixedSymbolSize()
QgsLayerTreeModel legendModel( root.get() ); QgsLayerTreeModel legendModel( root.get() );
QgsLegendSettings settings; QgsLegendSettings settings;
settings.setColumnCount( 2 ); settings.setColumnCount( 2 );
settings.rstyle( QgsLegendStyle::Style::Symbol ).setMargin( QgsLegendStyle::Side::Top, 9 ); settings.rstyle( Qgis::LegendComponent::Symbol ).setMargin( QgsLegendStyle::Side::Top, 9 );
setStandardTestFont( settings, QStringLiteral( "Bold" ) ); setStandardTestFont( settings, QStringLiteral( "Bold" ) );
const QImage res = renderLegend( &legendModel, settings ); const QImage res = renderLegend( &legendModel, settings );
@ -2204,7 +2204,7 @@ void TestQgsLegendRenderer::testHeatmap()
QgsLayerTreeModel legendModel( root.get() ); QgsLayerTreeModel legendModel( root.get() );
QgsLegendSettings settings; QgsLegendSettings settings;
settings.rstyle( QgsLegendStyle::Style::Symbol ).setMargin( QgsLegendStyle::Side::Top, 9 ); settings.rstyle( Qgis::LegendComponent::Symbol ).setMargin( QgsLegendStyle::Side::Top, 9 );
setStandardTestFont( settings, QStringLiteral( "Bold" ) ); setStandardTestFont( settings, QStringLiteral( "Bold" ) );
const QImage res = renderLegend( &legendModel, settings ); const QImage res = renderLegend( &legendModel, settings );