QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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  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