27#include <QDomDocument>
37 if (
font.pointSizeF() > 0 )
42 else if (
font.pixelSize() > 0 )
62 QDomElement styleElem = doc.createElement( QStringLiteral(
"style" ) );
64 styleElem.setAttribute( QStringLiteral(
"name" ), name );
65 styleElem.setAttribute( QStringLiteral(
"alignment" ), QString::number( mAlignment ) );
66 styleElem.setAttribute( QStringLiteral(
"indent" ), QString::number( mIndent ) );
69 styleElem.setAttribute( QStringLiteral(
"marginTop" ), QString::number( mMarginMap[
Top] ) );
71 styleElem.setAttribute( QStringLiteral(
"marginBottom" ), QString::number( mMarginMap[
Bottom] ) );
73 styleElem.setAttribute( QStringLiteral(
"marginLeft" ), QString::number( mMarginMap[
Left] ) );
75 styleElem.setAttribute( QStringLiteral(
"marginRight" ), QString::number( mMarginMap[
Right] ) );
77 QDomElement textElem = mTextFormat.
writeXml( doc, context );
78 styleElem.appendChild( textElem );
80 elem.appendChild( styleElem );
86 if ( elem.isNull() )
return;
88 QDomNodeList textFormatNodeList = elem.elementsByTagName( QStringLiteral(
"text-style" ) );
89 if ( !textFormatNodeList.isEmpty() )
91 QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
92 mTextFormat.
readXml( textFormatElem, context );
99 f.fromString( elem.attribute( QStringLiteral(
"font" ) ) );
104 mMarginMap[
Top] = elem.attribute( QStringLiteral(
"marginTop" ), QStringLiteral(
"0" ) ).toDouble();
105 mMarginMap[
Bottom] = elem.attribute( QStringLiteral(
"marginBottom" ), QStringLiteral(
"0" ) ).toDouble();
106 mMarginMap[
Left] = elem.attribute( QStringLiteral(
"marginLeft" ), QStringLiteral(
"0" ) ).toDouble();
107 mMarginMap[
Right] = elem.attribute( QStringLiteral(
"marginRight" ), QStringLiteral(
"0" ) ).toDouble();
109 mAlignment =
static_cast< Qt::Alignment
>( elem.attribute( QStringLiteral(
"alignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
110 mIndent = elem.attribute( QStringLiteral(
"indent" ), QStringLiteral(
"0" ) ).toDouble();
120 return QStringLiteral(
"hidden" );
122 return QStringLiteral(
"title" );
124 return QStringLiteral(
"group" );
126 return QStringLiteral(
"subgroup" );
128 return QStringLiteral(
"symbol" );
130 return QStringLiteral(
"symbolLabel" );
137 if (
styleName == QLatin1String(
"hidden" ) )
139 else if (
styleName == QLatin1String(
"title" ) )
141 else if (
styleName == QLatin1String(
"group" ) )
143 else if (
styleName == QLatin1String(
"subgroup" ) )
145 else if (
styleName == QLatin1String(
"symbol" ) )
147 else if (
styleName == QLatin1String(
"symbolLabel" ) )
157 return QObject::tr(
"Undefined" );
159 return QObject::tr(
"Hidden" );
161 return QObject::tr(
"Title" );
163 return QObject::tr(
"Group" );
165 return QObject::tr(
"Subgroup" );
167 return QObject::tr(
"Symbol" );
169 return QObject::tr(
"Symbol label" );
@ 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 styleLabel(Style s)
Returns a translated string representing a style component, for use in UI.
static Style styleFromName(const QString &styleName)
Returns the style from name string.
void setMargin(Side side, double margin)
Sets the margin (in mm) for the specified side of the component.
void readXml(const QDomElement &elem, const QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext())
Reads the component's style definition from an XML element.
static QString styleName(Style s)
Returns the name for a style component as a string.
double margin(Side side) const
Returns the margin (in mm) for the specified side of the component.
Style
Component of legends which can be styled.
@ Group
Legend group title.
@ Symbol
Symbol icon (excluding label)
@ Undefined
Should not happen, only if corrupted project file.
@ Subgroup
Legend subgroup title.
@ Hidden
Special style, item is hidden including margins around.
@ SymbolLabel
Symbol label (excluding icon)
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.
The class is used as a container of context for various read/write operations on other objects.
void setSize(double size)
Sets the size for rendered text.
void setFont(const QFont &font)
Sets the font used for rendering text.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units for the size of rendered text.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
static QgsTextFormat fromQFont(const QFont &font)
Returns a text format matching the settings from an input font.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)