QGIS API Documentation 3.41.0-Master (af5edcb665c)
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#include "moc_qgsmaprenderersequentialjob.cpp"
18
19#include "qgslogger.h"
21#include "qgspallabeling.h"
22#include "qgslabelingresults.h"
24
26 : QgsMapRendererQImageJob( settings )
27
28{
29 QgsDebugMsgLevel( QStringLiteral( "SEQUENTIAL construct" ), 5 );
30
32 mImage.setDevicePixelRatio( mSettings.devicePixelRatio() );
33 mImage.setDotsPerMeterX( 1000 * settings.outputDpi() / 25.4 );
34 mImage.setDotsPerMeterY( 1000 * settings.outputDpi() / 25.4 );
35 mImage.fill( Qt::transparent );
36}
37
39{
40 QgsDebugMsgLevel( QStringLiteral( "SEQUENTIAL destruct" ), 5 );
41 if ( isActive() )
42 {
43 // still running!
44 QgsDebugMsgLevel( QStringLiteral( "SEQUENTIAL destruct -- still running! (canceling)" ), 5 );
45 cancel();
46 }
47
48 Q_ASSERT( !mInternalJob && !mPainter );
49}
50
51
52void QgsMapRendererSequentialJob::startPrivate()
53{
54 if ( isActive() )
55 return; // do nothing if we are already running
56
57 mLabelingResults.reset();
58
59 mRenderingStart.start();
60
61 mErrors.clear();
62
63 QgsDebugMsgLevel( QStringLiteral( "SEQUENTIAL START" ), 5 );
64
65 Q_ASSERT( !mInternalJob && !mPainter );
66
67 mPainter = new QPainter( &mImage );
68
69 mInternalJob = new QgsMapRendererCustomPainterJob( mSettings, mPainter );
70 mInternalJob->setLabelSink( labelSink() );
71 mInternalJob->setCache( mCache );
72
76
77 mInternalJob->start();
78}
79
80
82{
83 if ( !isActive() )
84 return;
85
86 QgsDebugMsgLevel( QStringLiteral( "sequential - cancel internal" ), 5 );
87 // cppcheck-suppress nullPointerRedundantCheck
88 mInternalJob->cancel();
89
90 Q_ASSERT( !mInternalJob && !mPainter );
91}
92
94{
95 if ( !isActive() )
96 return;
97
98 QgsDebugMsgLevel( QStringLiteral( "sequential - cancel internal" ), 5 );
99 mInternalJob->cancelWithoutBlocking();
100}
101
103{
104 if ( !isActive() )
105 return;
106
107 mInternalJob->waitForFinished();
108}
109
111{
112 return nullptr != mInternalJob;
113}
114
116{
117 return mUsedCachedLabels;
118}
119
121{
122 return mLabelingResults.release();
123}
124
125
127{
128 if ( isActive() && mCache )
129 // this will allow immediate display of cached layers and at the same time updates of the layer being rendered
130 return composeImage( mSettings, mInternalJob->jobs(), LabelRenderJob() );
131 else
132 return mImage;
133}
134
135
137{
138 QgsDebugMsgLevel( QStringLiteral( "SEQUENTIAL finished" ), 5 );
139
140 mPainter->end();
141 delete mPainter;
142 mPainter = nullptr;
143
144 mLabelingResults.reset( mInternalJob->takeLabelingResults() );
145 mUsedCachedLabels = mInternalJob->usedCachedLabels();
147
148 mRenderedItemResults.reset( mInternalJob->takeRenderedItemResults() );
149
150 mErrors = mInternalJob->errors();
151
152 // now we are in a slot called from mInternalJob - do not delete it immediately
153 // so the class is still valid when the execution returns to the class
154 mInternalJob->deleteLater();
155 mInternalJob = nullptr;
156
158
159 emit finished();
160}
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