20 #include "qgssettings.h" 
   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 ) );
 
   54     styleElem.setAttribute( QStringLiteral( 
"marginTop" ), QString::number( mMarginMap[
Top] ) );
 
   56     styleElem.setAttribute( QStringLiteral( 
"marginBottom" ), QString::number( mMarginMap[
Bottom] ) );
 
   58     styleElem.setAttribute( QStringLiteral( 
"marginLeft" ), QString::number( mMarginMap[
Left] ) );
 
   60     styleElem.setAttribute( QStringLiteral( 
"marginRight" ), QString::number( mMarginMap[
Right] ) );
 
   64   elem.appendChild( styleElem );
 
   70   if ( elem.isNull() ) 
return;
 
   74     mFont.fromString( elem.attribute( QStringLiteral( 
"font" ) ) );
 
   77   mMarginMap[
Top] = elem.attribute( QStringLiteral( 
"marginTop" ), QStringLiteral( 
"0" ) ).toDouble();
 
   78   mMarginMap[
Bottom] = elem.attribute( QStringLiteral( 
"marginBottom" ), QStringLiteral( 
"0" ) ).toDouble();
 
   79   mMarginMap[
Left] = elem.attribute( QStringLiteral( 
"marginLeft" ), QStringLiteral( 
"0" ) ).toDouble();
 
   80   mMarginMap[
Right] = elem.attribute( QStringLiteral( 
"marginRight" ), QStringLiteral( 
"0" ) ).toDouble();
 
   82   mAlignment = 
static_cast< Qt::Alignment 
>( elem.attribute( QStringLiteral( 
"alignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
 
   92       return QStringLiteral( 
"hidden" );
 
   94       return QStringLiteral( 
"title" );
 
   96       return QStringLiteral( 
"group" );
 
   98       return QStringLiteral( 
"subgroup" );
 
  100       return QStringLiteral( 
"symbol" );
 
  102       return QStringLiteral( 
"symbolLabel" );
 
  109   if ( 
styleName == QLatin1String( 
"hidden" ) )
 
  111   else if ( 
styleName == QLatin1String( 
"title" ) )
 
  113   else if ( 
styleName == QLatin1String( 
"group" ) )
 
  115   else if ( 
styleName == QLatin1String( 
"subgroup" ) )
 
  117   else if ( 
styleName == QLatin1String( 
"symbol" ) )
 
  119   else if ( 
styleName == QLatin1String( 
"symbolLabel" ) )
 
  129       return QObject::tr( 
"Undefined" );
 
  131       return QObject::tr( 
"Hidden" );
 
  133       return QObject::tr( 
"Title" );
 
  135       return QObject::tr( 
"Group" );
 
  137       return QObject::tr( 
"Subgroup" );
 
  139       return QObject::tr( 
"Symbol" );
 
  141       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)