QgsMapRendererCustomPainterJob class
Job implementation that renders everything sequentially using a custom painter.
Contents
- Reference
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).
Base classes
- class QgsMapRendererJob
- Abstract base class for map rendering implementations.
Public functions
- void cancel() override
- Stop the rendering job - does not return until the job has terminated.
- void cancelWithoutBlocking() override
- Triggers cancelation of the rendering job without blocking.
- auto isActive() const -> bool override
- Tell whether the rendering job is currently running in background.
- auto jobs() const -> const LayerRenderJobs&
- void renderSynchronously()
- Render the map synchronously in this thread.
- void start() override
- Start the rendering job and immediately return.
- auto takeLabelingResults() -> QgsLabelingResults* override
- Gets pointer to internal labeling engine (in order to get access to the results).
- auto usedCachedLabels() const -> bool override
- Returns true if the render job was able to use a cached labeling solution.
- void waitForFinished() override
- Block until the job has finished.
- void waitForFinishedWithEventLoop(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents)
- Wait for the job to be finished - and keep the thread's event loop running while waiting.
Function documentation
void QgsMapRendererCustomPainterJob:: cancel() override
Stop the rendering job - does not return until the job has terminated.
Does nothing if the rendering is not active.
void QgsMapRendererCustomPainterJob:: cancelWithoutBlocking() override
Triggers cancelation of the rendering job without blocking.
The render job will continue to operate until it is able to cancel, at which stage the finished() signal will be emitted. Does nothing if the rendering is not active.
const LayerRenderJobs& QgsMapRendererCustomPainterJob:: jobs() const
void QgsMapRendererCustomPainterJob:: renderSynchronously()
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.
void QgsMapRendererCustomPainterJob:: start() override
Start the rendering job and immediately return.
Does nothing if the rendering is already in progress.
QgsLabelingResults* QgsMapRendererCustomPainterJob:: takeLabelingResults() override
Gets pointer to internal labeling engine (in order to get access to the results).
This should not be used if cached labeling was redrawn - see usedCachedLabels().
bool QgsMapRendererCustomPainterJob:: usedCachedLabels() const override
Returns true if the render job was able to use a cached labeling solution.
If so, any previously stored labeling results (see takeLabelingResults()) should be retained.
void QgsMapRendererCustomPainterJob:: waitForFinishedWithEventLoop(QEventLoop::ProcessEventsFlags flags = 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.