QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
QgsSymbolLegendNode Class Reference

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

#include <qgslayertreemodellegendnode.h>

Inheritance diagram for QgsSymbolLegendNode:
Inheritance graph
[legend]

Public Member Functions

 QgsSymbolLegendNode (QgsLayerTreeLayer *nodeLayer, const QgsLegendSymbolItem &item, QObject *parent=nullptr)
 Constructor for QgsSymbolLegendNode.
 
 ~QgsSymbolLegendNode ()
 
QgsExpressionContextScopecreateSymbolScope () const
 Create an expression context scope containing symbol related variables.
 
QgsSymbolcustomSymbol () const
 Returns the node's custom symbol.
 
QVariant data (int role) const override
 Returns data associated with the item. Must be implemented in derived class.
 
QSizeF drawSymbol (const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
 Draws symbol on the left side of the item.
 
QString evaluateLabel (const QgsExpressionContext &context=QgsExpressionContext(), const QString &label=QString())
 Evaluates and returns the text label of the current node.
 
QJsonObject exportSymbolToJson (const QgsLegendSettings &settings, const QgsRenderContext &context) const override
 Adds a symbol in base64 string within a JSON object with the key "icon".
 
Qt::ItemFlags flags () const override
 Returns item flags associated with the item. Default implementation returns Qt::ItemIsEnabled.
 
QSize iconSize () const
 
void invalidateMapBasedData () override
 Notification from model that information from associated map view has changed.
 
bool isScaleOK (double scale) const override
 
QSize minimumIconSize () const
 Calculates the minimum icon size to prevent cropping.
 
QSize minimumIconSize (QgsRenderContext *context) const
 Calculates the minimum icon size to prevent cropping.
 
QgsLegendPatchShape patchShape () const
 Returns the symbol patch shape to use when rendering the legend node symbol.
 
void setCustomSymbol (QgsSymbol *symbol)
 Sets the node's custom symbol.
 
bool setData (const QVariant &value, int role) override
 Sets some data associated with the item. Default implementation does nothing and returns false.
 
void setEmbeddedInParent (bool embedded) override
 
void setIconSize (QSize sz)
 Set the icon size.
 
void setPatchShape (const QgsLegendPatchShape &shape)
 Sets the symbol patch shape to use when rendering the legend node symbol.
 
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.
 
void setUserLabel (const QString &userLabel) override
 
const QgsSymbolsymbol () const
 Returns the symbol used by the legend node.
 
QString symbolLabel () const
 Label of the symbol, user defined label will be used, otherwise will default to the label made by QGIS.
 
QString textOnSymbolLabel () const
 Returns label of text to be shown on top of the symbol.
 
QgsTextFormat textOnSymbolTextFormat () const
 Returns text format of the label to be shown on top of the symbol.
 
- Public Member Functions inherited from QgsLayerTreeModelLegendNode
virtual bool columnBreak () const
 Returns whether a forced column break should occur before the node.
 
virtual ItemMetrics draw (const QgsLegendSettings &settings, ItemContext *ctx)
 Entry point called from QgsLegendRenderer to do the rendering.
 
virtual QSizeF drawSymbolText (const QgsLegendSettings &settings, ItemContext *ctx, QSizeF symbolSize) const
 Draws label on the right side of the item.
 
QJsonObject exportToJson (const QgsLegendSettings &settings, const QgsRenderContext &context)
 Entry point called from QgsLegendRenderer to do the rendering in a JSON object.
 
virtual bool isEmbeddedInParent () const
 
QgsLayerTreeLayerlayerNode () const
 Returns pointer to the parent layer node.
 
QgsLayerTreeModelmodel () const
 Returns pointer to model owning this legend node.
 
virtual void setColumnBreak (bool breakBeforeNode)
 Sets whether a forced column break should occur before the node.
 
virtual void setUserPatchSize (QSizeF size)
 Sets the user (overridden) size for the legend node.
 
virtual QString userLabel () const
 
virtual QSizeF userPatchSize () const
 Returns the user (overridden) size for the legend node.
 

Static Public Attributes

static double MAXIMUM_SIZE = -1.0
 
static double MINIMUM_SIZE = -1.0
 

Additional Inherited Members

- Public Types inherited from QgsLayerTreeModelLegendNode
enum class  CustomRole : int { RuleKey = Qt::UserRole , ParentRuleKey , NodeType , IsDataDefinedSize }
 Legend node data roles. More...
 
enum  NodeTypes {
  SimpleLegend , SymbolLegend , RasterSymbolLegend , ImageLegend ,
  WmsLegend , DataDefinedSizeLegend , EmbeddedWidget , ColorRampLegend
}
 Types of legend nodes. More...
 
- Public Slots inherited from QgsLayerTreeModelLegendNode
void checkAllItems ()
 Checks all checkable items belonging to the same layer as this node.
 
void toggleAllItems ()
 Toggle all checkable items belonging to the same layer as this node.
 
void uncheckAllItems ()
 Unchecks all checkable items belonging to the same layer as this node.
 
- Signals inherited from QgsLayerTreeModelLegendNode
void dataChanged ()
 Emitted on internal data change so the layer tree model can forward the signal to views.
 
void sizeChanged ()
 Emitted when the size of this node changes.
 
- Protected Member Functions inherited from QgsLayerTreeModelLegendNode
 QgsLayerTreeModelLegendNode (QgsLayerTreeLayer *nodeL, QObject *parent=nullptr)
 Construct the node with pointer to its parent layer node.
 
QgsRenderContextcreateTemporaryRenderContext () const
 Returns a temporary context or nullptr if legendMapViewData are not valid.
 
- Protected Attributes inherited from QgsLayerTreeModelLegendNode
bool mColumnBreakBeforeNode = false
 
bool mEmbeddedInParent
 
QgsLayerTreeLayermLayerNode = nullptr
 
QgsLegendPatchShape mPatchShape
 
QString mUserLabel
 
QSizeF mUserSize
 

Detailed Description

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

Definition at line 397 of file qgslayertreemodellegendnode.h.

Constructor & Destructor Documentation

◆ QgsSymbolLegendNode()

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

Constructor for QgsSymbolLegendNode.

Parameters
nodeLayerlayer node
itemthe legend symbol item
parentattach a parent QObject to the legend node.

Definition at line 322 of file qgslayertreemodellegendnode.cpp.

◆ ~QgsSymbolLegendNode()

QgsSymbolLegendNode::~QgsSymbolLegendNode ( )
default

Member Function Documentation

◆ createSymbolScope()

QgsExpressionContextScope * QgsSymbolLegendNode::createSymbolScope ( ) const

Create an expression context scope containing symbol related variables.

The caller takes ownership of the returned object.

Since
QGIS 3.36

Definition at line 977 of file qgslayertreemodellegendnode.cpp.

◆ customSymbol()

QgsSymbol * QgsSymbolLegendNode::customSymbol ( ) const

Returns the node's custom symbol.

If a non-nullptr value is returned, then this symbol will be used for rendering the legend node instead of the default symbol().

See also
setCustomSymbol()
Since
QGIS 3.14

Definition at line 452 of file qgslayertreemodellegendnode.cpp.

◆ data()

QVariant QgsSymbolLegendNode::data ( int  role) const
overridevirtual

Returns data associated with the item. Must be implemented in derived class.

Implements QgsLayerTreeModelLegendNode.

Definition at line 546 of file qgslayertreemodellegendnode.cpp.

◆ drawSymbol()

QSizeF QgsSymbolLegendNode::drawSymbol ( const QgsLegendSettings settings,
ItemContext ctx,
double  itemHeight 
) const
overridevirtual

Draws symbol on the left side of the item.

Parameters
settingsLegend layout configuration
ctxContext for rendering - may be nullptr if only doing layout without actual rendering
itemHeightMinimal 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)

Reimplemented from QgsLayerTreeModelLegendNode.

Definition at line 650 of file qgslayertreemodellegendnode.cpp.

◆ evaluateLabel()

QString QgsSymbolLegendNode::evaluateLabel ( const QgsExpressionContext context = QgsExpressionContext(),
const QString &  label = QString() 
)

Evaluates and returns the text label of the current node.

Parameters
contextextra QgsExpressionContext to use for evaluating the expression
labeltext to evaluate instead of the layer layertree string
Since
QGIS 3.10

Definition at line 941 of file qgslayertreemodellegendnode.cpp.

◆ exportSymbolToJson()

QJsonObject QgsSymbolLegendNode::exportSymbolToJson ( const QgsLegendSettings settings,
const QgsRenderContext context 
) const
overridevirtual

Adds a symbol in base64 string within a JSON object with the key "icon".

Parameters
settingsLegend layout configuration
contextRendering context
Since
QGIS 3.8

Reimplemented from QgsLayerTreeModelLegendNode.

Definition at line 827 of file qgslayertreemodellegendnode.cpp.

◆ flags()

Qt::ItemFlags QgsSymbolLegendNode::flags ( ) const
overridevirtual

Returns item flags associated with the item. Default implementation returns Qt::ItemIsEnabled.

Reimplemented from QgsLayerTreeModelLegendNode.

Definition at line 353 of file qgslayertreemodellegendnode.cpp.

◆ iconSize()

QSize QgsSymbolLegendNode::iconSize ( ) const
inline

Definition at line 435 of file qgslayertreemodellegendnode.h.

◆ invalidateMapBasedData()

void QgsSymbolLegendNode::invalidateMapBasedData ( )
overridevirtual

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

Default implementation does nothing.

Reimplemented from QgsLayerTreeModelLegendNode.

Definition at line 896 of file qgslayertreemodellegendnode.cpp.

◆ isScaleOK()

bool QgsSymbolLegendNode::isScaleOK ( double  scale) const
inlineoverridevirtual

Reimplemented from QgsLayerTreeModelLegendNode.

Definition at line 427 of file qgslayertreemodellegendnode.h.

◆ minimumIconSize() [1/2]

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.

Definition at line 362 of file qgslayertreemodellegendnode.cpp.

◆ minimumIconSize() [2/2]

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().

Definition at line 368 of file qgslayertreemodellegendnode.cpp.

◆ patchShape()

QgsLegendPatchShape QgsSymbolLegendNode::patchShape ( ) const

Returns the symbol patch shape to use when rendering the legend node symbol.

See also
setPatchShape()
Since
QGIS 3.14

Definition at line 435 of file qgslayertreemodellegendnode.cpp.

◆ setCustomSymbol()

void QgsSymbolLegendNode::setCustomSymbol ( QgsSymbol symbol)

Sets the node's custom symbol.

If a non-nullptr value is set, then this symbol will be used for rendering the legend node instead of the default symbol().

Ownership of symbol is transferred.

See also
customSymbol()
Since
QGIS 3.14

Definition at line 457 of file qgslayertreemodellegendnode.cpp.

◆ setData()

bool QgsSymbolLegendNode::setData ( const QVariant &  value,
int  role 
)
overridevirtual

Sets some data associated with the item. Default implementation does nothing and returns false.

Reimplemented from QgsLayerTreeModelLegendNode.

Definition at line 625 of file qgslayertreemodellegendnode.cpp.

◆ setEmbeddedInParent()

void QgsSymbolLegendNode::setEmbeddedInParent ( bool  embedded)
overridevirtual

Reimplemented from QgsLayerTreeModelLegendNode.

Definition at line 889 of file qgslayertreemodellegendnode.cpp.

◆ setIconSize()

void QgsSymbolLegendNode::setIconSize ( QSize  sz)

Set the icon size.

Definition at line 905 of file qgslayertreemodellegendnode.cpp.

◆ setPatchShape()

void QgsSymbolLegendNode::setPatchShape ( const QgsLegendPatchShape shape)

Sets the symbol patch shape to use when rendering the legend node symbol.

See also
patchShape()
Since
QGIS 3.14

Definition at line 447 of file qgslayertreemodellegendnode.cpp.

◆ setSymbol()

void QgsSymbolLegendNode::setSymbol ( QgsSymbol symbol)

Sets the symbol to be used by the legend node.

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

Parameters
symbolnew symbol for node. Ownership is transferred.
See also
symbol()

Definition at line 462 of file qgslayertreemodellegendnode.cpp.

◆ setTextOnSymbolLabel()

void QgsSymbolLegendNode::setTextOnSymbolLabel ( const QString &  label)
inline

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

Since
QGIS 3.2

Definition at line 476 of file qgslayertreemodellegendnode.h.

◆ setTextOnSymbolTextFormat()

void QgsSymbolLegendNode::setTextOnSymbolTextFormat ( const QgsTextFormat format)
inline

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

Since
QGIS 3.2

Definition at line 488 of file qgslayertreemodellegendnode.h.

◆ setUserLabel()

void QgsSymbolLegendNode::setUserLabel ( const QString &  userLabel)
inlineoverridevirtual

Reimplemented from QgsLayerTreeModelLegendNode.

Definition at line 425 of file qgslayertreemodellegendnode.h.

◆ symbol()

const QgsSymbol * QgsSymbolLegendNode::symbol ( ) const

Returns the symbol used by the legend node.

See also
setSymbol()

Definition at line 416 of file qgslayertreemodellegendnode.cpp.

◆ symbolLabel()

QString QgsSymbolLegendNode::symbolLabel ( ) const

Label of the symbol, user defined label will be used, otherwise will default to the label made by QGIS.

Since
QGIS 3.10

Definition at line 421 of file qgslayertreemodellegendnode.cpp.

◆ textOnSymbolLabel()

QString QgsSymbolLegendNode::textOnSymbolLabel ( ) const
inline

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

Since
QGIS 3.2

Definition at line 470 of file qgslayertreemodellegendnode.h.

◆ textOnSymbolTextFormat()

QgsTextFormat QgsSymbolLegendNode::textOnSymbolTextFormat ( ) const
inline

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

Since
QGIS 3.2

Definition at line 482 of file qgslayertreemodellegendnode.h.

Member Data Documentation

◆ MAXIMUM_SIZE

double QgsSymbolLegendNode::MAXIMUM_SIZE = -1.0
static

Definition at line 404 of file qgslayertreemodellegendnode.h.

◆ MINIMUM_SIZE

double QgsSymbolLegendNode::MINIMUM_SIZE = -1.0
static

Definition at line 403 of file qgslayertreemodellegendnode.h.


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