QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 }
33 
35 {
36  QgsDebugMsg( "SEQUENTIAL destruct" );
37  if ( isActive() )
38  {
39  // still running!
40  QgsDebugMsg( "SEQUENTIAL destruct -- still running! (cancelling)" );
41  cancel();
42  }
43 
44  Q_ASSERT( mInternalJob == 0 && mPainter == 0 );
45 
46  delete mLabelingResults;
47  mLabelingResults = 0;
48 }
49 
50 
52 {
53  if ( isActive() )
54  return; // do nothing if we are already running
55 
56  mRenderingStart.start();
57 
58  mErrors.clear();
59 
60  QgsDebugMsg( "SEQUENTIAL START" );
61 
62  Q_ASSERT( mInternalJob == 0 && mPainter == 0 );
63 
64  mPainter = new QPainter( &mImage );
65 
68 
69  connect( mInternalJob, SIGNAL( finished() ), SLOT( internalFinished() ) );
70 
72 }
73 
74 
76 {
77  if ( !isActive() )
78  return;
79 
80  QgsDebugMsg( "sequential - cancel internal" );
82 
83  Q_ASSERT( mInternalJob == 0 && mPainter == 0 );
84 }
85 
87 {
88  if ( !isActive() )
89  return;
90 
92 }
93 
95 {
96  return mInternalJob != 0;
97 }
98 
100 {
102  mLabelingResults = 0;
103  return tmp;
104 }
105 
106 
108 {
109  if ( isActive() && mCache )
110  // this will allow immediate display of cached layers and at the same time updates of the layer being rendered
111  return composeImage( mSettings, mInternalJob->jobs() );
112  else
113  return mImage;
114 }
115 
116 
118 {
119  QgsDebugMsg( "SEQUENTIAL finished" );
120 
121  mPainter->end();
122  delete mPainter;
123  mPainter = 0;
124 
126 
128 
129  // now we are in a slot called from mInternalJob - do not delete it immediately
130  // so the class is still valid when the execution returns to the class
131  mInternalJob->deleteLater();
132  mInternalJob = 0;
133 
134  mRenderingTime = mRenderingStart.elapsed();
135 
136  emit finished();
137 }
138 
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.
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