QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
22 
24  : QgsMapRendererQImageJob( settings )
25  , mInternalJob( nullptr )
26  , mPainter( nullptr )
27  , mLabelingResults( nullptr )
28 {
29  QgsDebugMsg( "SEQUENTIAL construct" );
30 
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  QgsDebugMsg( "SEQUENTIAL destruct" );
40  if ( isActive() )
41  {
42  // still running!
43  QgsDebugMsg( "SEQUENTIAL destruct -- still running! (cancelling)" );
44  cancel();
45  }
46 
47  Q_ASSERT( !mInternalJob && !mPainter );
48 
49  delete mLabelingResults;
50  mLabelingResults = nullptr;
51 }
52 
53 
55 {
56  if ( isActive() )
57  return; // do nothing if we are already running
58 
60 
61  mErrors.clear();
62 
63  QgsDebugMsg( "SEQUENTIAL START" );
64 
65  Q_ASSERT( !mInternalJob && !mPainter );
66 
67  mPainter = new QPainter( &mImage );
68 
71 
72  connect( mInternalJob, SIGNAL( finished() ), SLOT( internalFinished() ) );
73 
75 }
76 
77 
79 {
80  if ( !isActive() )
81  return;
82 
83  QgsDebugMsg( "sequential - cancel internal" );
85 
86  Q_ASSERT( !mInternalJob && !mPainter );
87 }
88 
90 {
91  if ( !isActive() )
92  return;
93 
94  QgsDebugMsg( "sequential - cancel internal" );
96 }
97 
99 {
100  if ( !isActive() )
101  return;
102 
104 }
105 
107 {
108  return nullptr != mInternalJob;
109 }
110 
112 {
114  mLabelingResults = nullptr;
115  return tmp;
116 }
117 
118 
120 {
121  if ( isActive() && mCache )
122  // this will allow immediate display of cached layers and at the same time updates of the layer being rendered
123  return composeImage( mSettings, mInternalJob->jobs() );
124  else
125  return mImage;
126 }
127 
128 
130 {
131  QgsDebugMsg( "SEQUENTIAL finished" );
132 
133  mPainter->end();
134  delete mPainter;
135  mPainter = nullptr;
136 
138 
140 
141  // now we are in a slot called from mInternalJob - do not delete it immediately
142  // so the class is still valid when the execution returns to the class
144  mInternalJob = nullptr;
145 
147 
148  emit finished();
149 }
150 
void clear()
void finished()
emitted when asynchronous rendering is finished (or canceled).
const LayerRenderJobs & jobs() const
void setDotsPerMeterX(int x)
void setDotsPerMeterY(int y)
Job implementation that renders everything sequentially using a custom painter.
virtual void start() override
Start the rendering job and immediately return.
bool end()
static QImage composeImage(const QgsMapSettings &settings, const LayerRenderJobs &jobs)
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
virtual void cancel() override
Stop the rendering job - does not return until the job has terminated.
virtual void cancel() override
Stop the rendering job - does not return until the job has terminated.
virtual QgsLabelingResults * takeLabelingResults() override
Get pointer to internal labeling engine (in order to get access to the results)
void setCache(QgsMapRendererCache *cache)
Assign a cache to be used for reading and storing rendered images of individual layers.
The QgsMapSettings class contains configuration for rendering of the map.
int elapsed() const
virtual void start() override
Start the rendering job and immediately return.
void fill(uint pixelValue)
Errors errors() const
List of errors that happened during the rendering job - available when the rendering has been finishe...
QgsMapRendererSequentialJob(const QgsMapSettings &settings)
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
void deleteLater()
QgsMapSettings mSettings
virtual void cancelWithoutBlocking() override
Triggers cancellation of the rendering job without blocking.
double outputDpi() const
Return DPI used for conversion between real world units (e.g.
virtual QImage renderedImage() override
Get a preview/resulting image.
Intermediate base class adding functionality that allows client to query the rendered image...
QgsMapRendererCustomPainterJob * mInternalJob
virtual void cancelWithoutBlocking() override
Triggers cancellation of the rendering job without blocking.
void start()
Class that stores computed placement from labeling engine.
virtual bool isActive() const override
Tell whether the rendering job is currently running in background.
virtual void waitForFinished() override
Block until the job has finished.
virtual QgsLabelingResults * takeLabelingResults() override
Get pointer to internal labeling engine (in order to get access to the results)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual void waitForFinished() override
Block until the job has finished.
QgsMapRendererCache * mCache
QSize outputSize() const
Return the size of the resulting map image.