QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
qgsmaprenderersequentialjob.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaprenderersequentialjob.cpp
3 --------------------------------------
4 Date : December 2013
5 Copyright : (C) 2013 by Martin Dobias
6 Email : wonder dot sk at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17
18#include "qgslogger.h"
20#include "qgspallabeling.h"
21#include "qgslabelingresults.h"
23
25 : QgsMapRendererQImageJob( settings )
26
27{
28 QgsDebugMsgLevel( QStringLiteral( "SEQUENTIAL construct" ), 5 );
29
31 mImage.setDevicePixelRatio( mSettings.devicePixelRatio() );
32 mImage.setDotsPerMeterX( 1000 * settings.outputDpi() / 25.4 );
33 mImage.setDotsPerMeterY( 1000 * settings.outputDpi() / 25.4 );
34 mImage.fill( Qt::transparent );
35}
36
38{
39 QgsDebugMsgLevel( QStringLiteral( "SEQUENTIAL destruct" ), 5 );
40 if ( isActive() )
41 {
42 // still running!
43 QgsDebugMsgLevel( QStringLiteral( "SEQUENTIAL destruct -- still running! (canceling)" ), 5 );
44 cancel();
45 }
46
47 Q_ASSERT( !mInternalJob && !mPainter );
48}
49
50
51void QgsMapRendererSequentialJob::startPrivate()
52{
53 if ( isActive() )
54 return; // do nothing if we are already running
55
56 mLabelingResults.reset();
57
58 mRenderingStart.start();
59
60 mErrors.clear();
61
62 QgsDebugMsgLevel( QStringLiteral( "SEQUENTIAL START" ), 5 );
63
64 Q_ASSERT( !mInternalJob && !mPainter );
65
66 mPainter = new QPainter( &mImage );
67
68 mInternalJob = new QgsMapRendererCustomPainterJob( mSettings, mPainter );
69 mInternalJob->setLabelSink( labelSink() );
70 mInternalJob->setCache( mCache );
71
75
76 mInternalJob->start();
77}
78
79
81{
82 if ( !isActive() )
83 return;
84
85 QgsDebugMsgLevel( QStringLiteral( "sequential - cancel internal" ), 5 );
86 // cppcheck-suppress nullPointerRedundantCheck
87 mInternalJob->cancel();
88
89 Q_ASSERT( !mInternalJob && !mPainter );
90}
91
93{
94 if ( !isActive() )
95 return;
96
97 QgsDebugMsgLevel( QStringLiteral( "sequential - cancel internal" ), 5 );
98 mInternalJob->cancelWithoutBlocking();
99}
100
102{
103 if ( !isActive() )
104 return;
105
106 mInternalJob->waitForFinished();
107}
108
110{
111 return nullptr != mInternalJob;
112}
113
115{
116 return mUsedCachedLabels;
117}
118
120{
121 return mLabelingResults.release();
122}
123
124
126{
127 if ( isActive() && mCache )
128 // this will allow immediate display of cached layers and at the same time updates of the layer being rendered
129 return composeImage( mSettings, mInternalJob->jobs(), LabelRenderJob() );
130 else
131 return mImage;
132}
133
134
136{
137 QgsDebugMsgLevel( QStringLiteral( "SEQUENTIAL finished" ), 5 );
138
139 mPainter->end();
140 delete mPainter;
141 mPainter = nullptr;
142
143 mLabelingResults.reset( mInternalJob->takeLabelingResults() );
144 mUsedCachedLabels = mInternalJob->usedCachedLabels();
146
147 mRenderedItemResults.reset( mInternalJob->takeRenderedItemResults() );
148
149 mErrors = mInternalJob->errors();
150
151 // now we are in a slot called from mInternalJob - do not delete it immediately
152 // so the class is still valid when the execution returns to the class
153 mInternalJob->deleteLater();
154 mInternalJob = nullptr;
155
157
158 emit finished();
159}
Class that stores computed placement from labeling engine.
Job implementation that renders everything sequentially using a custom painter.
void cancel() override
Stop the rendering job - does not return until the job has terminated.
QgsLabelingResults * takeLabelingResults() override
Gets pointer to internal labeling engine (in order to get access to the results).
void cancelWithoutBlocking() override
Triggers cancellation of the rendering job without blocking.
void waitForFinished() override
Block until the job has finished.
const std::vector< LayerRenderJob > & jobs() const
bool usedCachedLabels() const override
Returns true if the render job was able to use a cached labeling solution.
static QImage composeImage(const QgsMapSettings &settings, const std::vector< LayerRenderJob > &jobs, const LabelRenderJob &labelJob, const QgsMapRendererCache *cache=nullptr)
void setCache(QgsMapRendererCache *cache)
Assign a cache to be used for reading and storing rendered images of individual layers.
void setLabelSink(QgsLabelSink *sink)
Assigns the label sink which will take over responsibility for handling labels during the rendering j...
std::unique_ptr< QgsRenderedItemResults > mRenderedItemResults
Errors errors() const
List of errors that happened during the rendering job - available when the rendering has been finishe...
void layerRendered(const QString &layerId)
Emitted when a layer has completed rendering.
QElapsedTimer mRenderingStart
QgsMapRendererCache * mCache
void finished()
emitted when asynchronous rendering is finished (or canceled).
QgsMapSettings mSettings
void start()
Start the rendering job and immediately return.
void layerRenderingStarted(const QString &layerId)
Emitted just before rendering starts for a particular layer.
QStringList mLayersRedrawnFromCache
QStringList layersRedrawnFromCache() const
Returns a list of the layer IDs for all layers which were redrawn from cached images.
QgsRenderedItemResults * takeRenderedItemResults()
Takes the rendered item results from the map render job and returns them.
QgsLabelSink * labelSink() const
Returns the label sink associated to this rendering job.
Intermediate base class adding functionality that allows client to query the rendered image.
bool usedCachedLabels() const override
Returns true if the render job was able to use a cached labeling solution.
void cancelWithoutBlocking() override
Triggers cancellation of the rendering job without blocking.
QImage renderedImage() override
Gets a preview/resulting image.
void waitForFinished() override
Block until the job has finished.
void cancel() override
Stop the rendering job - does not return until the job has terminated.
QgsLabelingResults * takeLabelingResults() override
Gets pointer to internal labeling engine (in order to get access to the results).
QgsMapRendererSequentialJob(const QgsMapSettings &settings)
bool isActive() const override
Tell whether the rendering job is currently running in background.
The QgsMapSettings class contains configuration for rendering of the map.
QSize deviceOutputSize() const
Returns the device output size of the map render.
float devicePixelRatio() const
Returns the device pixel ratio.
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
double outputDpi() const
Returns the DPI (dots per inch) used for conversion between real world units (e.g.
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39