QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
QgsLegendRenderer Class Reference

The QgsLegendRenderer class handles automatic layout and rendering of legend. More...

#include <qgslegendrenderer.h>

Public Member Functions

 QgsLegendRenderer (QgsLayerTreeModel *legendModel, const QgsLegendSettings &settings)
 Constructor for QgsLegendRenderer.
 
void drawLegend (QgsRenderContext &context)
 Draws the legend using a given render context.
 
Q_DECL_DEPRECATED void drawLegend (QPainter *painter)
 Draws the legend with given painter.
 
QJsonObject exportLegendToJson (const QgsRenderContext &context)
 Renders the legend in a json object.
 
QSizeF legendSize () const
 Returns the preferred legend size set by the client.
 
QSizeF minimumSize (QgsRenderContext *renderContext=nullptr)
 Runs the layout algorithm and returns the minimum size required for the legend.
 
void setLegendSize (QSizeF s)
 Sets the preferred resulting legend size.
 

Static Public Member Functions

static QgsLegendStyle::Style nodeLegendStyle (QgsLayerTreeNode *node, QgsLayerTreeModel *model)
 Returns the style for the given node, within the specified model.
 
static void setNodeLegendStyle (QgsLayerTreeNode *node, QgsLegendStyle::Style style)
 Sets the style of a node.
 

Detailed Description

The QgsLegendRenderer class handles automatic layout and rendering of legend.

The content is given by QgsLayerTreeModel instance. Various layout properties can be configured within QgsLegendRenderer.

All spacing and sizes are in millimeters.

Since
QGIS 2.6

Definition at line 46 of file qgslegendrenderer.h.

Constructor & Destructor Documentation

◆ QgsLegendRenderer()

QgsLegendRenderer::QgsLegendRenderer ( QgsLayerTreeModel legendModel,
const QgsLegendSettings settings 
)

Constructor for QgsLegendRenderer.

The ownership of the legend model is not changed, and the model must exist for the lifetime of this renderer.

Definition at line 30 of file qgslegendrenderer.cpp.

Member Function Documentation

◆ drawLegend() [1/2]

void QgsLegendRenderer::drawLegend ( QgsRenderContext context)

Draws the legend using a given render context.

The legend will occupy the area reported in legendSize().

Since
QGIS 3.6

Definition at line 1068 of file qgslegendrenderer.cpp.

◆ drawLegend() [2/2]

void QgsLegendRenderer::drawLegend ( QPainter *  painter)

Draws the legend with given painter.

The legend will occupy the area reported in legendSize(). The painter should be scaled beforehand so that units correspond to millimeters.

Deprecated:
Use the variant which accepts a QgsRenderContext instead.

Definition at line 56 of file qgslegendrenderer.cpp.

◆ exportLegendToJson()

QJsonObject QgsLegendRenderer::exportLegendToJson ( const QgsRenderContext context)

Renders the legend in a json object.

Since
QGIS 3.8

Definition at line 69 of file qgslegendrenderer.cpp.

◆ legendSize()

QSizeF QgsLegendRenderer::legendSize ( ) const
inline

Returns the preferred legend size set by the client.

If the returned size is null, the legend will be drawn with the minimum possible size to fit its content.

See also
minimumSize()
setLegendSize()

Definition at line 81 of file qgslegendrenderer.h.

◆ minimumSize()

QSizeF QgsLegendRenderer::minimumSize ( QgsRenderContext renderContext = nullptr)

Runs the layout algorithm and returns the minimum size required for the legend.

See also
setLegendSize()
legendSize()

Definition at line 36 of file qgslegendrenderer.cpp.

◆ nodeLegendStyle()

QgsLegendStyle::Style QgsLegendRenderer::nodeLegendStyle ( QgsLayerTreeNode node,
QgsLayerTreeModel model 
)
static

Returns the style for the given node, within the specified model.

See also
setNodeLegendStyle()

Definition at line 1016 of file qgslegendrenderer.cpp.

◆ setLegendSize()

void QgsLegendRenderer::setLegendSize ( QSizeF  s)
inline

Sets the preferred resulting legend size.

If the size is null, the legend will be drawn with the minimum possible size to fit its content.

See also
legendSize()
minimumSize()

Definition at line 71 of file qgslegendrenderer.h.

◆ setNodeLegendStyle()

void QgsLegendRenderer::setNodeLegendStyle ( QgsLayerTreeNode node,
QgsLegendStyle::Style  style 
)
static

Sets the style of a node.

See also
nodeLegendStyle()

Definition at line 1044 of file qgslegendrenderer.cpp.


The documentation for this class was generated from the following files: