QgsLayerTreeModelLegendNode class
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegend implementation.
Contents
The objects are used in QgsLayerTreeModel. Custom implementations may offer additional interactivity and customized look.
Derived classes
- class QgsDataDefinedSizeLegendNode
- Produces legend node with a marker symbol.
- class QgsImageLegendNode
- Implementation of legend node interface for displaying arbitrary raster image.
- class QgsRasterSymbolLegendNode
- Implementation of legend node interface for displaying raster legend entries.
- class QgsSimpleLegendNode
- Implementation of legend node interface for displaying arbitrary label with icon.
- class QgsSymbolLegendNode
- Implementation of legend node interface for displaying preview of vector symbols and their labels and allowing interaction with the symbol / renderer.
- class QgsWmsLegendNode
- Implementation of legend node interface for displaying WMS legend entries.
Public types
- enum LegendNodeRoles { RuleKeyRole = Qt::UserRole, ParentRuleKeyRole }
Constructors, destructors, conversion operators
- QgsLayerTreeModelLegendNode(QgsLayerTreeLayer* nodeL, QObject* parent = nullptr) protected explicit
- Construct the node with pointer to its parent layer node.
Public functions
- auto data(int role) const -> QVariant pure virtual
- Returns data associated with the item. Must be implemented in derived class.
- auto draw(const QgsLegendSettings& settings, ItemContext* ctx) -> ItemMetrics virtual
- Entry point called from QgsLegendRenderer to do the rendering.
- auto drawSymbol(const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight) const -> QSizeF virtual
- Draws symbol on the left side of the item.
- auto drawSymbolText(const QgsLegendSettings& settings, ItemContext* ctx, QSizeF symbolSize) const -> QSizeF virtual
- Draws label on the right side of the item.
- auto flags() const -> Qt::ItemFlags virtual
- Returns item flags associated with the item. Default implementation returns Qt::ItemIsEnabled.
- void invalidateMapBasedData() virtual
- Notification from model that information from associated map view has changed.
- auto layerNode() const -> QgsLayerTreeLayer*
- Returns pointer to the parent layer node.
- auto model() const -> QgsLayerTreeModel*
- Returns pointer to model owning this legend node.
- auto setData(const QVariant& value, int role) -> bool virtual
- Sets some data associated with the item. Default implementation does nothing and returns false.
Signals
- void dataChanged()
- Emitted on internal data change so the layer tree model can forward the signal to views.
Protected functions
- auto createTemporaryRenderContext() const -> QgsRenderContext*
- Returns a temporary context or null if legendMapViewData are not valid.
Enum documentation
enum QgsLayerTreeModelLegendNode:: LegendNodeRoles
| Enumerators | |
|---|---|
| RuleKeyRole |
Rule key of the node (QString) |
| ParentRuleKeyRole |
Rule key of the parent legend node - for legends with tree hierarchy (QString). Added in 2.8. |
Function documentation
ItemMetrics QgsLayerTreeModelLegendNode:: draw(const QgsLegendSettings& settings,
ItemContext* ctx) virtual
Entry point called from QgsLegendRenderer to do the rendering.
Default implementation calls drawSymbol() and drawSymbolText() methods.
If ctx is null, this is just first stage when preparing layout - without actual rendering.
QSizeF QgsLayerTreeModelLegendNode:: drawSymbol(const QgsLegendSettings& settings,
ItemContext* ctx,
double itemHeight) const virtual
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) |
QSizeF QgsLayerTreeModelLegendNode:: drawSymbolText(const QgsLegendSettings& settings,
ItemContext* ctx,
QSizeF symbolSize) const virtual
Draws label on the right side of the item.
| Parameters | |
|---|---|
| settings | Legend layout configuration |
| ctx | Context for rendering - may be null if only doing layout without actual rendering |
| symbolSize | Real size of the associated symbol - used for correct positioning when rendering |
| Returns | Size of the label (may span multiple lines) |
void QgsLayerTreeModelLegendNode:: invalidateMapBasedData() virtual
Notification from model that information from associated map view has changed.
Default implementation does nothing.