25#include <QDomDocument>
38 mTextFormat.setFont(
font );
39 if (
font.pointSizeF() > 0 )
41 mTextFormat.setSize(
font.pointSizeF() );
44 else if (
font.pixelSize() > 0 )
46 mTextFormat.setSize(
font.pixelSize() );
64 QDomElement styleElem = doc.createElement( QStringLiteral(
"style" ) );
66 styleElem.setAttribute( QStringLiteral(
"name" ), name );
67 styleElem.setAttribute( QStringLiteral(
"alignment" ), QString::number( mAlignment ) );
68 styleElem.setAttribute( QStringLiteral(
"indent" ), QString::number( mIndent ) );
71 styleElem.setAttribute( QStringLiteral(
"marginTop" ), QString::number( mMarginMap[
Top] ) );
73 styleElem.setAttribute( QStringLiteral(
"marginBottom" ), QString::number( mMarginMap[
Bottom] ) );
75 styleElem.setAttribute( QStringLiteral(
"marginLeft" ), QString::number( mMarginMap[
Left] ) );
77 styleElem.setAttribute( QStringLiteral(
"marginRight" ), QString::number( mMarginMap[
Right] ) );
79 QDomElement textElem = mTextFormat.writeXml( doc, context );
80 styleElem.appendChild( textElem );
82 elem.appendChild( styleElem );
88 if ( elem.isNull() )
return;
90 QDomNodeList textFormatNodeList = elem.elementsByTagName( QStringLiteral(
"text-style" ) );
91 if ( !textFormatNodeList.isEmpty() )
93 QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
94 mTextFormat.readXml( textFormatElem, context );
101 f.fromString( elem.attribute( QStringLiteral(
"font" ) ) );
106 mMarginMap[
Top] = elem.attribute( QStringLiteral(
"marginTop" ), QStringLiteral(
"0" ) ).toDouble();
107 mMarginMap[
Bottom] = elem.attribute( QStringLiteral(
"marginBottom" ), QStringLiteral(
"0" ) ).toDouble();
108 mMarginMap[
Left] = elem.attribute( QStringLiteral(
"marginLeft" ), QStringLiteral(
"0" ) ).toDouble();
109 mMarginMap[
Right] = elem.attribute( QStringLiteral(
"marginRight" ), QStringLiteral(
"0" ) ).toDouble();
111 mAlignment =
static_cast< Qt::Alignment
>( elem.attribute( QStringLiteral(
"alignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
112 mIndent = elem.attribute( QStringLiteral(
"indent" ), QStringLiteral(
"0" ) ).toDouble();
117 if ( mTextFormat.dataDefinedProperties().hasActiveProperties() )
118 mTextFormat.updateDataDefinedProperties( context );
129 return QStringLiteral(
"hidden" );
131 return QStringLiteral(
"title" );
133 return QStringLiteral(
"group" );
135 return QStringLiteral(
"subgroup" );
137 return QStringLiteral(
"symbol" );
139 return QStringLiteral(
"symbolLabel" );
146 if (
styleName == QLatin1String(
"hidden" ) )
148 else if (
styleName == QLatin1String(
"title" ) )
150 else if (
styleName == QLatin1String(
"group" ) )
152 else if (
styleName == QLatin1String(
"subgroup" ) )
154 else if (
styleName == QLatin1String(
"symbol" ) )
156 else if (
styleName == QLatin1String(
"symbolLabel" ) )
166 return QObject::tr(
"Undefined" );
168 return QObject::tr(
"Hidden" );
170 return QObject::tr(
"Title" );
172 return QObject::tr(
"Group" );
174 return QObject::tr(
"Subgroup" );
176 return QObject::tr(
"Symbol" );
178 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).