Class: QgsDiagramRenderer

class qgis.core.QgsDiagramRenderer

Bases: sip.wrapper

Constructor for QgsDiagramRenderer.

QgsDiagramRenderer(other: QgsDiagramRenderer)

Evaluates and returns the diagram settings relating to a diagram for a specific feature.

Methods

attributeLegend

Returns True if renderer will show legend items for diagram attributes.

clone

Returns new instance that is equivalent to this one

convertSizeToMapUnits

Converts size from mm to map units

diagram

rtype

QgsDiagram

diagramAttributes

Returns attribute indices needed for diagram rendering

diagramSettings

Returns list with all diagram settings in the renderer

diagramSize

Returns size of the diagram (in painter units) or an invalid size in case of error

dpiPaintDevice

Returns the paint device dpi (or -1 in case of error

legendItems

Returns list of legend nodes for the diagram

readXml

Reads diagram state from a DOM element.

referencedFields

Returns the set of any fields required for diagram rendering

renderDiagram

Renders the diagram for a specified feature at a specific position in the passed render context.

rendererName

rtype

str

setAttributeLegend

Sets whether the renderer will show legend items for diagram attributes.

setDiagram

param d

sizeMapUnits

Returns size of the diagram for a feature in map units.

writeXml

Writes diagram state to a DOM element.

attributeLegend(self) → bool

Returns True if renderer will show legend items for diagram attributes.

New in version 2.16.

Return type

bool

clone(self) → QgsDiagramRenderer

Returns new instance that is equivalent to this one

New in version 2.4.

Return type

QgsDiagramRenderer

convertSizeToMapUnits(self, size: QSizeF, context: QgsRenderContext)

Converts size from mm to map units

Parameters
diagram(self) → QgsDiagram
Return type

QgsDiagram

diagramAttributes(self) → List[str]

Returns attribute indices needed for diagram rendering

Return type

List[str]

diagramSettings(self) → List[QgsDiagramSettings]

Returns list with all diagram settings in the renderer

diagramSettings(self, feature: QgsFeature, c: QgsRenderContext, s: QgsDiagramSettings) -> bool Returns diagram settings for a feature (or False if the diagram for the feature is not to be rendered). Used internally within renderDiagram()

Parameters
  • feature – the feature

  • c – render context

  • s – out: diagram settings for the feature

Return type

List[QgsDiagramSettings]

diagramSize(self, features: QgsFeature, c: QgsRenderContext) → QSizeF

Returns size of the diagram (in painter units) or an invalid size in case of error

Parameters
Return type

QSizeF

dpiPaintDevice(QPainter) → int

Returns the paint device dpi (or -1 in case of error

Return type

int

legendItems(self, nodeLayer: QgsLayerTreeLayer) → List[QgsLayerTreeModelLegendNode]

Returns list of legend nodes for the diagram

Note

caller is responsible for deletion of QgsLayerTreeModelLegendNodes

New in version 2.10.

Parameters

nodeLayer (QgsLayerTreeLayer) –

Return type

List[QgsLayerTreeModelLegendNode]

readXml(self, elem: QDomElement, context: QgsReadWriteContext)

Reads diagram state from a DOM element. Subclasses should ensure that _readXml() is called by their readXml implementation to restore the general QgsDiagramRenderer settings.

See also

writeXml()

Parameters
referencedFields(self, context: QgsExpressionContext = QgsExpressionContext()) → Set[str]

Returns the set of any fields required for diagram rendering

Parameters

context (QgsExpressionContext = QgsExpressionContext()) – expression context the diagrams will be drawn using

New in version 2.16.

Return type

Set[str]

renderDiagram(self, feature: QgsFeature, c: QgsRenderContext, pos: Union[QPointF, QPoint], properties: QgsPropertyCollection = QgsPropertyCollection())

Renders the diagram for a specified feature at a specific position in the passed render context.

Parameters
rendererName(self) → str
Return type

str

setAttributeLegend(self, enabled: bool)

Sets whether the renderer will show legend items for diagram attributes.

Parameters

enabled (bool) – set to True to show diagram attribute legend

New in version 2.16.

setDiagram(self, d: QgsDiagram)
Parameters

d (QgsDiagram) –

sizeMapUnits(self, feature: QgsFeature, c: QgsRenderContext) → QSizeF

Returns size of the diagram for a feature in map units. Returns an invalid QSizeF in case of error

Parameters
Return type

QSizeF

writeXml(self, layerElem: QDomElement, doc: QDomDocument, context: QgsReadWriteContext)

Writes diagram state to a DOM element. Subclasses should ensure that _writeXml() is called by their writeXml implementation to save the general QgsDiagramRenderer settings.

See also

readXml()

Parameters