28 #include <QJsonObject>
35 , mSettings( settings )
41 std::unique_ptr< QgsRenderContext > tmpContext;
48 tmpContext->setRendererScale( mSettings.
mapScale() );
50 renderContext = tmpContext.get();
55 return paintAndDetermineSize( *renderContext );
64 context.setRendererScale( mSettings.
mapScale() );
68 paintAndDetermineSize( context );
80 json[QStringLiteral(
"title" )] = mSettings.
title();
88 const QList<QgsLayerTreeNode *> childNodes = nodeGroup->
children();
94 const QModelIndex idx = mLegendModel->
node2index( nodeGroup );
95 const QString text = mLegendModel->
data( idx, Qt::DisplayRole ).toString();
98 group[ QStringLiteral(
"type" ) ] = QStringLiteral(
"group" );
99 group[ QStringLiteral(
"title" ) ] = text;
100 nodes.append( group );
109 const QModelIndex idx = mLegendModel->
node2index( nodeLayer );
110 text = mLegendModel->
data( idx, Qt::DisplayRole ).toString();
113 QList<QgsLayerTreeModelLegendNode *> legendNodes = mLegendModel->
layerLegendNodes( nodeLayer );
118 if ( legendNodes.count() == 1 )
120 QJsonObject group = legendNodes.at( 0 )->exportToJson( mSettings, context );
121 group[ QStringLiteral(
"type" ) ] = QStringLiteral(
"layer" );
122 nodes.append( group );
124 else if ( legendNodes.count() > 1 )
127 group[ QStringLiteral(
"type" ) ] = QStringLiteral(
"layer" );
128 group[ QStringLiteral(
"title" ) ] = text;
131 for (
int j = 0; j < legendNodes.count(); j++ )
135 symbols.append( symbol );
137 group[ QStringLiteral(
"symbols" ) ] = symbols;
139 nodes.append( group );
144 json[QStringLiteral(
"nodes" )] = nodes;
148 QSizeF QgsLegendRenderer::paintAndDetermineSize(
QgsRenderContext &context )
159 QList<LegendComponentGroup> componentGroups = createComponentGroupList( rootGroup, context );
161 const int columnCount = setColumns( componentGroups );
163 QMap< int, double > maxColumnWidths;
164 qreal maxEqualColumnWidth = 0;
172 for (
const LegendComponentGroup &group : qgis::as_const( componentGroups ) )
174 const QSizeF actualSize = drawGroup( group, context, ColumnContext() );
175 maxEqualColumnWidth = std::max( actualSize.width(), maxEqualColumnWidth );
176 maxColumnWidths[ group.column ] = std::max( actualSize.width(), maxColumnWidths.value( group.column, 0 ) );
179 if ( columnCount == 1 )
182 maxEqualColumnWidth = std::max( maxEqualColumnWidth, mLegendSize.width() - 2 * mSettings.
boxSpace() );
183 maxColumnWidths[ 0 ] = maxEqualColumnWidth;
187 QSizeF titleSize = drawTitle( context, 0 );
189 titleSize.rwidth() += mSettings.
boxSpace() * 2.0;
194 bool firstInColumn =
true;
195 double columnMaxHeight = 0;
196 qreal columnWidth = 0;
198 ColumnContext columnContext;
199 columnContext.left = mSettings.
boxSpace();
200 columnContext.right = std::max( mLegendSize.width() - mSettings.
boxSpace(), mSettings.
boxSpace() );
201 double currentY = columnTop;
203 for (
const LegendComponentGroup &group : qgis::as_const( componentGroups ) )
205 if ( group.column > column )
208 columnContext.left = group.column > 0 ? columnContext.right + mSettings.
columnSpace() : mSettings.
boxSpace();
209 columnWidth = mSettings.
equalColumnWidth() ? maxEqualColumnWidth : maxColumnWidths.value( group.column );
210 columnContext.right = columnContext.left + columnWidth;
211 currentY = columnTop;
213 firstInColumn =
true;
215 if ( !firstInColumn )
217 currentY += spaceAboveGroup( group );
220 drawGroup( group, context, columnContext, currentY );
222 currentY += group.size.height();
223 columnMaxHeight = std::max( currentY - columnTop, columnMaxHeight );
225 firstInColumn =
false;
227 const double totalWidth = columnContext.right + mSettings.
boxSpace();
229 size.rheight() = columnTop + columnMaxHeight + mSettings.
boxSpace();
230 size.rwidth() = totalWidth;
231 if ( !mSettings.
title().isEmpty() )
233 size.rwidth() = std::max( titleSize.width(), size.width() );
237 if ( mLegendSize.isValid() )
239 qreal w = std::max( size.width(), mLegendSize.width() );
240 qreal h = std::max( size.height(), mLegendSize.height() );
241 size = QSizeF( w, h );
245 if ( !mSettings.
title().isEmpty() )
253 void QgsLegendRenderer::widthAndOffsetForTitleText(
const Qt::AlignmentFlag halignment,
const double legendWidth,
double &textBoxWidth,
double &textBoxLeft )
255 switch ( halignment )
259 textBoxWidth = legendWidth - 2 * mSettings.
boxSpace();
262 case Qt::AlignHCenter:
265 const double centerX = legendWidth / 2;
266 textBoxWidth = ( std::min(
static_cast< double >( centerX ), legendWidth - centerX ) - mSettings.
boxSpace() ) * 2.0;
267 textBoxLeft = centerX - textBoxWidth / 2.;
275 QList<LegendComponentGroup> componentGroups;
278 return componentGroups;
280 const QList<QgsLayerTreeNode *> childNodes = parentGroup->
children();
288 QList<LegendComponentGroup> subgroups = createComponentGroupList( nodeGroup, context );
289 bool hasSubItems = !subgroups.empty();
293 LegendComponent component;
294 component.item = node;
295 component.size = drawGroupTitle( nodeGroup, context );
297 if ( !subgroups.isEmpty() )
300 subgroups[0].size.rheight() += spaceAboveGroup( subgroups[0] );
302 subgroups[0].components.prepend( component );
303 subgroups[0].size.rheight() += component.size.height();
304 subgroups[0].size.rwidth() = std::max( component.size.width(), subgroups[0].size.width() );
305 if ( nodeGroup->
customProperty( QStringLiteral(
"legend/column-break" ) ).toInt() )
306 subgroups[0].placeColumnBreakBeforeGroup =
true;
311 LegendComponentGroup group;
312 group.placeColumnBreakBeforeGroup = nodeGroup->
customProperty( QStringLiteral(
"legend/column-break" ) ).toInt();
313 group.components.append( component );
314 group.size.rwidth() += component.size.width();
315 group.size.rheight() += component.size.height();
316 group.size.rwidth() = std::max( component.size.width(), group.size.width() );
317 subgroups.append( group );
323 componentGroups.append( subgroups );
331 bool allowColumnSplit =
false;
338 allowColumnSplit =
true;
341 allowColumnSplit =
false;
345 LegendComponentGroup group;
346 group.placeColumnBreakBeforeGroup = nodeLayer->
customProperty( QStringLiteral(
"legend/column-break" ) ).toInt();
350 LegendComponent component;
351 component.item = node;
352 component.size = drawLayerTitle( nodeLayer, context );
353 group.components.append( component );
354 group.size.rwidth() = component.size.width();
355 group.size.rheight() = component.size.height();
358 QList<QgsLayerTreeModelLegendNode *> legendNodes = mLegendModel->
layerLegendNodes( nodeLayer );
366 QList<LegendComponentGroup> layerGroups;
367 layerGroups.reserve( legendNodes.count() );
369 bool groupIsLayerGroup =
true;
371 for (
int j = 0; j < legendNodes.count(); j++ )
375 LegendComponent symbolComponent = drawSymbolItem(
legendNode, context, ColumnContext(), 0 );
379 if ( !allowColumnSplit || j == 0 )
383 if ( groupIsLayerGroup )
384 layerGroups.prepend( group );
386 layerGroups.append( group );
388 group = LegendComponentGroup();
389 group.placeColumnBreakBeforeGroup =
true;
390 groupIsLayerGroup =
false;
395 group.size.rwidth() = std::max( symbolComponent.size.width(), group.size.width() );
397 if ( !group.components.isEmpty() )
402 group.size.rheight() += symbolComponent.size.height();
403 group.components.append( symbolComponent );
407 if ( group.size.height() > 0 )
409 if ( groupIsLayerGroup )
410 layerGroups.prepend( group );
412 layerGroups.append( group );
413 group = LegendComponentGroup();
414 groupIsLayerGroup =
false;
416 LegendComponentGroup symbolGroup;
417 symbolGroup.placeColumnBreakBeforeGroup = forceBreak;
418 symbolGroup.components.append( symbolComponent );
419 symbolGroup.size.rwidth() = symbolComponent.size.width();
420 symbolGroup.size.rheight() = symbolComponent.size.height();
421 layerGroups.append( symbolGroup );
424 if ( group.size.height() > 0 )
426 if ( groupIsLayerGroup )
427 layerGroups.prepend( group );
429 layerGroups.append( group );
431 componentGroups.append( layerGroups );
435 return componentGroups;
439 int QgsLegendRenderer::setColumns( QList<LegendComponentGroup> &componentGroups )
442 double totalHeight = 0;
443 qreal maxGroupHeight = 0;
444 int forcedColumnBreaks = 0;
445 double totalSpaceAboveGroups = 0;
446 for (
const LegendComponentGroup &group : qgis::as_const( componentGroups ) )
448 totalHeight += spaceAboveGroup( group );
449 totalSpaceAboveGroups += spaceAboveGroup( group );
450 totalHeight += group.size.height();
451 maxGroupHeight = std::max( group.size.height(), maxGroupHeight );
453 if ( group.placeColumnBreakBeforeGroup )
454 forcedColumnBreaks++;
456 double averageGroupHeight = ( totalHeight - totalSpaceAboveGroups ) / componentGroups.size();
458 if ( mSettings.
columnCount() == 0 && forcedColumnBreaks == 0 )
463 const int targetNumberColumns = std::max( forcedColumnBreaks + 1, mSettings.
columnCount() );
464 const int numberAutoPlacedBreaks = targetNumberColumns - forcedColumnBreaks - 1;
471 double maxColumnHeight = 0;
472 int currentColumn = 0;
473 int currentColumnGroupCount = 0;
474 double currentColumnHeight = 0;
475 double closedColumnsHeight = 0;
476 int autoPlacedBreaks = 0;
479 double averageSpaceAboveGroups = 0;
480 if ( componentGroups.size() > targetNumberColumns )
481 averageSpaceAboveGroups = totalSpaceAboveGroups / ( componentGroups.size() );
484 totalHeight -= targetNumberColumns * averageSpaceAboveGroups;
486 for (
int i = 0; i < componentGroups.size(); i++ )
488 LegendComponentGroup group = componentGroups.at( i );
489 double currentHeight = currentColumnHeight;
490 if ( currentColumnGroupCount > 0 )
491 currentHeight += spaceAboveGroup( group );
492 currentHeight += group.size.height();
494 int numberRemainingGroups = componentGroups.size() - i;
497 int numberRemainingColumns = numberAutoPlacedBreaks + 1 - autoPlacedBreaks;
498 double avgColumnHeight = ( currentHeight + numberRemainingGroups * averageGroupHeight + ( numberRemainingGroups - numberRemainingColumns - 1 ) * averageSpaceAboveGroups ) / numberRemainingColumns;
501 int averageGroupsPerColumn = std::ceil( avgColumnHeight / ( averageGroupHeight + averageSpaceAboveGroups ) );
502 avgColumnHeight = averageGroupsPerColumn * ( averageGroupHeight + averageSpaceAboveGroups ) - averageSpaceAboveGroups;
504 bool canCreateNewColumn = ( currentColumnGroupCount > 0 )
505 && ( currentColumn < targetNumberColumns - 1 )
506 && ( autoPlacedBreaks < numberAutoPlacedBreaks );
508 bool shouldCreateNewColumn = currentHeight > avgColumnHeight
509 && currentColumnGroupCount > 0
510 && currentHeight > maxGroupHeight
511 && currentHeight > maxColumnHeight;
513 shouldCreateNewColumn |= group.placeColumnBreakBeforeGroup;
514 canCreateNewColumn |= group.placeColumnBreakBeforeGroup;
518 shouldCreateNewColumn |= ( componentGroups.size() - i < targetNumberColumns - currentColumn );
520 if ( canCreateNewColumn && shouldCreateNewColumn )
524 if ( !group.placeColumnBreakBeforeGroup )
526 currentColumnGroupCount = 0;
527 closedColumnsHeight += currentColumnHeight;
528 currentColumnHeight = group.size.height();
532 currentColumnHeight = currentHeight;
534 componentGroups[i].column = currentColumn;
535 currentColumnGroupCount++;
536 maxColumnHeight = std::max( currentColumnHeight, maxColumnHeight );
540 QMap<QString, qreal> maxSymbolWidth;
541 for (
int i = 0; i < componentGroups.size(); i++ )
543 LegendComponentGroup &group = componentGroups[i];
544 for (
int j = 0; j < group.components.size(); j++ )
548 QString key = QStringLiteral(
"%1-%2" ).arg(
reinterpret_cast< qulonglong
>(
legendNode->
layerNode() ) ).arg( group.column );
549 maxSymbolWidth[key] = std::max( group.components.at( j ).symbolSize.width(), maxSymbolWidth[key] );
553 for (
int i = 0; i < componentGroups.size(); i++ )
555 LegendComponentGroup &group = componentGroups[i];
556 for (
int j = 0; j < group.components.size(); j++ )
560 QString key = QStringLiteral(
"%1-%2" ).arg(
reinterpret_cast< qulonglong
>(
legendNode->
layerNode() ) ).arg( group.column );
563 group.components[j].labelXOffset = maxSymbolWidth[key] + space;
564 group.components[j].maxSiblingSymbolWidth = maxSymbolWidth[key];
565 group.components[j].size.rwidth() = maxSymbolWidth[key] + space + group.components.at( j ).labelSize.width();
569 return targetNumberColumns;
572 QSizeF QgsLegendRenderer::drawTitle(
QgsRenderContext &context,
double top, Qt::AlignmentFlag halignment,
double legendWidth )
575 if ( mSettings.
title().isEmpty() )
583 if (
auto *lPainter = context.
painter() )
585 lPainter->setPen( mSettings.
fontColor() );
591 widthAndOffsetForTitleText( halignment, legendWidth, textBoxWidth, textBoxLeft );
595 for ( QStringList::Iterator titlePart = lines.begin(); titlePart != lines.end(); ++titlePart )
602 QRectF r( textBoxLeft, y, textBoxWidth, height );
606 mSettings.
drawText( context.
painter(), r, *titlePart, titleFont, halignment, Qt::AlignVCenter, Qt::TextDontClip );
610 size.rwidth() = std::max( width, size.rwidth() );
613 if ( titlePart != ( lines.end() - 1 ) )
618 size.rheight() = y - top;
624 double QgsLegendRenderer::spaceAboveGroup(
const LegendComponentGroup &group )
626 if ( group.components.isEmpty() )
return 0;
628 LegendComponent component = group.components.first();
630 if (
QgsLayerTreeGroup *nodeGroup = qobject_cast<QgsLayerTreeGroup *>( component.item ) )
634 else if (
QgsLayerTreeLayer *nodeLayer = qobject_cast<QgsLayerTreeLayer *>( component.item ) )
638 else if ( qobject_cast<QgsLayerTreeModelLegendNode *>( component.item ) )
647 QSizeF QgsLegendRenderer::drawGroup(
const LegendComponentGroup &group,
QgsRenderContext &context, ColumnContext columnContext,
double top )
650 QSizeF size = QSizeF( group.size );
651 double currentY = top;
652 for (
const LegendComponent &component : qgis::as_const( group.components ) )
654 if (
QgsLayerTreeGroup *groupItem = qobject_cast<QgsLayerTreeGroup *>( component.item ) )
664 groupSize = drawGroupTitle( groupItem, context, columnContext, currentY );
665 size.rwidth() = std::max( groupSize.width(), size.width() );
668 else if (
QgsLayerTreeLayer *layerItem = qobject_cast<QgsLayerTreeLayer *>( component.item ) )
678 subGroupSize = drawLayerTitle( layerItem, context, columnContext, currentY );
679 size.rwidth() = std::max( subGroupSize.width(), size.width() );
689 LegendComponent symbolComponent = drawSymbolItem(
legendNode, context, columnContext, currentY, component.maxSiblingSymbolWidth );
691 size.rwidth() = std::max( symbolComponent.size.width(), size.width() );
693 currentY += component.size.height();
714 ctx.
point = QPointF( columnContext.left, top );
747 LegendComponent component;
748 component.item = symbolItem;
755 double width = std::max(
static_cast< double >( im.
symbolSize.width() ), maxSiblingSymbolWidth )
762 component.size = QSizeF( width, height );
769 QModelIndex idx = mLegendModel->
node2index( nodeLayer );
770 QString titleString = mLegendModel->
data( idx, Qt::DisplayRole ).toString();
772 if ( titleString.isEmpty() )
777 if (
auto *lPainter = context.
painter() )
783 if ( nodeLayer->
layer() )
793 for ( QStringList::ConstIterator layerItemPart = lines.constBegin(); layerItemPart != lines.constEnd(); ++layerItemPart )
796 if ( QPainter *destPainter = context.
painter() )
798 double x = columnContext.left + sideMargin;
803 x = columnContext.right - labelWidth - sideMargin;
805 x = columnContext.left + ( columnContext.right - columnContext.left - labelWidth ) / 2;
807 mSettings.
drawText( destPainter, x, y, *layerItemPart, layerFont );
811 size.rwidth() = std::max( width, size.width() );
812 if ( layerItemPart != ( lines.end() - 1 ) )
818 size.rheight() = y - top;
830 QModelIndex idx = mLegendModel->
node2index( nodeGroup );
834 if (
auto *lPainter = context.
painter() )
835 lPainter->setPen( mSettings.
fontColor() );
842 for ( QStringList::ConstIterator groupPart = lines.constBegin(); groupPart != lines.constEnd(); ++groupPart )
846 if ( QPainter *destPainter = context.
painter() )
848 double x = columnContext.left + sideMargin;
853 x = columnContext.right - labelWidth - sideMargin;
855 x = columnContext.left + ( columnContext.right - columnContext.left - labelWidth ) / 2;
857 mSettings.
drawText( destPainter, x, y, *groupPart, groupFont );
860 size.rwidth() = std::max( width, size.width() );
861 if ( groupPart != ( lines.end() - 1 ) )
872 QString style = node->
customProperty( QStringLiteral(
"legend/title-style" ) ).toString();
873 if ( style == QLatin1String(
"hidden" ) )
875 else if ( style == QLatin1String(
"group" ) )
877 else if ( style == QLatin1String(
"subgroup" ) )
904 str = QStringLiteral(
"hidden" );
907 str = QStringLiteral(
"group" );
910 str = QStringLiteral(
"subgroup" );
916 if ( !str.isEmpty() )
924 paintAndDetermineSize( context );
Single scope for storing variables and functions for use within a QgsExpressionContext.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Layer tree group node serves as a container for layers and further groups.
Layer tree node points to a map layer.
@ AllowSplittingLegendNodesOverMultipleColumns
Allow splitting node's legend nodes across multiple columns.
@ PreventSplittingLegendNodesOverMultipleColumns
Prevent splitting node's legend nodes across multiple columns.
@ UseDefaultLegendSetting
Inherit default legend column splitting setting.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
LegendNodesSplitBehavior legendSplitBehavior() const
Returns the column split behavior for the node.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
QJsonObject exportToJson(const QgsLegendSettings &settings, const QgsRenderContext &context)
Entry point called from QgsLegendRenderer to do the rendering in a JSON object.
virtual bool columnBreak() const
Returns whether a forced column break should occur before the node.
QgsLayerTreeLayer * layerNode() const
Returns pointer to the parent layer node.
virtual QSizeF userPatchSize() const
Returns the user (overridden) size for the legend node.
virtual ItemMetrics draw(const QgsLegendSettings &settings, ItemContext *ctx)
Entry point called from QgsLegendRenderer to do the rendering.
The QgsLayerTreeModel class is model implementation for Qt item views framework.
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...
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...
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
const QgsMapSettings * legendFilterMapSettings() const
Returns the current map settings used for the current legend filter (or nullptr if none is enabled)
QgsLayerTree * rootGroup() const
Returns pointer to the root node of the layer tree. Always a non nullptr value.
QgsLayerTreeModelLegendNode * legendNodeEmbeddedInParent(QgsLayerTreeLayer *nodeLayer) const
Returns legend node that may be embedded in parent (i.e.
This class is a base class for nodes in a layer tree.
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.
void removeCustomProperty(const QString &key)
Remove a custom property from layer. Properties are stored in a map and saved in project file.
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.
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
QSizeF minimumSize(QgsRenderContext *renderContext=nullptr)
Runs the layout algorithm and returns the minimum size required for the legend.
static void setNodeLegendStyle(QgsLayerTreeNode *node, QgsLegendStyle::Style style)
Sets the style of a node.
QJsonObject exportLegendToJson(const QgsRenderContext &context)
Renders the legend in a json object.
QgsLegendRenderer(QgsLayerTreeModel *legendModel, const QgsLegendSettings &settings)
Constructor for QgsLegendRenderer.
static QgsLegendStyle::Style nodeLegendStyle(QgsLayerTreeNode *node, QgsLayerTreeModel *model)
Returns the style for the given node, within the specified model.
Q_DECL_DEPRECATED void drawLegend(QPainter *painter)
Draws the legend with given painter.
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
int columnCount() const
Returns the desired minimum number of columns to show in the legend.
QColor layerFontColor() const
Returns layer font color, defaults to fontColor()
void drawText(QPainter *p, double x, double y, const QString &text, const QFont &font) const
Draws Text.
QgsLegendStyle style(QgsLegendStyle::Style s) const
Returns the style for a legend component.
double fontDescentMillimeters(const QFont &font) const
Returns the font descent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCA...
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
QColor fontColor() const
Returns the font color used for legend items.
QString title() const
Returns the title for the legend, which will be rendered above all legend items.
double textWidthMillimeters(const QFont &font, const QString &text) const
Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE...
double columnSpace() const
Returns the margin space between adjacent columns (in millimeters).
double fontAscentMillimeters(const QFont &font) const
Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCAL...
double boxSpace() const
Returns the legend box space (in millimeters), which is the empty margin around the inside of the leg...
double lineSpacing() const
Returns the line spacing to use between lines of legend text.
Q_DECL_DEPRECATED double mmPerMapUnit() const
bool splitLayer() const
Returns true if layer components can be split over multiple columns.
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...
QStringList splitStringForWrapping(const QString &stringToSplt) const
Splits a string using the wrap char taking into account handling empty wrap char which means no wrapp...
Qt::AlignmentFlag symbolAlignment() const
Returns the alignment for placement of legend symbols.
bool equalColumnWidth() const
Returns true if all columns should have equal widths.
Q_DECL_DEPRECATED double mapScale() const
Returns the legend map scale.
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.
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)
Perform transforms between map coordinates and device coordinates.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
Scoped object for temporary replacement of a QgsRenderContext destination painter.
Scoped object for temporary scaling of a QgsRenderContext for millimeter based rendering.
Implementation of legend node interface for displaying preview of vector symbols and their labels and...
QgsLayerTreeModelLegendNode * legendNode(const QString &rule, QgsLayerTreeModel &model)
QgsLayerTreeModel * legendModel(const QgsWmsRenderContext &context, QgsLayerTree &tree)
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
QPainter * painter
Painter.
double top
Top y-position of legend item.
Q_DECL_DEPRECATED double labelXOffset
Offset from the left side where label should start.
QgsLegendPatchShape patchShape
The patch shape to render for the node.
double maxSiblingSymbolWidth
Largest symbol width, considering all other sibling legend components associated with the current com...
QSizeF patchSize
Symbol patch size to render for the node.
double columnLeft
Left side of current legend column.
double columnRight
Right side of current legend column.
Q_DECL_DEPRECATED QPointF point
Top-left corner of the legend item.
Q_NOWARN_DEPRECATED_POP QgsRenderContext * context
Render context, if available.