25#include <QDomDocument>
32using namespace Qt::StringLiterals;
40 mTextFormat.setFont(
font );
41 if (
font.pointSizeF() > 0 )
43 mTextFormat.setSize(
font.pointSizeF() );
46 else if (
font.pixelSize() > 0 )
48 mTextFormat.setSize(
font.pixelSize() );
66 QDomElement styleElem = doc.createElement( u
"style"_s );
68 styleElem.setAttribute( u
"name"_s, name );
69 styleElem.setAttribute( u
"alignment"_s, QString::number( mAlignment ) );
70 styleElem.setAttribute( u
"indent"_s, QString::number( mIndent ) );
73 styleElem.setAttribute( u
"marginTop"_s, QString::number( mMarginMap[
Top] ) );
75 styleElem.setAttribute( u
"marginBottom"_s, QString::number( mMarginMap[
Bottom] ) );
77 styleElem.setAttribute( u
"marginLeft"_s, QString::number( mMarginMap[
Left] ) );
79 styleElem.setAttribute( u
"marginRight"_s, QString::number( mMarginMap[
Right] ) );
81 QDomElement textElem = mTextFormat.writeXml( doc, context );
82 styleElem.appendChild( textElem );
84 elem.appendChild( styleElem );
90 if ( elem.isNull() )
return;
92 QDomNodeList textFormatNodeList = elem.elementsByTagName( u
"text-style"_s );
93 if ( !textFormatNodeList.isEmpty() )
95 QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
96 mTextFormat.readXml( textFormatElem, context );
103 f.fromString( elem.attribute( u
"font"_s ) );
108 mMarginMap[
Top] = elem.attribute( u
"marginTop"_s, u
"0"_s ).toDouble();
109 mMarginMap[
Bottom] = elem.attribute( u
"marginBottom"_s, u
"0"_s ).toDouble();
110 mMarginMap[
Left] = elem.attribute( u
"marginLeft"_s, u
"0"_s ).toDouble();
111 mMarginMap[
Right] = elem.attribute( u
"marginRight"_s, u
"0"_s ).toDouble();
113 mAlignment =
static_cast< Qt::Alignment
>( elem.attribute( u
"alignment"_s, QString::number( Qt::AlignLeft ) ).toInt() );
114 mIndent = elem.attribute( u
"indent"_s, u
"0"_s ).toDouble();
119 if ( mTextFormat.dataDefinedProperties().hasActiveProperties() )
120 mTextFormat.updateDataDefinedProperties( context );
137 return u
"subgroup"_s;
141 return u
"symbolLabel"_s;
158 else if (
styleName ==
"symbolLabel"_L1 )
168 return QObject::tr(
"Undefined" );
170 return QObject::tr(
"Hidden" );
172 return QObject::tr(
"Title" );
174 return QObject::tr(
"Group" );
176 return QObject::tr(
"Subgroup" );
178 return QObject::tr(
"Symbol" );
180 return QObject::tr(
"Symbol label" );
LegendComponent
Component of legends which can be styled.
@ Symbol
Symbol icon (excluding label).
@ Group
Legend group title.
@ Hidden
Special style, item is hidden including margins around.
@ Subgroup
Legend subgroup title.
@ SymbolLabel
Symbol label (excluding icon).
@ Undefined
Should not happen, only if corrupted project file.
@ Points
Points (e.g., for font sizes).
static bool setFromXmlChildNode(QFont &font, const QDomElement &element, const QString &childNode)
Sets the properties of a font to match the properties stored in an XML child node.
Q_DECL_DEPRECATED QFont font() const
Returns the font used for rendering this legend component.
static QString styleName(Qgis::LegendComponent s)
Returns the name for a style component as a string.
void setMargin(Side side, double margin)
Sets the margin (in mm) for the specified side of the component.
void updateDataDefinedProperties(QgsRenderContext &context)
Updates any data-defined properties in the style, using the specified render context.
void readXml(const QDomElement &elem, const QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext())
Reads the component's style definition from an XML element.
double margin(Side side) const
Returns the margin (in mm) for the specified side of the component.
static Qgis::LegendComponent styleFromName(const QString &styleName)
Returns the style from name string.
Q_DECL_DEPRECATED void setFont(const QFont &font)
Sets the font used for rendering this legend component.
void writeXml(const QString &name, QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext()) const
Writes the component's style definition to an XML element.
static QString styleLabel(Qgis::LegendComponent s)
Returns a translated string representing a style component, for use in UI.
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
static QgsTextFormat fromQFont(const QFont &font)
Returns a text format matching the settings from an input font.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).