QGIS API Documentation 4.3.0-Master (c8cdfe19d7b)
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 "qgslabelingresults.h"
19#include "qgslogger.h"
21#include "qgspallabeling.h"
23
24#include <QString>
25
26#include "moc_qgsmaprenderersequentialjob.cpp"
27
28using namespace Qt::StringLiterals;
29
31 : QgsMapRendererQImageJob( settings )
32
33{
34 QgsDebugMsgLevel( u"SEQUENTIAL construct"_s, 5 );
35
36 mImage = QImage( mSettings.deviceOutputSize(), mSettings.outputImageFormat() );
37 mImage.setDevicePixelRatio( mSettings.devicePixelRatio() );
38 mImage.setDotsPerMeterX( static_cast< int >( 1000 * settings.outputDpi() / 25.4 ) );
39 mImage.setDotsPerMeterY( static_cast< int >( 1000 * settings.outputDpi() / 25.4 ) );
40 mImage.fill( Qt::transparent );
41}
42
44{
45 QgsDebugMsgLevel( u"SEQUENTIAL destruct"_s, 5 );
46 if ( isActive() )
47 {
48 // still running!
49 QgsDebugMsgLevel( u"SEQUENTIAL destruct -- still running! (canceling)"_s, 5 );
50 cancel();
51 }
52
53 Q_ASSERT( !mInternalJob && !mPainter );
54}
55
56
57void QgsMapRendererSequentialJob::startPrivate()
58{
59 if ( isActive() )
60 return; // do nothing if we are already running
61
62 mLabelingResults.reset();
63
64 mRenderingStart.start();
65
66 mErrors.clear();
67
68 QgsDebugMsgLevel( u"SEQUENTIAL START"_s, 5 );
69
70 Q_ASSERT( !mInternalJob && !mPainter );
71
72 mPainter = new QPainter( &mImage );
73
74 mInternalJob = new QgsMapRendererCustomPainterJob( mSettings, mPainter );
75 mInternalJob->setLabelSink( labelSink() );
76 mInternalJob->setCache( mCache );
77
81
82 mInternalJob->start();
83}
84
85
87{
88 if ( !isActive() )
89 return;
90
91 QgsDebugMsgLevel( u"sequential - cancel internal"_s, 5 );
92 // cppcheck-suppress nullPointerRedundantCheck
93 mInternalJob->cancel();
94
95 Q_ASSERT( !mInternalJob && !mPainter );
96}
97
99{
100 if ( !isActive() )
101 return;
102
103 QgsDebugMsgLevel( u"sequential - cancel internal"_s, 5 );
104 mInternalJob->cancelWithoutBlocking();
105}
106
108{
109 if ( !isActive() )
110 return;
111
112 mInternalJob->waitForFinished();
113}
114
116{
117 return nullptr != mInternalJob;
118}
119
121{
122 return mUsedCachedLabels;
123}
124
126{
127 return mLabelingResults.release();
128}
129
130
132{
133 if ( isActive() && mCache )
134 // this will allow immediate display of cached layers and at the same time updates of the layer being rendered
135 return composeImage( mSettings, mInternalJob->jobs(), LabelRenderJob() );
136 else
137 return mImage;
138}
139
140
142{
143 QgsDebugMsgLevel( u"SEQUENTIAL finished"_s, 5 );
144
145 mPainter->end();
146 delete mPainter;
147 mPainter = nullptr;
148
149 mLabelingResults.reset( mInternalJob->takeLabelingResults() );
150 mUsedCachedLabels = mInternalJob->usedCachedLabels();
151 mLayersRedrawnFromCache = mInternalJob->layersRedrawnFromCache();
152
153 mRenderedItemResults.reset( mInternalJob->takeRenderedItemResults() );
154
155 mErrors = mInternalJob->errors();
156
157 // now we are in a slot called from mInternalJob - do not delete it immediately
158 // so the class is still valid when the execution returns to the class
159 mInternalJob->deleteLater();
160 mInternalJob = nullptr;
161
163
164 emit finished();
165}
Stores computed placement from labeling engine.
Job implementation that renders everything sequentially using a custom painter.
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
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
QgsLabelSink * labelSink() const
Returns the label sink associated to this rendering job.
QgsMapRendererQImageJob(const QgsMapSettings &settings)
bool usedCachedLabels() const final
Returns true if the render job was able to use a cached labeling solution.
void waitForFinished() final
Block until the job has finished.
void cancelWithoutBlocking() final
Triggers cancellation of the rendering job without blocking.
QgsLabelingResults * takeLabelingResults() final
Gets pointer to internal labeling engine (in order to get access to the results).
QImage renderedImage() final
Gets a preview/resulting image.
void cancel() final
Stop the rendering job - does not return until the job has terminated.
bool isActive() const final
Tell whether the rendering job is currently running in background.
QgsMapRendererSequentialJob(const QgsMapSettings &settings)
Contains configuration for rendering maps.
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:80