QGIS API Documentation
2.8.2-Wien
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
src
core
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
16
#include "
qgsmaprenderersequentialjob.h
"
17
18
#include "
qgslogger.h
"
19
#include "
qgsmaprenderercustompainterjob.h
"
20
#include "
qgspallabeling.h
"
21
22
23
QgsMapRendererSequentialJob::QgsMapRendererSequentialJob
(
const
QgsMapSettings
& settings )
24
:
QgsMapRendererQImageJob
( settings )
25
, mInternalJob( 0 )
26
, mPainter( 0 )
27
, mLabelingResults( 0 )
28
{
29
QgsDebugMsg
(
"SEQUENTIAL construct"
);
30
31
mImage
= QImage(
mSettings
.
outputSize
(),
mSettings
.
outputImageFormat
() );
32
mImage
.setDotsPerMeterX( 1000 * settings.
outputDpi
() / 25.4 );
33
mImage
.setDotsPerMeterY( 1000 * settings.
outputDpi
() / 25.4 );
34
}
35
36
QgsMapRendererSequentialJob::~QgsMapRendererSequentialJob
()
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
53
void
QgsMapRendererSequentialJob::start
()
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
68
mInternalJob
=
new
QgsMapRendererCustomPainterJob
(
mSettings
,
mPainter
);
69
mInternalJob
->
setCache
(
mCache
);
70
71
connect(
mInternalJob
, SIGNAL(
finished
() ), SLOT(
internalFinished
() ) );
72
73
mInternalJob
->
start
();
74
}
75
76
77
void
QgsMapRendererSequentialJob::cancel
()
78
{
79
if
( !
isActive
() )
80
return
;
81
82
QgsDebugMsg
(
"sequential - cancel internal"
);
83
mInternalJob
->
cancel
();
84
85
Q_ASSERT(
mInternalJob
== 0 &&
mPainter
== 0 );
86
}
87
88
void
QgsMapRendererSequentialJob::waitForFinished
()
89
{
90
if
( !
isActive
() )
91
return
;
92
93
mInternalJob
->
waitForFinished
();
94
}
95
96
bool
QgsMapRendererSequentialJob::isActive
()
const
97
{
98
return
mInternalJob
!= 0;
99
}
100
101
QgsLabelingResults
*
QgsMapRendererSequentialJob::takeLabelingResults
()
102
{
103
QgsLabelingResults
* tmp =
mLabelingResults
;
104
mLabelingResults
= 0;
105
return
tmp;
106
}
107
108
109
QImage
QgsMapRendererSequentialJob::renderedImage
()
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
119
void
QgsMapRendererSequentialJob::internalFinished
()
120
{
121
QgsDebugMsg
(
"SEQUENTIAL finished"
);
122
123
mPainter
->end();
124
delete
mPainter
;
125
mPainter
= 0;
126
127
mLabelingResults
=
mInternalJob
->
takeLabelingResults
();
128
129
mErrors
=
mInternalJob
->
errors
();
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
Generated on Sun May 10 2015 16:33:24 for QGIS API Documentation by
1.8.1.2