27 #include <QDomElement>
28 #include <QDomDocument>
48 QDomElement styleElem = doc.createElement( QStringLiteral(
"style" ) );
50 styleElem.setAttribute( QStringLiteral(
"name" ), name );
51 styleElem.setAttribute( QStringLiteral(
"alignment" ), QString::number( mAlignment ) );
52 styleElem.setAttribute( QStringLiteral(
"indent" ), QString::number( mIndent ) );
55 styleElem.setAttribute( QStringLiteral(
"marginTop" ), QString::number( mMarginMap[
Top] ) );
57 styleElem.setAttribute( QStringLiteral(
"marginBottom" ), QString::number( mMarginMap[
Bottom] ) );
59 styleElem.setAttribute( QStringLiteral(
"marginLeft" ), QString::number( mMarginMap[
Left] ) );
61 styleElem.setAttribute( QStringLiteral(
"marginRight" ), QString::number( mMarginMap[
Right] ) );
65 elem.appendChild( styleElem );
71 if ( elem.isNull() )
return;
75 mFont.fromString( elem.attribute( QStringLiteral(
"font" ) ) );
78 mMarginMap[
Top] = elem.attribute( QStringLiteral(
"marginTop" ), QStringLiteral(
"0" ) ).toDouble();
79 mMarginMap[
Bottom] = elem.attribute( QStringLiteral(
"marginBottom" ), QStringLiteral(
"0" ) ).toDouble();
80 mMarginMap[
Left] = elem.attribute( QStringLiteral(
"marginLeft" ), QStringLiteral(
"0" ) ).toDouble();
81 mMarginMap[
Right] = elem.attribute( QStringLiteral(
"marginRight" ), QStringLiteral(
"0" ) ).toDouble();
83 mAlignment =
static_cast< Qt::Alignment
>( elem.attribute( QStringLiteral(
"alignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
84 mIndent = elem.attribute( QStringLiteral(
"indent" ), QStringLiteral(
"0" ) ).toDouble();
94 return QStringLiteral(
"hidden" );
96 return QStringLiteral(
"title" );
98 return QStringLiteral(
"group" );
100 return QStringLiteral(
"subgroup" );
102 return QStringLiteral(
"symbol" );
104 return QStringLiteral(
"symbolLabel" );
111 if (
styleName == QLatin1String(
"hidden" ) )
113 else if (
styleName == QLatin1String(
"title" ) )
115 else if (
styleName == QLatin1String(
"group" ) )
117 else if (
styleName == QLatin1String(
"subgroup" ) )
119 else if (
styleName == QLatin1String(
"symbol" ) )
121 else if (
styleName == QLatin1String(
"symbolLabel" ) )
131 return QObject::tr(
"Undefined" );
133 return QObject::tr(
"Hidden" );
135 return QObject::tr(
"Title" );
137 return QObject::tr(
"Group" );
139 return QObject::tr(
"Subgroup" );
141 return QObject::tr(
"Symbol" );
143 return QObject::tr(
"Symbol label" );
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.
static QDomElement toXmlElement(const QFont &font, QDomDocument &document, const QString &elementName)
Returns a DOM element containing the properties of the font.
double margin(Side side)
Returns the margin (in mm) for the specified side of the 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.
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)
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.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)