QgsDataDefinedSizeLegend class

Object that keeps configuration of appearance of marker symbol's data-defined size in legend.

For example: the list of classes (size values), whether the classes should appear in separate legend nodes or whether to collapse them into one legend node.

Public types

struct SizeClass
Definition of one class for the legend.
enum LegendType { LegendSeparated, LegendCollapsed }
Determines how to display data-defined size legend.
enum VerticalAlignment { AlignCenter, AlignBottom }
How to vertically align symbols when all classes go into one node.

Public static functions

static auto readXml(const QDomElement& elem, const QgsReadWriteContext& context) SIP_FACTORY -> QgsDataDefinedSizeLegend*
Creates instance from given element and returns it (caller takes ownership). Returns null on error.

Constructors, destructors, conversion operators

QgsDataDefinedSizeLegend() defaulted
Constructor for QgsDataDefinedSizeLegend.
QgsDataDefinedSizeLegend(const QgsDataDefinedSizeLegend& other)
Copy constructor.

Public functions

auto classes() const -> QList<QgsDataDefinedSizeLegend::SizeClass>
Returns list of classes: each class is a pair of symbol size (in units used by the symbol) and label.
auto collapsedLegendImage(QgsRenderContext& context, const QColor& backgroundColor = Qt::transparent, double paddingMM = 1) const -> QImage
Returns output image that would be shown in the legend. Returns invalid image if legend is not configured as collapsed.
void drawCollapsedLegend(QgsRenderContext& context, QSize*outputSize SIP_OUT = nullptr, int*labelXOffset SIP_OUT = nullptr) const
Draw the legend if using LegendOneNodeForAll and optionally output size of the legend and x offset of labels (in painter units).
auto font() const -> QFont
Returns font used for rendering of labels - only valid for collapsed legend.
auto legendSymbolList() const -> QgsLegendSymbolList
Generates legend symbol items according to the configuration.
auto legendType() const -> LegendType
Returns how the legend should be rendered.
void setClasses(const QList<QgsDataDefinedSizeLegend::SizeClass>& classes)
Sets list of classes: each class is a pair of symbol size (in units used by the symbol) and label.
void setFont(const QFont& font)
Sets font used for rendering of labels - only valid for collapsed legend.
void setLegendType(LegendType type)
Sets how the legend should be rendered.
void setSizeScaleTransformer(QgsSizeScaleTransformer*transformer SIP_TRANSFER)
Sets transformer for scaling of symbol sizes. Takes ownership of the object. Accepts null pointer to set no transformer.
void setSymbol(QgsMarkerSymbol*symbol SIP_TRANSFER)
Sets marker symbol that will be used to draw markers in legend.
void setTextAlignment(Qt::AlignmentFlag flag)
Sets horizontal text alignment for rendering of labels - only valid for collapsed legend.
void setTextColor(const QColor& color)
Sets text color for rendering of labels - only valid for collapsed legend.
void setTitle(const QString& title)
Sets title label for data-defined size legend.
void setVerticalAlignment(VerticalAlignment vAlign)
Sets vertical alignment of symbols - only valid for collapsed legend.
auto sizeScaleTransformer() const -> QgsSizeScaleTransformer*
Returns transformer for scaling of symbol sizes. Returns null if no transformer is defined.
auto symbol() const -> QgsMarkerSymbol*
Returns marker symbol that will be used to draw markers in legend.
auto textAlignment() const -> Qt::AlignmentFlag
Returns horizontal text alignment for rendering of labels - only valid for collapsed legend.
auto textColor() const -> QColor
Returns text color for rendering of labels - only valid for collapsed legend.
auto title() const -> QString
Returns title label for data-defined size legend.
void updateFromSymbolAndProperty(const QgsMarkerSymbol* symbol, const QgsProperty& ddSize)
Updates the list of classes, source symbol and title label from given symbol and property.
auto verticalAlignment() const -> VerticalAlignment
Returns vertical alignment of symbols - only valid for collapsed legend.
void writeXml(QDomElement& elem, const QgsReadWriteContext& context) const
Writes configuration to the given XML element.

Enum documentation

enum QgsDataDefinedSizeLegend::LegendType

Determines how to display data-defined size legend.

Enumerators
LegendSeparated

Each class (size value) has a separate legend node.

LegendCollapsed

All classes are rendered within one legend node.

enum QgsDataDefinedSizeLegend::VerticalAlignment

How to vertically align symbols when all classes go into one node.

Enumerators
AlignCenter

Symbols are aligned to the center.

AlignBottom

Symbols are aligned to the bottom.

Function documentation

void QgsDataDefinedSizeLegend::drawCollapsedLegend(QgsRenderContext& context, QSize*outputSize SIP_OUT = nullptr, int*labelXOffset SIP_OUT = nullptr) const

Draw the legend if using LegendOneNodeForAll and optionally output size of the legend and x offset of labels (in painter units).

If the painter in context is null, it only does size calculation without actual rendering. Does nothing if legend is not configured as collapsed.