28#include <QDomDocument> 
   38  if ( 
font.pointSizeF() > 0 )
 
   43  else if ( 
font.pixelSize() > 0 )
 
 
   63  QDomElement styleElem = doc.createElement( QStringLiteral( 
"style" ) );
 
   65  styleElem.setAttribute( QStringLiteral( 
"name" ), name );
 
   66  styleElem.setAttribute( QStringLiteral( 
"alignment" ), QString::number( mAlignment ) );
 
   67  styleElem.setAttribute( QStringLiteral( 
"indent" ), QString::number( mIndent ) );
 
   70    styleElem.setAttribute( QStringLiteral( 
"marginTop" ), QString::number( mMarginMap[
Top] ) );
 
   72    styleElem.setAttribute( QStringLiteral( 
"marginBottom" ), QString::number( mMarginMap[
Bottom] ) );
 
   74    styleElem.setAttribute( QStringLiteral( 
"marginLeft" ), QString::number( mMarginMap[
Left] ) );
 
   76    styleElem.setAttribute( QStringLiteral( 
"marginRight" ), QString::number( mMarginMap[
Right] ) );
 
   78  QDomElement textElem = mTextFormat.
writeXml( doc, context );
 
   79  styleElem.appendChild( textElem );
 
   81  elem.appendChild( styleElem );
 
 
   87  if ( elem.isNull() ) 
return;
 
   89  QDomNodeList textFormatNodeList = elem.elementsByTagName( QStringLiteral( 
"text-style" ) );
 
   90  if ( !textFormatNodeList.isEmpty() )
 
   92    QDomElement textFormatElem = textFormatNodeList.at( 0 ).toElement();
 
   93    mTextFormat.
readXml( textFormatElem, context );
 
  100      f.fromString( elem.attribute( QStringLiteral( 
"font" ) ) );
 
  105  mMarginMap[
Top] = elem.attribute( QStringLiteral( 
"marginTop" ), QStringLiteral( 
"0" ) ).toDouble();
 
  106  mMarginMap[
Bottom] = elem.attribute( QStringLiteral( 
"marginBottom" ), QStringLiteral( 
"0" ) ).toDouble();
 
  107  mMarginMap[
Left] = elem.attribute( QStringLiteral( 
"marginLeft" ), QStringLiteral( 
"0" ) ).toDouble();
 
  108  mMarginMap[
Right] = elem.attribute( QStringLiteral( 
"marginRight" ), QStringLiteral( 
"0" ) ).toDouble();
 
  110  mAlignment = 
static_cast< Qt::Alignment 
>( elem.attribute( QStringLiteral( 
"alignment" ), QString::number( Qt::AlignLeft ) ).toInt() );
 
  111  mIndent = elem.attribute( QStringLiteral( 
"indent" ), QStringLiteral( 
"0" ) ).toDouble();
 
 
  128      return QStringLiteral( 
"hidden" );
 
  130      return QStringLiteral( 
"title" );
 
  132      return QStringLiteral( 
"group" );
 
  134      return QStringLiteral( 
"subgroup" );
 
  136      return QStringLiteral( 
"symbol" );
 
  138      return QStringLiteral( 
"symbolLabel" );
 
 
  145  if ( 
styleName == QLatin1String( 
"hidden" ) )
 
  147  else if ( 
styleName == QLatin1String( 
"title" ) )
 
  149  else if ( 
styleName == QLatin1String( 
"group" ) )
 
  151  else if ( 
styleName == QLatin1String( 
"subgroup" ) )
 
  153  else if ( 
styleName == QLatin1String( 
"symbol" ) )
 
  155  else if ( 
styleName == QLatin1String( 
"symbolLabel" ) )
 
 
  165      return QObject::tr( 
"Undefined" );
 
  167      return QObject::tr( 
"Hidden" );
 
  169      return QObject::tr( 
"Title" );
 
  171      return QObject::tr( 
"Group" );
 
  173      return QObject::tr( 
"Subgroup" );
 
  175      return QObject::tr( 
"Symbol" );
 
  177      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.
 
bool hasActiveProperties() const final
Returns true if the collection has any active properties, or false if all properties within the colle...
 
A container for the context for various read/write operations on objects.
 
Contains information about the context of a rendering operation.
 
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 updateDataDefinedProperties(QgsRenderContext &context)
Updates the format by evaluating current values of data defined properties.
 
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the format's property collection, used for data defined overrides.
 
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)