QGIS API Documentation  2.14.0-Essen
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 
95 }
96 
98 {
99  return nullptr != mInternalJob;
100 }
101 
103 {
105  mLabelingResults = nullptr;
106  return tmp;
107 }
108 
109 
111 {
112  if ( isActive() && mCache )
113  // this will allow immediate display of cached layers and at the same time updates of the layer being rendered
114  return composeImage( mSettings, mInternalJob->jobs() );
115  else
116  return mImage;
117 }
118 
119 
121 {
122  QgsDebugMsg( "SEQUENTIAL finished" );
123 
124  mPainter->end();
125  delete mPainter;
126  mPainter = nullptr;
127 
129 
131 
132  // now we are in a slot called from mInternalJob - do not delete it immediately
133  // so the class is still valid when the execution returns to the class
135  mInternalJob = nullptr;
136 
138 
139  emit finished();
140 }
141 
void clear()
void finished()
emitted when asynchronous rendering is finished (or canceled).
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
int outputDpi() const
Return DPI used for conversion between real world units (e.g.
virtual void start() override
Start the rendering job and immediately return.
void fill(uint pixelValue)
QSize outputSize() const
Return the size of the resulting map image.
QgsMapRendererSequentialJob(const QgsMapSettings &settings)
const LayerRenderJobs & jobs() const
void deleteLater()
QgsMapSettings mSettings
virtual QImage renderedImage() override
Get a preview/resulting image.
Intermediate base class adding functionality that allows client to query the rendered image...
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
QgsMapRendererCustomPainterJob * mInternalJob
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)
Errors errors() const
List of errors that happened during the rendering job - available when the rendering has been finishe...
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