QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
Public Member Functions | List of all members
QgsMapRendererCustomPainterJob Class Reference

Job implementation that renders everything sequentially using a custom painter. More...

#include <qgsmaprenderercustompainterjob.h>

Inheritance diagram for QgsMapRendererCustomPainterJob:
Inheritance graph
[legend]

Public Member Functions

 QgsMapRendererCustomPainterJob (const QgsMapSettings &settings, QPainter *painter)
 
 ~QgsMapRendererCustomPainterJob () override
 
void cancel () override
 Stop the rendering job - does not return until the job has terminated. More...
 
void cancelWithoutBlocking () override
 Triggers cancellation of the rendering job without blocking. More...
 
bool isActive () const override
 Tell whether the rendering job is currently running in background. More...
 
const std::vector< LayerRenderJob > & jobs () const
 
void prepare ()
 Prepares the job for rendering synchronously in a background thread. More...
 
void renderPrepared ()
 Render a pre-prepared job. More...
 
void renderSynchronously ()
 Render the map synchronously in this thread. More...
 
QgsLabelingResultstakeLabelingResults () override
 Gets pointer to internal labeling engine (in order to get access to the results). More...
 
bool usedCachedLabels () const override
 Returns true if the render job was able to use a cached labeling solution. More...
 
void waitForFinished () override
 Block until the job has finished. More...
 
void waitForFinishedWithEventLoop (QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
 Wait for the job to be finished - and keep the thread's event loop running while waiting. More...
 
- Public Member Functions inherited from QgsMapRendererAbstractCustomPainterJob
 QgsMapRendererAbstractCustomPainterJob (const QgsMapSettings &settings)
 Constructor for QgsMapRendererAbstractCustomPainterJob, using the given map settings. More...
 
- Public Member Functions inherited from QgsMapRendererJob
 QgsMapRendererJob (const QgsMapSettings &settings)
 
 ~QgsMapRendererJob () override
 
virtual void cancel ()=0
 Stop the rendering job - does not return until the job has terminated. More...
 
virtual void cancelWithoutBlocking ()=0
 Triggers cancellation of the rendering job without blocking. More...
 
Errors errors () const
 List of errors that happened during the rendering job - available when the rendering has been finished. More...
 
const QgsFeatureFilterProviderfeatureFilterProvider () const
 Returns the feature filter provider used by the QgsRenderContext of each LayerRenderJob. More...
 
virtual bool isActive () const =0
 Tell whether the rendering job is currently running in background. More...
 
QgsLabelingEngineFeedbacklabelingEngineFeedback ()
 Returns the associated labeling engine feedback object. More...
 
QgsLabelSinklabelSink () const
 Returns the label sink associated to this rendering job. More...
 
QStringList layersRedrawnFromCache () const
 Returns a list of the layer IDs for all layers which were redrawn from cached images. More...
 
const QgsMapSettingsmapSettings () const
 Returns map settings with which this job was started. More...
 
QHash< QgsMapLayer *, int > perLayerRenderingTime () const
 Returns the render time (in ms) per layer. More...
 
int renderingTime () const
 Returns the total time it took to finish the job (in milliseconds). More...
 
void setCache (QgsMapRendererCache *cache)
 Assign a cache to be used for reading and storing rendered images of individual layers. More...
 
void setFeatureFilterProvider (const QgsFeatureFilterProvider *f)
 Set the feature filter provider used by the QgsRenderContext of each LayerRenderJob. More...
 
void setLabelSink (QgsLabelSink *sink)
 Assigns the label sink which will take over responsibility for handling labels during the rendering job. More...
 
void setLayerRenderingTimeHints (const QHash< QString, int > &hints)
 Sets approximate render times (in ms) for map layers. More...
 
void start ()
 Start the rendering job and immediately return. More...
 
virtual QgsLabelingResultstakeLabelingResults ()=0
 Gets pointer to internal labeling engine (in order to get access to the results). More...
 
QgsRenderedItemResultstakeRenderedItemResults ()
 Takes the rendered item results from the map render job and returns them. More...
 
virtual bool usedCachedLabels () const =0
 Returns true if the render job was able to use a cached labeling solution. More...
 
virtual void waitForFinished ()=0
 Block until the job has finished. More...
 

Additional Inherited Members

- Public Types inherited from QgsMapRendererJob
typedef QList< QgsMapRendererJob::ErrorErrors
 
- Signals inherited from QgsMapRendererJob
void finished ()
 emitted when asynchronous rendering is finished (or canceled). More...
 
void layerRendered (const QString &layerId)
 Emitted when a layer has completed rendering. More...
 
void layerRenderingStarted (const QString &layerId)
 Emitted just before rendering starts for a particular layer. More...
 
void renderingLayersFinished ()
 Emitted when the layers are rendered. More...
 
- Static Public Attributes inherited from QgsMapRendererJob
static const QString LABEL_CACHE_ID
 QgsMapRendererCache ID string for cached label image. More...
 
static const QString LABEL_PREVIEW_CACHE_ID
 QgsMapRendererCache ID string for cached label image during preview compositions only. More...
 
static const QgsSettingsEntryBool settingsLogCanvasRefreshEvent = QgsSettingsEntryBool( QStringLiteral( "logCanvasRefreshEvent" ), QgsSettings::Prefix::MAP, false )
 Settings entry log canvas refresh event. More...
 
- Protected Member Functions inherited from QgsMapRendererAbstractCustomPainterJob
void preparePainter (QPainter *painter, const QColor &backgroundColor=Qt::transparent)
 Prepares the given painter ready for a map render. More...
 
- Protected Member Functions inherited from QgsMapRendererJob
void cleanupJobs (std::vector< LayerRenderJob > &jobs)
 
void cleanupLabelJob (LabelRenderJob &job)
 Handles clean up tasks for a label job, including deletion of images and storing cached label results. More...
 
void cleanupSecondPassJobs (std::vector< LayerRenderJob > &jobs)
 
void initSecondPassJobs (std::vector< LayerRenderJob > &secondPassJobs, LabelRenderJob &labelJob) const
 Initialize secondPassJobs according to what have been rendered (mask clipping path e.g.) in first pass jobs and labelJob. More...
 
void logRenderingTime (const std::vector< LayerRenderJob > &jobs, const std::vector< LayerRenderJob > &secondPassJobs, const LabelRenderJob &labelJob)
 
std::vector< LayerRenderJob > prepareJobs (QPainter *painter, QgsLabelingEngine *labelingEngine2, bool deferredPainterSet=false)
 Creates a list of layer rendering jobs and prepares them for later render. More...
 
bool prepareLabelCache () const
 Prepares the cache for storing the result of labeling. More...
 
LabelRenderJob prepareLabelingJob (QPainter *painter, QgsLabelingEngine *labelingEngine2, bool canUseLabelCache=true)
 Prepares a labeling job. More...
 
std::vector< LayerRenderJob > prepareSecondPassJobs (std::vector< LayerRenderJob > &firstPassJobs, LabelRenderJob &labelJob)
 Prepares jobs for a second pass, if selective masks exist (from labels or symbol layers). More...
 
- Static Protected Member Functions inherited from QgsMapRendererJob
static QImage composeImage (const QgsMapSettings &settings, const std::vector< LayerRenderJob > &jobs, const LabelRenderJob &labelJob, const QgsMapRendererCache *cache=nullptr)
 
static void composeSecondPass (std::vector< LayerRenderJob > &secondPassJobs, LabelRenderJob &labelJob, bool forceVector=false)
 Compose second pass images into first pass images. More...
 
static Q_DECL_DEPRECATED void drawLabeling (const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter)
 
static void drawLabeling (QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter)
 
static QImage layerImageToBeComposed (const QgsMapSettings &settings, const LayerRenderJob &job, const QgsMapRendererCache *cache)
 
- Protected Attributes inherited from QgsMapRendererJob
QgsMapRendererCachemCache = nullptr
 
Errors mErrors
 
QHash< QString, int > mLayerRenderingTimeHints
 Approximate expected layer rendering time per layer, by layer ID. More...
 
QStringList mLayersRedrawnFromCache
 
QHash< QgsWeakMapLayerPointer, int > mPerLayerRenderingTime
 Render time (in ms) per layer, by layer ID. More...
 
bool mRecordRenderingTime = true
 true if layer rendering time should be recorded. More...
 
std::unique_ptr< QgsRenderedItemResultsmRenderedItemResults
 
QElapsedTimer mRenderingStart
 
int mRenderingTime = 0
 
QgsMapSettings mSettings
 

Detailed Description

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).

Since
QGIS 2.4

Definition at line 63 of file qgsmaprenderercustompainterjob.h.

Constructor & Destructor Documentation

◆ QgsMapRendererCustomPainterJob()

QgsMapRendererCustomPainterJob::QgsMapRendererCustomPainterJob ( const QgsMapSettings settings,
QPainter *  painter 
)

Definition at line 75 of file qgsmaprenderercustompainterjob.cpp.

◆ ~QgsMapRendererCustomPainterJob()

QgsMapRendererCustomPainterJob::~QgsMapRendererCustomPainterJob ( )
override

Definition at line 84 of file qgsmaprenderercustompainterjob.cpp.

Member Function Documentation

◆ cancel()

void QgsMapRendererCustomPainterJob::cancel ( )
overridevirtual

Stop the rendering job - does not return until the job has terminated.

Does nothing if the rendering is not active.

Implements QgsMapRendererJob.

Definition at line 144 of file qgsmaprenderercustompainterjob.cpp.

◆ cancelWithoutBlocking()

void QgsMapRendererCustomPainterJob::cancelWithoutBlocking ( )
overridevirtual

Triggers cancellation 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.

Implements QgsMapRendererJob.

Definition at line 168 of file qgsmaprenderercustompainterjob.cpp.

◆ isActive()

bool QgsMapRendererCustomPainterJob::isActive ( ) const
overridevirtual

Tell whether the rendering job is currently running in background.

Implements QgsMapRendererJob.

Definition at line 202 of file qgsmaprenderercustompainterjob.cpp.

◆ jobs()

const std::vector< LayerRenderJob > & QgsMapRendererCustomPainterJob::jobs ( ) const
inline
Note
not available in Python bindings

Definition at line 78 of file qgsmaprenderercustompainterjob.h.

◆ prepare()

void QgsMapRendererCustomPainterJob::prepare ( )

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()
Since
QGIS 3.10

Definition at line 237 of file qgsmaprenderercustompainterjob.cpp.

◆ renderPrepared()

void QgsMapRendererCustomPainterJob::renderPrepared ( )

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).

Since
QGIS 3.10

Definition at line 245 of file qgsmaprenderercustompainterjob.cpp.

◆ renderSynchronously()

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.

Definition at line 229 of file qgsmaprenderercustompainterjob.cpp.

◆ takeLabelingResults()

QgsLabelingResults * QgsMapRendererCustomPainterJob::takeLabelingResults ( )
overridevirtual

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().

See also
usedCachedLabels()

Implements QgsMapRendererJob.

Definition at line 212 of file qgsmaprenderercustompainterjob.cpp.

◆ usedCachedLabels()

bool QgsMapRendererCustomPainterJob::usedCachedLabels ( ) const
overridevirtual

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.

See also
takeLabelingResults()
Since
QGIS 3.0

Implements QgsMapRendererJob.

Definition at line 207 of file qgsmaprenderercustompainterjob.cpp.

◆ waitForFinished()

void QgsMapRendererCustomPainterJob::waitForFinished ( )
overridevirtual

Block until the job has finished.

Implements QgsMapRendererJob.

Definition at line 185 of file qgsmaprenderercustompainterjob.cpp.

◆ waitForFinishedWithEventLoop()

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.

Definition at line 221 of file qgsmaprenderercustompainterjob.cpp.


The documentation for this class was generated from the following files: