Class: QgsMapLayerRenderer

Base class for utility classes that encapsulate information necessary for rendering of map layers.

The rendering is typically done in a background thread, so it is necessary to keep all structures required for rendering away from the original map layer because it may change any time.

Because the data needs to be copied (to avoid the need for locking), it is highly desirable to use copy-on-write where possible. This way, the overhead of copying (both memory and CPU) will be kept low. Qt containers and various Qt classes use implicit sharing.

The scenario will be:

  1. renderer job (doing preparation in the GUI thread) calls QgsMapLayer.createMapRenderer() and gets instance of this class. The instance is initialized at that point and should not need additional calls to QgsVectorLayer.

  2. renderer job (still in GUI thread) stores the renderer for later use.

  3. renderer job (in worker thread) calls QgsMapLayerRenderer.render()

  4. renderer job (again in GUI thread) will check errors() and report them

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: render()

Abstract Methods

render

Do the rendering (based on data stored in the class).

Methods

appendRenderedItemDetails

Appends the details of a rendered item to the renderer.

errors

Returns list of errors (problems) that happened during the rendering

isReadyToCompose

Returns whether the renderer has already drawn (at least partially) some data

layerId

Gets access to the ID of the layer rendered by this class

renderContext

Returns the render context associated with the renderer.

takeRenderedItemDetails

Takes the list of rendered item details from the renderer.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsMapLayerRenderer. See the FAQ for more details.

feedback

Access to feedback object of the layer renderer (may be None)

flags

Returns flags which control how the map layer rendering behaves.

forceRasterRender

Returns True if the renderer must be rendered to a raster paint device (e.g. QImage).

class qgis.core.QgsMapLayerRenderer[source]

Bases: object

__init__(layerID: str | None, context: QgsRenderContext | None = None)

Constructor for QgsMapLayerRenderer, with the associated layerID and render context.

Parameters:
__init__(a0: QgsMapLayerRenderer)
Parameters:

a0 (QgsMapLayerRenderer)

appendRenderedItemDetails(self, details: QgsRenderedItemDetails | None)[source]

Appends the details of a rendered item to the renderer.

Rendered item details can be retrieved by calling takeRenderedItemDetails().

Ownership of details is transferred to the renderer.

Added in version 3.22.

Parameters:

details (Optional[QgsRenderedItemDetails])

errors(self) List[str][source]

Returns list of errors (problems) that happened during the rendering

Return type:

List[str]

virtual feedback(self) QgsFeedback | None[source]

Access to feedback object of the layer renderer (may be None)

Return type:

Optional[QgsFeedback]

virtual flags(self) Qgis.MapLayerRendererFlags[source]

Returns flags which control how the map layer rendering behaves.

Added in version 3.34.

Return type:

Qgis.MapLayerRendererFlags

virtual forceRasterRender(self) bool[source]

Returns True if the renderer must be rendered to a raster paint device (e.g. QImage).

Some layer settings require layers to be effectively “flattened” while rendering maps, which is achieved by first rendering the layer onto a raster paint device and then compositing the resultant image onto the final map render.

E.g. if a layer contains features with transparency or alternative blending modes, and the effects of these opacity or blending modes should be restricted to only affect other features within the SAME layer, then a flattened raster based render is required.

Subclasses should return True whenever their corresponding layer settings require the layer to always be rendered using a raster paint device.

Added in version 3.18.

Return type:

bool

isReadyToCompose(self) bool[source]

Returns whether the renderer has already drawn (at least partially) some data

Added in version 3.18.

Return type:

bool

layerId(self) str[source]

Gets access to the ID of the layer rendered by this class

Return type:

str

abstract render(self) bool[source]

Do the rendering (based on data stored in the class).

Returns True if the layer was completely rendered successfully (i.e. the render was not canceled early).

Return type:

bool

renderContext(self) QgsRenderContext | None[source]

Returns the render context associated with the renderer.

Added in version 3.10.

Return type:

Optional[QgsRenderContext]

takeRenderedItemDetails(self) List[QgsRenderedItemDetails]

Takes the list of rendered item details from the renderer.

Ownership of items is transferred to the caller.

Added in version 3.22.

Return type:

List[QgsRenderedItemDetails]