28 #include <QJsonObject>    34   : mLegendModel( legendModel )
    35   , mSettings( settings )
    41   return paintAndDetermineSize( renderContext );
    46   paintAndDetermineSize( painter );
    55   json[QStringLiteral( 
"title" )] = mSettings.
title();
    62   const QList<QgsLayerTreeNode *> childNodes = nodeGroup->
children();
    68       const QModelIndex idx = mLegendModel->
node2index( nodeGroup );
    69       const QString text = mLegendModel->
data( idx, Qt::DisplayRole ).toString();
    72       group[ QStringLiteral( 
"type" ) ] = QStringLiteral( 
"group" );
    73       group[ QStringLiteral( 
"title" ) ] = text;
    75       nodes.append( group );
    80       group[ QStringLiteral( 
"type" ) ] = QStringLiteral( 
"layer" );
    87         const QModelIndex idx = mLegendModel->
node2index( nodeLayer );
    88         text = mLegendModel->
data( idx, Qt::DisplayRole ).toString();
    91       QList<QgsLayerTreeModelLegendNode *> legendNodes = mLegendModel->
layerLegendNodes( nodeLayer );
    96       if ( legendNodes.count() == 1 )
    98         legendNodes.at( 0 )->exportToJson( mSettings, context, group );
    99         nodes.append( group );
   101       else if ( legendNodes.count() > 1 )
   104         for ( 
int j = 0; j < legendNodes.count(); j++ )
   109           symbols.append( symbol );
   111         group[ QStringLiteral( 
"title" ) ] = text;
   112         group[ QStringLiteral( 
"symbols" ) ] = symbols;
   113         nodes.append( group );
   118   json[QStringLiteral( 
"nodes" )] = nodes;
   121 QSizeF QgsLegendRenderer::paintAndDetermineSize( QPainter *painter )
   123   return paintAndDetermineSizeInternal( 
nullptr, painter );
   126 QSizeF QgsLegendRenderer::paintAndDetermineSizeInternal( 
QgsRenderContext *context, QPainter *painter )
   135   QPainter *prevPainter = context ? context->
painter() : 
nullptr;
   139   QList<LegendComponentGroup> componentGroups = createComponentGroupList( rootGroup, mSettings.
splitLayer(), context );
   141   setColumns( componentGroups );
   143   QMap< int, double > maxColumnWidths;
   144   qreal maxEqualColumnWidth = 0;
   152   for ( 
const LegendComponentGroup &group : qgis::as_const( componentGroups ) )
   154     const QSizeF actualSize = drawGroup( group, context, ColumnContext() );
   155     maxEqualColumnWidth = std::max( actualSize.width(), maxEqualColumnWidth );
   156     maxColumnWidths[ group.column ] = std::max( actualSize.width(), maxColumnWidths.value( group.column, 0 ) );
   164     maxEqualColumnWidth = std::max( maxEqualColumnWidth, mLegendSize.width() - 2 * mSettings.
boxSpace() );
   165     maxColumnWidths[ 0 ] = maxEqualColumnWidth;
   169   QSizeF titleSize = drawTitle();
   171   titleSize.rwidth() += mSettings.
boxSpace() * 2.0;
   174   bool firstInColumn = 
true;
   175   double columnMaxHeight = 0;
   176   qreal columnWidth = 0;
   178   ColumnContext columnContext;
   179   columnContext.left = mSettings.
boxSpace();
   180   columnContext.right = std::max( mLegendSize.width() - mSettings.
boxSpace(), mSettings.
boxSpace() );
   181   double currentY = columnTop;
   183   for ( 
const LegendComponentGroup &group : qgis::as_const( componentGroups ) )
   185     if ( group.column > column )
   188       columnContext.left = group.column > 0 ? columnContext.right + mSettings.
columnSpace() : mSettings.
boxSpace();
   189       columnWidth = mSettings.
equalColumnWidth() ? maxEqualColumnWidth : maxColumnWidths.value( group.column );
   190       columnContext.right = columnContext.left + columnWidth;
   191       currentY = columnTop;
   193       firstInColumn = 
true;
   195     if ( !firstInColumn )
   197       currentY += spaceAboveGroup( group );
   201       drawGroup( group, context, columnContext, currentY );
   203       drawGroup( group, columnContext, painter, currentY );
   205     currentY += group.size.height();
   206     columnMaxHeight = std::max( currentY - columnTop, columnMaxHeight );
   208     firstInColumn = 
false;
   210   const double totalWidth = columnContext.right + mSettings.
boxSpace();
   212   size.rheight() = columnTop + columnMaxHeight + mSettings.
boxSpace();
   213   size.rwidth() = totalWidth;
   214   if ( !mSettings.
title().isEmpty() )
   216     size.rwidth() = std::max( titleSize.width(), size.width() );
   220   if ( mLegendSize.isValid() )
   222     qreal w = std::max( size.width(), mLegendSize.width() );
   223     qreal h = std::max( size.height(), mLegendSize.height() );
   224     size = QSizeF( w, h );
   228   if ( !mSettings.
title().isEmpty() )
   239 void QgsLegendRenderer::widthAndOffsetForTitleText( 
const Qt::AlignmentFlag halignment, 
const double legendWidth, 
double &textBoxWidth, 
double &textBoxLeft )
   241   switch ( halignment )
   245       textBoxWidth = legendWidth - 2 * mSettings.
boxSpace();
   248     case Qt::AlignHCenter:
   251       const double centerX = legendWidth / 2;
   252       textBoxWidth = ( std::min( static_cast< double >( centerX ), legendWidth - centerX ) - mSettings.
boxSpace() ) * 2.0;
   253       textBoxLeft = centerX - textBoxWidth / 2.;
   259 QList<QgsLegendRenderer::LegendComponentGroup> QgsLegendRenderer::createComponentGroupList( 
QgsLayerTreeGroup *parentGroup, 
bool splitLayer, 
QgsRenderContext *context )
   261   QList<LegendComponentGroup> componentGroups;
   264     return componentGroups;
   266   const QList<QgsLayerTreeNode *> childNodes = parentGroup->
children();
   274       QList<LegendComponentGroup> subgroups = createComponentGroupList( nodeGroup, splitLayer, context );
   275       bool hasSubItems = !subgroups.empty();
   279         LegendComponent component;
   280         component.item = node;
   281         component.size = drawGroupTitle( nodeGroup );
   283         if ( !subgroups.isEmpty() )
   286           subgroups[0].size.rheight() += spaceAboveGroup( subgroups[0] );
   288           subgroups[0].components.prepend( component );
   289           subgroups[0].size.rheight() += component.size.height();
   290           subgroups[0].size.rwidth() = std::max( component.size.width(), subgroups[0].size.width() );
   295           LegendComponentGroup group;
   296           group.components.append( component );
   297           group.size.rwidth() += component.size.width();
   298           group.size.rheight() += component.size.height();
   299           group.size.rwidth() = std::max( component.size.width(), group.size.width() );
   300           subgroups.append( group );
   306         componentGroups.append( subgroups );
   314       LegendComponentGroup group;
   318         LegendComponent component;
   319         component.item = node;
   320         component.size = drawLayerTitle( nodeLayer );
   321         group.components.append( component );
   322         group.size.rwidth() = component.size.width();
   323         group.size.rheight() = component.size.height();
   326       QList<QgsLayerTreeModelLegendNode *> legendNodes = mLegendModel->
layerLegendNodes( nodeLayer );
   334       QList<LegendComponentGroup> layerGroups;
   335       layerGroups.reserve( legendNodes.count() );
   337       for ( 
int j = 0; j < legendNodes.count(); j++ )
   341         LegendComponent symbolComponent = drawSymbolItem( legendNode, context, ColumnContext(), 0 );
   347           group.size.rwidth() = std::max( symbolComponent.size.width(), group.size.width() );
   349           if ( !group.components.isEmpty() )
   354           group.size.rheight() += symbolComponent.size.height();
   355           group.components.append( symbolComponent );
   359           LegendComponentGroup symbolGroup;
   360           symbolGroup.components.append( symbolComponent );
   361           symbolGroup.size.rwidth() = symbolComponent.size.width();
   362           symbolGroup.size.rheight() = symbolComponent.size.height();
   363           layerGroups.append( symbolGroup );
   366       layerGroups.prepend( group );
   367       componentGroups.append( layerGroups );
   371   return componentGroups;
   375 void QgsLegendRenderer::setColumns( QList<LegendComponentGroup> &componentGroups )
   381   double totalHeight = 0;
   382   qreal maxGroupHeight = 0;
   383   for ( 
const LegendComponentGroup &group : qgis::as_const( componentGroups ) )
   385     totalHeight += spaceAboveGroup( group );
   386     totalHeight += group.size.height();
   387     maxGroupHeight = std::max( group.size.height(), maxGroupHeight );
   395   double maxColumnHeight = 0;
   396   int currentColumn = 0;
   397   int currentColumnGroupCount = 0; 
   398   double currentColumnHeight = 0;
   399   double closedColumnsHeight = 0;
   401   for ( 
int i = 0; i < componentGroups.size(); i++ )
   404     double avgColumnHeight = ( totalHeight - closedColumnsHeight ) / ( mSettings.
columnCount() - currentColumn );
   406     LegendComponentGroup group = componentGroups.at( i );
   407     double currentHeight = currentColumnHeight;
   408     if ( currentColumnGroupCount > 0 )
   409       currentHeight += spaceAboveGroup( group );
   410     currentHeight += group.size.height();
   412     bool canCreateNewColumn = ( currentColumnGroupCount > 0 )  
   413                               && ( currentColumn < mSettings.
columnCount() - 1 ); 
   415     bool shouldCreateNewColumn = ( currentHeight - avgColumnHeight ) > group.size.height() / 2  
   416                                  && currentColumnGroupCount > 0 
   417                                  && currentHeight > maxGroupHeight  
   418                                  && currentHeight > maxColumnHeight; 
   422     shouldCreateNewColumn |= ( componentGroups.size() - i < mSettings.
columnCount() - currentColumn );
   424     if ( canCreateNewColumn && shouldCreateNewColumn )
   428       currentColumnGroupCount = 0;
   429       closedColumnsHeight += currentColumnHeight;
   430       currentColumnHeight = group.size.height();
   434       currentColumnHeight = currentHeight;
   436     componentGroups[i].column = currentColumn;
   437     currentColumnGroupCount++;
   438     maxColumnHeight = std::max( currentColumnHeight, maxColumnHeight );
   442   QMap<QString, qreal> maxSymbolWidth;
   443   for ( 
int i = 0; i < componentGroups.size(); i++ )
   445     LegendComponentGroup &group = componentGroups[i];
   446     for ( 
int j = 0; j < group.components.size(); j++ )
   450         QString key = QStringLiteral( 
"%1-%2" ).arg( reinterpret_cast< qulonglong >( 
legendNode->
layerNode() ) ).arg( group.column );
   451         maxSymbolWidth[key] = std::max( group.components.at( j ).symbolSize.width(), maxSymbolWidth[key] );
   455   for ( 
int i = 0; i < componentGroups.size(); i++ )
   457     LegendComponentGroup &group = componentGroups[i];
   458     for ( 
int j = 0; j < group.components.size(); j++ )
   462         QString key = QStringLiteral( 
"%1-%2" ).arg( reinterpret_cast< qulonglong >( 
legendNode->
layerNode() ) ).arg( group.column );
   465         group.components[j].labelXOffset = maxSymbolWidth[key] + space;
   466         group.components[j].maxSiblingSymbolWidth = maxSymbolWidth[key];
   467         group.components[j].size.rwidth() = maxSymbolWidth[key] + space + group.components.at( j ).labelSize.width();
   473 QSizeF QgsLegendRenderer::drawTitle( QPainter *painter, 
double top, Qt::AlignmentFlag halignment, 
double legendWidth )
   475   return drawTitleInternal( 
nullptr, painter, top, halignment, legendWidth );
   478 QSizeF QgsLegendRenderer::drawTitleInternal( 
QgsRenderContext *context, QPainter *painter, 
const double top, Qt::AlignmentFlag halignment, 
double legendWidth )
   481   if ( mSettings.
title().isEmpty() )
   489   if ( context && context->
painter() )
   495     painter->setPen( mSettings.
fontColor() );
   501   widthAndOffsetForTitleText( halignment, legendWidth, textBoxWidth, textBoxLeft );
   505   for ( QStringList::Iterator titlePart = lines.begin(); titlePart != lines.end(); ++titlePart )
   512     QRectF r( textBoxLeft, y, textBoxWidth, height );
   514     if ( context && context->
painter() )
   516       mSettings.
drawText( context->
painter(), r, *titlePart, titleFont, halignment, Qt::AlignVCenter, Qt::TextDontClip );
   520       mSettings.
drawText( painter, r, *titlePart, titleFont, halignment, Qt::AlignVCenter, Qt::TextDontClip );
   524     size.rwidth() = std::max( width, size.rwidth() );
   527     if ( titlePart != ( lines.end() - 1 ) )
   532   size.rheight() = y - top;
   538 double QgsLegendRenderer::spaceAboveGroup( 
const LegendComponentGroup &group )
   540   if ( group.components.isEmpty() ) 
return 0;
   542   LegendComponent component = group.components.first();
   544   if ( 
QgsLayerTreeGroup *nodeGroup = qobject_cast<QgsLayerTreeGroup *>( component.item ) )
   548   else if ( 
QgsLayerTreeLayer *nodeLayer = qobject_cast<QgsLayerTreeLayer *>( component.item ) )
   552   else if ( qobject_cast<QgsLayerTreeModelLegendNode *>( component.item ) )
   561 QSizeF QgsLegendRenderer::drawGroup( 
const LegendComponentGroup &group, ColumnContext columnContext, QPainter *painter, 
double top )
   563   return drawGroupInternal( group, 
nullptr, columnContext, painter, top );
   566 QSizeF QgsLegendRenderer::drawGroupInternal( 
const LegendComponentGroup &group, 
QgsRenderContext *context, ColumnContext columnContext, QPainter *painter, 
const double top )
   569   QSizeF size = QSizeF( group.size );
   570   double currentY = top;
   571   for ( 
const LegendComponent &component : qgis::as_const( group.components ) )
   573     if ( 
QgsLayerTreeGroup *groupItem = qobject_cast<QgsLayerTreeGroup *>( component.item ) )
   584           groupSize = drawGroupTitle( groupItem, context, columnContext, currentY );
   586           groupSize = drawGroupTitle( groupItem, columnContext, painter, currentY );
   587         size.rwidth() = std::max( groupSize.width(), size.width() );
   590     else if ( 
QgsLayerTreeLayer *layerItem = qobject_cast<QgsLayerTreeLayer *>( component.item ) )
   601           subGroupSize = drawLayerTitle( layerItem, context, columnContext, currentY );
   603           subGroupSize = drawLayerTitle( layerItem, columnContext, painter, currentY );
   604         size.rwidth() = std::max( subGroupSize.width(), size.width() );
   614       LegendComponent symbolComponent = context ? drawSymbolItem( 
legendNode, context, columnContext, currentY, component.maxSiblingSymbolWidth )
   615                                         : drawSymbolItem( 
legendNode, columnContext, painter, currentY, component.maxSiblingSymbolWidth );
   617       size.rwidth() = std::max( symbolComponent.size.width(), size.width() );
   619     currentY += component.size.height();
   625 QgsLegendRenderer::LegendComponent QgsLegendRenderer::drawSymbolItem( 
QgsLayerTreeModelLegendNode *symbolItem, ColumnContext columnContext, QPainter *painter, 
double top, 
double maxSiblingSymbolWidth )
   627   return drawSymbolItemInternal( symbolItem, columnContext, 
nullptr, painter, top, maxSiblingSymbolWidth );
   630 QgsLegendRenderer::LegendComponent QgsLegendRenderer::drawSymbolItemInternal( 
QgsLayerTreeModelLegendNode *symbolItem, ColumnContext columnContext, 
QgsRenderContext *context, QPainter *painter, 
double top, 
double maxSiblingSymbolWidth )
   645   ctx.
point = QPointF( columnContext.left, top );
   655       : ( painter ? &ctx : 
nullptr ) );
   660   LegendComponent component;
   661   component.item = symbolItem;
   668   double width = std::max( static_cast< double >( im.
symbolSize.width() ), maxSiblingSymbolWidth )
   674   component.size = QSizeF( width, height );
   678 QSizeF QgsLegendRenderer::drawLayerTitle( 
QgsLayerTreeLayer *nodeLayer, ColumnContext columnContext, QPainter *painter, 
double top )
   680   return drawLayerTitleInternal( nodeLayer, columnContext, 
nullptr, painter, top );
   683 QSizeF QgsLegendRenderer::drawLayerTitleInternal( 
QgsLayerTreeLayer *nodeLayer, ColumnContext columnContext, 
QgsRenderContext *context, QPainter *painter, 
const double top )
   686   QModelIndex idx = mLegendModel->
node2index( nodeLayer );
   687   QString titleString = mLegendModel->
data( idx, Qt::DisplayRole ).toString();
   689   if ( titleString.isEmpty() )
   694   if ( context && context->
painter() )
   702   if ( context && nodeLayer->
layer() )
   713   for ( QStringList::ConstIterator layerItemPart = lines.constBegin(); layerItemPart != lines.constEnd(); ++layerItemPart )
   716     if ( QPainter *destPainter = context && context->
painter() ? context->
painter() : painter )
   718       double x = columnContext.left;
   723           x = columnContext.right - labelWidth;
   725           x = columnContext.left + ( columnContext.right - columnContext.left - labelWidth ) / 2;
   727       mSettings.
drawText( destPainter, x, y, *layerItemPart, layerFont );
   730     size.rwidth() = std::max( width, size.width() );
   731     if ( layerItemPart != ( lines.end() - 1 ) )
   737   size.rheight() = y - top;
   746 QSizeF QgsLegendRenderer::drawGroupTitle( 
QgsLayerTreeGroup *nodeGroup, ColumnContext columnContext, QPainter *painter, 
double top )
   748   return drawGroupTitleInternal( nodeGroup, columnContext, 
nullptr, painter, top );
   751 QSizeF QgsLegendRenderer::drawGroupTitleInternal( 
QgsLayerTreeGroup *nodeGroup, ColumnContext columnContext, 
QgsRenderContext *context, QPainter *painter, 
const double top )
   754   QModelIndex idx = mLegendModel->
node2index( nodeGroup );
   758   if ( context && context->
painter() )
   761     painter->setPen( mSettings.
fontColor() );
   767   const QStringList lines = mSettings.
evaluateItemText( mLegendModel->
data( idx, Qt::DisplayRole ).toString(),
   769   for ( QStringList::ConstIterator groupPart = lines.constBegin(); groupPart != lines.constEnd(); ++groupPart )
   773     if ( QPainter *destPainter = context && context->
painter() ? context->
painter() : painter )
   775       double x = columnContext.left;
   780           x = columnContext.right - labelWidth;
   782           x = columnContext.left + ( columnContext.right - columnContext.left - labelWidth ) / 2;
   784       mSettings.
drawText( destPainter, x, y, *groupPart, groupFont );
   787     size.rwidth() = std::max( width, size.width() );
   788     if ( groupPart != ( lines.end() - 1 ) )
   799   QString style = node->
customProperty( QStringLiteral( 
"legend/title-style" ) ).toString();
   800   if ( style == QLatin1String( 
"hidden" ) )
   802   else if ( style == QLatin1String( 
"group" ) )
   804   else if ( style == QLatin1String( 
"subgroup" ) )
   831       str = QStringLiteral( 
"hidden" );
   834       str = QStringLiteral( 
"group" );
   837       str = QStringLiteral( 
"subgroup" );
   843   if ( !str.isEmpty() )
   849 QSizeF QgsLegendRenderer::drawTitle( 
QgsRenderContext *rendercontext, 
double top, Qt::AlignmentFlag halignment, 
double legendWidth )
   851   return drawTitleInternal( rendercontext, 
nullptr, top, halignment, legendWidth );
   854 QSizeF QgsLegendRenderer::drawGroup( 
const LegendComponentGroup &group, 
QgsRenderContext *rendercontext, ColumnContext columnContext, 
double top )
   856   return drawGroupInternal( group, rendercontext, columnContext, 
nullptr, top );
   859 QgsLegendRenderer::LegendComponent QgsLegendRenderer::drawSymbolItem( 
QgsLayerTreeModelLegendNode *symbolItem, 
QgsRenderContext *rendercontext, ColumnContext columnContext, 
double top, 
double maxSiblingSymbolWidth )
   861   return drawSymbolItemInternal( symbolItem, columnContext, rendercontext, 
nullptr, top, maxSiblingSymbolWidth );
   866   return drawLayerTitleInternal( nodeLayer, columnContext, rendercontext, 
nullptr, top );
   871   return drawGroupTitleInternal( nodeGroup, columnContext, rendercontext, 
nullptr, top );
   876   paintAndDetermineSize( &context );
   879 QSizeF QgsLegendRenderer::paintAndDetermineSize( 
QgsRenderContext *context )
   881   return paintAndDetermineSizeInternal( context, 
nullptr );
 static void setNodeLegendStyle(QgsLayerTreeNode *node, QgsLegendStyle::Style style)
Sets the style of a node. 
 
Q_NOWARN_DEPRECATED_POP QgsRenderContext * context
Render context, if available. 
 
Layer tree group node serves as a container for layers and further groups. 
 
void drawText(QPainter *p, double x, double y, const QString &text, const QFont &font) const
Draws Text. 
 
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer. 
 
double columnRight
Right side of current legend column. 
 
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node. 
 
double fontAscentMillimeters(const QFont &font) const
Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCAL...
 
QStringList evaluateItemText(const QString &text, const QgsExpressionContext &context) const
Splits a string using the wrap char taking into account handling empty wrap char which means no wrapp...
 
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group. 
 
void drawLegend(QPainter *painter)
Draws the legend with given painter. 
 
QStringList splitStringForWrapping(const QString &stringToSplt) const
Splits a string using the wrap char taking into account handling empty wrap char which means no wrapp...
 
QgsLayerTreeModelLegendNode * legendNodeEmbeddedInParent(QgsLayerTreeLayer *nodeLayer) const
Returns legend node that may be embedded in parent (i.e. 
 
double margin(Side side)
Returns the margin (in mm) for the specified side of the component. 
 
QFont font() const
Returns the font used for rendering this legend component. 
 
#define Q_NOWARN_DEPRECATED_PUSH
 
QColor layerFontColor() const
Returns layer font color, defaults to fontColor() 
 
QgsLayerTreeLayer * layerNode() const
Returns pointer to the parent layer node. 
 
double textWidthMillimeters(const QFont &font, const QString &text) const
Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE...
 
Should not happen, only if corrupted project file. 
 
QModelIndex node2index(QgsLayerTreeNode *node) const
Returns index for a given node. If the node does not belong to the layer tree, the result is undefine...
 
QPainter * painter
Painter. 
 
QgsLegendRenderer(QgsLayerTreeModel *legendModel, const QgsLegendSettings &settings)
Constructor for QgsLegendRenderer. 
 
The QgsLayerTreeModel class is model implementation for Qt item views framework. 
 
QgsLegendStyle style(QgsLegendStyle::Style s) const
Returns style. 
 
static QgsLegendStyle::Style nodeLegendStyle(QgsLayerTreeNode *node, QgsLayerTreeModel *model)
Returns the style for the given node, within the specified model. 
 
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent. 
 
Q_DECL_DEPRECATED double labelXOffset
Offset from the left side where label should start. 
 
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
 
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
 
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer. Properties are stored in a map and saved in project file...
 
Symbol icon (excluding label) 
 
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation. 
 
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node. 
 
This class is a base class for nodes in a layer tree. 
 
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title. 
 
double maxSiblingSymbolWidth
Largest symbol width, considering all other sibling legend components associated with the current com...
 
Single scope for storing variables and functions for use within a QgsExpressionContext. 
 
void removeCustomProperty(const QString &key)
Remove a custom property from layer. Properties are stored in a map and saved in project file...
 
QgsLayerTreeModelLegendNode * legendNode(const QString &rule, QgsLayerTreeModel &model)
 
Qt::Alignment alignment() const
Returns the alignment for the legend component. 
 
Style
Component of legends which can be styled. 
 
virtual ItemMetrics draw(const QgsLegendSettings &settings, ItemContext *ctx)
Entry point called from QgsLegendRenderer to do the rendering. 
 
QgsExpressionContext & expressionContext()
Gets the expression context. 
 
const QgsMapSettings * legendFilterMapSettings() const
Returns the current map settings used for the current legend filter (or nullptr if none is enabled) ...
 
QgsMapLayer * layer() const
Returns the map layer associated with this node. 
 
#define Q_NOWARN_DEPRECATED_POP
 
double top
Top y-position of legend item. 
 
void exportToJson(const QgsLegendSettings &settings, const QgsRenderContext &context, QJsonObject &json)
Entry point called from QgsLegendRenderer to do the rendering in a JSON object. 
 
Special style, item is hidden including margins around. 
 
Contains information about the context of a rendering operation. 
 
QPainter * painter()
Returns the destination QPainter for the render operation. 
 
QgsLayerTreeModel * legendModel(const QgsWmsRenderContext &context, QgsLayerTree &tree)
 
QgsLayerTree * rootGroup() const
Returns pointer to the root node of the layer tree. Always a non nullptr value. 
 
void exportLegendToJson(const QgsRenderContext &context, QJsonObject &json)
Renders the legend in a json object. 
 
bool equalColumnWidth() const
 
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context. 
 
double columnSpace() const
 
double columnLeft
Left side of current legend column. 
 
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
 
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
 
Q_DECL_DEPRECATED QPointF point
Top-left corner of the legend item. 
 
QList< QgsLayerTreeModelLegendNode * > layerLegendNodes(QgsLayerTreeLayer *nodeLayer, bool skipNodeEmbeddedInParent=false)
Returns filtered list of active legend nodes attached to a particular layer node (by default it retur...
 
QSizeF minimumSize(QgsRenderContext *renderContext=nullptr)
Runs the layout algorithm and returns the minimum size required for the legend. 
 
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it. 
 
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer. 
 
Symbol label (excluding icon) 
 
double lineSpacing() const
 
double fontDescentMillimeters(const QFont &font) const
Returns the font descent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCA...
 
void setCustomProperty(const QString &key, const QVariant &value)
Sets a custom property for the node. Properties are stored in a map and saved in project file...
 
Layer tree node points to a map layer.