QgsSymbolLegendNode class

Implementation of legend node interface for displaying preview of vector symbols and their labels and allowing interaction with the symbol / renderer.

Base classes

class QgsLayerTreeModelLegendNode
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegend implementation.

Constructors, destructors, conversion operators

QgsSymbolLegendNode(QgsLayerTreeLayer* nodeLayer, const QgsLegendSymbolItem& item, QObject* parent = nullptr)
Constructor for QgsSymbolLegendNode.

Public functions

auto data(int role) const -> QVariant override
Returns data associated with the item. Must be implemented in derived class.
auto drawSymbol(const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight) const -> QSizeF override
Draws symbol on the left side of the item.
auto flags() const -> Qt::ItemFlags override
Returns item flags associated with the item. Default implementation returns Qt::ItemIsEnabled.
auto iconSize() const -> QSize
void invalidateMapBasedData() override
Notification from model that information from associated map view has changed.
auto minimumIconSize() const -> QSize
Calculates the minimum icon size to prevent cropping.
auto minimumIconSize(QgsRenderContext* context) const -> QSize
Calculates the minimum icon size to prevent cropping.
auto setData(const QVariant& value, int role) -> bool override
Sets some data associated with the item. Default implementation does nothing and returns false.
void setIconSize(QSize sz)
Set the icon size.
void setSymbol(QgsSymbol* symbol)
Sets the symbol to be used by the legend node.
void setTextOnSymbolLabel(const QString& label)
Sets label of text to be shown on top of the symbol.
void setTextOnSymbolTextFormat(const QgsTextFormat& format)
Sets format of text to be shown on top of the symbol.
auto symbol() const -> const QgsSymbol*
Returns the symbol used by the legend node.
auto textOnSymbolLabel() const -> QString
Returns label of text to be shown on top of the symbol.
auto textOnSymbolTextFormat() const -> QgsTextFormat
Returns text format of the label to be shown on top of the symbol.

Public slots

void checkAllItems()
Checks all items belonging to the same layer as this node.
void toggleAllItems()
Toggle all items belonging to the same layer as this node.
void uncheckAllItems()
Unchecks all items belonging to the same layer as this node.

Function documentation

QgsSymbolLegendNode::QgsSymbolLegendNode(QgsLayerTreeLayer* nodeLayer, const QgsLegendSymbolItem& item, QObject* parent = nullptr)

Constructor for QgsSymbolLegendNode.

Parameters
nodeLayer layer node
item the legend symbol item
parent attach a parent QObject to the legend node.

QSizeF QgsSymbolLegendNode::drawSymbol(const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight) const override

Draws symbol on the left side of the item.

Parameters
settings Legend layout configuration
ctx Context for rendering - may be null if only doing layout without actual rendering
itemHeight Minimal height of the legend item - used for correct positioning when rendering
Returns Real size of the symbol (may be bigger than "normal" symbol size from settings)

QSize QgsSymbolLegendNode::iconSize() const

void QgsSymbolLegendNode::invalidateMapBasedData() override

Notification from model that information from associated map view has changed.

Default implementation does nothing.

QSize QgsSymbolLegendNode::minimumIconSize() const

Calculates the minimum icon size to prevent cropping.

When evaluating the size for multiple icons it is more efficient to create a single render context in advance and use the variant which accepts a QgsRenderContext argument.

QSize QgsSymbolLegendNode::minimumIconSize(QgsRenderContext* context) const

Calculates the minimum icon size to prevent cropping.

When evaluating the size for multiple icons it is more efficient to create a single render context in advance and call this method instead of minimumIconSize().

void QgsSymbolLegendNode::setIconSize(QSize sz)

Set the icon size.

void QgsSymbolLegendNode::setSymbol(QgsSymbol* symbol)

Sets the symbol to be used by the legend node.

Parameters
symbol new symbol for node. Ownership is transferred.

The symbol change is also propagated to the associated vector layer's renderer.

void QgsSymbolLegendNode::setTextOnSymbolLabel(const QString& label)

Sets label of text to be shown on top of the symbol.

void QgsSymbolLegendNode::setTextOnSymbolTextFormat(const QgsTextFormat& format)

Sets format of text to be shown on top of the symbol.

const QgsSymbol* QgsSymbolLegendNode::symbol() const

Returns the symbol used by the legend node.

QString QgsSymbolLegendNode::textOnSymbolLabel() const

Returns label of text to be shown on top of the symbol.

QgsTextFormat QgsSymbolLegendNode::textOnSymbolTextFormat() const

Returns text format of the label to be shown on top of the symbol.

void QgsSymbolLegendNode::checkAllItems() public slot

Checks all items belonging to the same layer as this node.

void QgsSymbolLegendNode::toggleAllItems() public slot

Toggle all items belonging to the same layer as this node.

void QgsSymbolLegendNode::uncheckAllItems() public slot

Unchecks all items belonging to the same layer as this node.