17#include "moc_qgsmaprendererstagedrenderjob.cpp"
41void QgsMapRendererStagedRenderJob::startPrivate()
46 QgsDebugMsgLevel( QStringLiteral(
"Preparing list of layer jobs for rendering" ), 5 );
47 QElapsedTimer prepareTime;
50 mLabelingEngineV2.reset();
58 mLabelingEngineV2->setMapSettings(
mSettings );
61 mLayerJobs =
prepareJobs(
nullptr, mLabelingEngineV2.get(),
true );
64 mJobIt = mLayerJobs.begin();
91 if ( mLabelingEngineV2 )
92 return mLabelingEngineV2->takeResults();
104 if ( mJobIt != mLayerJobs.end() )
106 LayerRenderJob &job = *mJobIt;
108 job.renderer->renderContext()->setPainter( painter );
110 if ( job.context()->useAdvancedEffects() )
114 painter->setCompositionMode( job.blendMode );
117 if ( job.previewRenderImage && !job.previewRenderImageInitialized )
119 job.previewRenderImage->fill( 0 );
120 job.previewRenderImageInitialized =
true;
126 job.imageInitialized =
true;
129 job.completed = job.renderer->render();
134 painter->setOpacity( job.opacity );
135 painter->drawImage( 0, 0, *job.img );
136 painter->setOpacity( 1.0 );
138 job.context()->setPainter(
nullptr );
144 if ( !mLabelingEngineV2 )
149 if ( !mPreparedStagedLabelJob || mLabelLayerIt == mLabelingLayers.end() )
152 mLabelJob.context.setPainter( painter );
155 painter->setCompositionMode( QPainter::CompositionMode_SourceOver );
160 mLabelJob.context.setPainter(
nullptr );
164 mLabelJob.context.setPainter( painter );
165 drawLabeling( mLabelJob.context, mLabelingEngineV2.get(), painter );
166 mLabelJob.complete =
true;
168 mLabelJob.context.setPainter(
nullptr );
179 if ( mJobIt != mLayerJobs.end() )
182 if ( mJobIt != mLayerJobs.end() )
186 if ( mLabelingEngineV2 )
190 if ( !mPreparedStagedLabelJob )
192 mLabelingEngineV2->run( mLabelJob.context );
193 mPreparedStagedLabelJob =
true;
194 mLabelingLayers = mLabelingEngineV2->participatingLayerIds();
195 mLabelLayerIt = mLabelingLayers.begin();
196 if ( mLabelLayerIt == mLabelingLayers.end() )
206 if ( mLabelLayerIt != mLabelingLayers.end() )
209 if ( mLabelLayerIt != mLabelingLayers.end() )
219 mExportedLabels =
true;
221 else if ( !mExportedLabels )
238 if ( mJobIt != mLayerJobs.end() )
240 const LayerRenderJob &job = *mJobIt;
245 if ( mLabelLayerIt != mLabelingLayers.end() )
246 return *mLabelLayerIt;
253 if ( mJobIt != mLayerJobs.end() )
255 const LayerRenderJob &job = *mJobIt;
263 if ( mJobIt != mLayerJobs.end() )
265 const LayerRenderJob &job = *mJobIt;
266 return job.blendMode;
268 return QPainter::CompositionMode_SourceOver;
273 if ( mJobIt != mLayerJobs.end() )
277 if ( !mPreparedStagedLabelJob )
279 if ( mLabelLayerIt != mLabelingLayers.end() )
282 else if ( mNextIsLabel && !mExportedLabels )
@ DrawLabeling
Enable drawing of labels on top of the map.
Default QgsLabelingEngine implementation, which completes the whole labeling operation (including lab...
Class that stores computed placement from labeling engine.
Abstract base class for map renderer jobs which use custom painters.
void preparePainter(QPainter *painter, const QColor &backgroundColor=Qt::transparent)
Prepares the given painter ready for a map render.
QList< QPointer< QgsMapLayer > > participatingLabelLayers(QgsLabelingEngine *engine)
Returns a list of the layers participating in the map labeling.
static Q_DECL_DEPRECATED void drawLabeling(const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter)
void layerRendered(const QString &layerId)
Emitted when a layer has completed rendering.
std::vector< LayerRenderJob > prepareJobs(QPainter *painter, QgsLabelingEngine *labelingEngine2, bool deferredPainterSet=false)
Creates a list of layer rendering jobs and prepares them for later render.
void cleanupJobs(std::vector< LayerRenderJob > &jobs)
QElapsedTimer mRenderingStart
void layerRenderingStarted(const QString &layerId)
Emitted just before rendering starts for a particular layer.
LabelRenderJob prepareLabelingJob(QPainter *painter, QgsLabelingEngine *labelingEngine2, bool canUseLabelCache=true)
Prepares a labeling job.
void cleanupLabelJob(LabelRenderJob &job)
Handles clean up tasks for a label job, including deletion of images and storing cached label results...
double currentLayerOpacity() const
Returns the opacity for the current layer about to be rendered in the next render operation.
void cancel() override
Stop the rendering job - does not return until the job has terminated.
~QgsMapRendererStagedRenderJob() override
@ RenderLabelsByMapLayer
Labels should be rendered in individual stages by map layer. This allows separation of labels belongi...
bool usedCachedLabels() const override
Returns true if the render job was able to use a cached labeling solution.
RenderStage currentStage() const
Returns the current stage which will be rendered in the next render operation.
void waitForFinished() override
Block until the job has finished.
QPainter::CompositionMode currentLayerCompositionMode() const
Returns the composition mode for the current layer about to be rendered in the next render operation.
QString currentLayerId() const
Returns the ID of the current layer about to be rendered in the next render operation.
QgsLabelingResults * takeLabelingResults() override
Gets pointer to internal labeling engine (in order to get access to the results).
bool isActive() const override
Tell whether the rendering job is currently running in background.
QgsMapRendererStagedRenderJob(const QgsMapSettings &settings, Flags flags=Flags())
Constructor for QgsMapRendererStagedRenderJob, using the given map settings.
bool isFinished() const
Returns true if the job is finished, and nothing remains to render.
RenderStage
Represents the stages of a rendering job.
@ Finished
Rendering is finished.
@ Symbology
Rendering layer symbology.
@ Labels
Rendering labels.
bool nextPart()
Iterates to the next part to render.
bool renderCurrentPart(QPainter *painter)
Renders the current part of the map to the specified painter.
void cancelWithoutBlocking() override
Triggers cancellation of the rendering job without blocking.
The QgsMapSettings class contains configuration for rendering of the map.
bool testFlag(Qgis::MapSettingsFlag flag) const
Check whether a particular flag is enabled.
A QgsLabelingEngine implementation, which only calculates the labeling solution during its run() meth...
#define QgsDebugMsgLevel(str, level)