Class: QgsMapRendererCustomPainterJob

class qgis.core.QgsMapRendererCustomPainterJob

Bases: QgsMapRendererAbstractCustomPainterJob

Job implementation that renders everything sequentially using a custom painter.

Also supports synchronous rendering in main thread for cases when rendering in background is not an option because of some technical limitations (e.g. printing to printer on some platforms).

New in version 2.4:

Methods

cancel

cancelWithoutBlocking

childEvent

connectNotify

customEvent

disconnectNotify

isActive

rtype:

bool

isSignalConnected

prepare

Prepares the job for rendering synchronously in a background thread.

preparePainter

receivers

renderPrepared

Render a pre-prepared job.

renderSynchronously

Render the map synchronously in this thread.

sender

senderSignalIndex

takeLabelingResults

rtype:

QgsLabelingResults

timerEvent

usedCachedLabels

rtype:

bool

waitForFinished

waitForFinishedWithEventLoop

Wait for the job to be finished - and keep the thread's event loop running while waiting.

cancel(self)
cancelWithoutBlocking(self)
childEvent(self, QChildEvent)
connectNotify(self, QMetaMethod)
customEvent(self, QEvent)
disconnectNotify(self, QMetaMethod)
isActive(self) bool
Return type:

bool

isSignalConnected(self, QMetaMethod) bool
prepare(self)

Prepares the job for rendering synchronously in a background thread.

Must be called from the main thread.

This is an alternative to ordinary API (using start() + waiting for finished() signal), and an alternative to renderSynchronously() (which should only ever be called from the main thread).

See also

renderPrepared()

New in version 3.10.

preparePainter()
receivers(self, PYQT_SIGNAL) int
renderPrepared(self)

Render a pre-prepared job. Can be safely called in a background thread.

Must be preceded by a call to prepare()

This is an alternative to ordinary API (using start() + waiting for finished() signal), and an alternative to renderSynchronously() (which should only ever be called from the main thread).

New in version 3.10.

renderSynchronously(self)

Render the map synchronously in this thread. The function does not return until the map is completely rendered.

This is an alternative to ordinary API (using start() + waiting for finished() signal). Users are discouraged to use this method unless they have a strong reason for doing it. The synchronous rendering blocks the main thread, making the application unresponsive. Also, it is not possible to cancel rendering while it is in progress.

sender(self) QObject
senderSignalIndex(self) int
takeLabelingResults(self) QgsLabelingResults
Return type:

QgsLabelingResults

timerEvent(self, QTimerEvent)
usedCachedLabels(self) bool
Return type:

bool

waitForFinished(self)
waitForFinishedWithEventLoop(self, flags: QEventLoop.ProcessEventsFlags | QEventLoop.ProcessEventsFlag = QEventLoop.AllEvents)

Wait for the job to be finished - and keep the thread’s event loop running while waiting.

With a call to waitForFinished(), the waiting is done with a synchronization primitive and does not involve processing of messages. That may cause issues to code which requires some events to be handled in the main thread. Some plugins hooking into the rendering pipeline may require this in order to work properly - for example, OpenLayers plugin which uses a QWebPage in the main thread.

Ideally the “wait for finished” method should not be used at all. The code triggering rendering should not need to actively wait for rendering to finish.

Parameters:

flags (Union[QEventLoop.ProcessEventsFlags) –