26 #include <QDomElement> 27 #include <QDomDocument> 47 QDomElement styleElem = doc.createElement( QStringLiteral(
"style" ) );
49 styleElem.setAttribute( QStringLiteral(
"name" ), name );
50 styleElem.setAttribute( QStringLiteral(
"alignment" ), QString::number( mAlignment ) );
53 styleElem.setAttribute( QStringLiteral(
"marginTop" ), QString::number( mMarginMap[Top] ) );
55 styleElem.setAttribute( QStringLiteral(
"marginBottom" ), QString::number( mMarginMap[Bottom] ) );
57 styleElem.setAttribute( QStringLiteral(
"marginLeft" ), QString::number( mMarginMap[Left] ) );
59 styleElem.setAttribute( QStringLiteral(
"marginRight" ), QString::number( mMarginMap[Right] ) );
63 elem.appendChild( styleElem );
69 if ( elem.isNull() )
return;
73 mFont.fromString( elem.attribute( QStringLiteral(
"font" ) ) );
76 mMarginMap[
Top] = elem.attribute( QStringLiteral(
"marginTop" ), QStringLiteral(
"0" ) ).toDouble();
77 mMarginMap[
Bottom] = elem.attribute( QStringLiteral(
"marginBottom" ), QStringLiteral(
"0" ) ).toDouble();
78 mMarginMap[
Left] = elem.attribute( QStringLiteral(
"marginLeft" ), QStringLiteral(
"0" ) ).toDouble();
79 mMarginMap[
Right] = elem.attribute( QStringLiteral(
"marginRight" ), QStringLiteral(
"0" ) ).toDouble();
81 mAlignment =
static_cast< Qt::Alignment
>( elem.attribute( QStringLiteral(
"alignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
91 return QStringLiteral(
"hidden" );
93 return QStringLiteral(
"title" );
95 return QStringLiteral(
"group" );
97 return QStringLiteral(
"subgroup" );
99 return QStringLiteral(
"symbol" );
101 return QStringLiteral(
"symbolLabel" );
108 if ( styleName == QLatin1String(
"hidden" ) )
110 else if ( styleName == QLatin1String(
"title" ) )
112 else if ( styleName == QLatin1String(
"group" ) )
114 else if ( styleName == QLatin1String(
"subgroup" ) )
116 else if ( styleName == QLatin1String(
"symbol" ) )
118 else if ( styleName == QLatin1String(
"symbolLabel" ) )
128 return QObject::tr(
"Undefined" );
130 return QObject::tr(
"Hidden" );
132 return QObject::tr(
"Title" );
134 return QObject::tr(
"Group" );
136 return QObject::tr(
"Subgroup" );
138 return QObject::tr(
"Symbol" );
140 return QObject::tr(
"Symbol label" );
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
double margin(Side side)
Returns the margin (in mm) for the specified side of the component.
static Style styleFromName(const QString &styleName)
Returns the style from name string.
Should not happen, only if corrupted project file.
Symbol icon (excluding 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.
void setMargin(Side side, double margin)
Sets 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.
Style
Component of legends which can be styled.
static QString styleName(Style s)
Returns the name for a style component as a string.
void readXml(const QDomElement &elem, const QDomDocument &doc)
Reads the component's style definition from an XML element.
Special style, item is hidden including margins around.
void writeXml(const QString &name, QDomElement &elem, QDomDocument &doc) const
Writes the component's style definition to an XML element.
static QDomElement toXmlElement(const QFont &font, QDomDocument &document, const QString &elementName)
Returns a DOM element containing the properties of the font.
Symbol label (excluding icon)