QGIS API Documentation  2.9.0-Master
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( 0 )
26  , mPainter( 0 )
27  , mLabelingResults( 0 )
28 {
29  QgsDebugMsg( "SEQUENTIAL construct" );
30 
32  mImage.setDotsPerMeterX( 1000 * settings.outputDpi() / 25.4 );
33  mImage.setDotsPerMeterY( 1000 * settings.outputDpi() / 25.4 );
34 }
35 
37 {
38  QgsDebugMsg( "SEQUENTIAL destruct" );
39  if ( isActive() )
40  {
41  // still running!
42  QgsDebugMsg( "SEQUENTIAL destruct -- still running! (cancelling)" );
43  cancel();
44  }
45 
46  Q_ASSERT( mInternalJob == 0 && mPainter == 0 );
47 
48  delete mLabelingResults;
49  mLabelingResults = 0;
50 }
51 
52 
54 {
55  if ( isActive() )
56  return; // do nothing if we are already running
57 
58  mRenderingStart.start();
59 
60  mErrors.clear();
61 
62  QgsDebugMsg( "SEQUENTIAL START" );
63 
64  Q_ASSERT( mInternalJob == 0 && mPainter == 0 );
65 
66  mPainter = new QPainter( &mImage );
67 
70 
71  connect( mInternalJob, SIGNAL( finished() ), SLOT( internalFinished() ) );
72 
74 }
75 
76 
78 {
79  if ( !isActive() )
80  return;
81 
82  QgsDebugMsg( "sequential - cancel internal" );
84 
85  Q_ASSERT( mInternalJob == 0 && mPainter == 0 );
86 }
87 
89 {
90  if ( !isActive() )
91  return;
92 
94 }
95 
97 {
98  return mInternalJob != 0;
99 }
100 
102 {
104  mLabelingResults = 0;
105  return tmp;
106 }
107 
108 
110 {
111  if ( isActive() && mCache )
112  // this will allow immediate display of cached layers and at the same time updates of the layer being rendered
113  return composeImage( mSettings, mInternalJob->jobs() );
114  else
115  return mImage;
116 }
117 
118 
120 {
121  QgsDebugMsg( "SEQUENTIAL finished" );
122 
123  mPainter->end();
124  delete mPainter;
125  mPainter = 0;
126 
128 
130 
131  // now we are in a slot called from mInternalJob - do not delete it immediately
132  // so the class is still valid when the execution returns to the class
133  mInternalJob->deleteLater();
134  mInternalJob = 0;
135 
136  mRenderingTime = mRenderingStart.elapsed();
137 
138  emit finished();
139 }
140 
void finished()
emitted when asynchronous rendering is finished (or canceled).
Job implementation that renders everything sequentially using a custom painter.
virtual void start() override
Start the rendering job and immediately return.
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 outputDpi() const
Return DPI used for conversion between real world units (e.g.
virtual void start() override
Start the rendering job and immediately return.
QSize outputSize() const
Return the size of the resulting map image.
QgsMapRendererSequentialJob(const QgsMapSettings &settings)
const LayerRenderJobs & jobs() const
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
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...
virtual void waitForFinished() override
Block until the job has finished.
QgsMapRendererCache * mCache