Skip to content

Commit 159f135

Browse files
committedOct 31, 2013
Removed QgsMapRendererV2 again in favour of using jobs directly
1 parent ef3c267 commit 159f135

File tree

9 files changed

+160
-255
lines changed

9 files changed

+160
-255
lines changed
 

‎src/app/maprenderertest.h

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "qgsmaprendererv2.h"
1010
#include "qgsmaplayer.h"
1111

12+
#include "qgsmaprendererjob.h"
13+
1214
class TestWidget : public QLabel
1315
{
1416
Q_OBJECT
@@ -21,18 +23,18 @@ class TestWidget : public QLabel
2123
i = QImage(size(), QImage::Format_ARGB32_Premultiplied);
2224
i.fill(Qt::gray);
2325

26+
job = 0;
27+
2428
// init renderer
25-
rend.setLayers(QStringList(layer->id()));
26-
rend.setExtent(layer->extent());
27-
rend.setOutputSize(i.size());
28-
rend.setOutputDpi(120);
29-
rend.updateDerived();
29+
ms.setLayers(QStringList(layer->id()));
30+
ms.setExtent(layer->extent());
31+
ms.setOutputSize(i.size());
32+
ms.setOutputDpi(120);
33+
ms.updateDerived();
3034

31-
if (rend.hasValidSettings())
35+
if (ms.hasValidSettings())
3236
qDebug("map renderer settings valid");
3337

34-
connect(&rend, SIGNAL(finished()), SLOT(f()));
35-
3638
setPixmap(QPixmap::fromImage(i));
3739

3840
connect(&timer, SIGNAL(timeout()), SLOT(onMapUpdateTimeout()));
@@ -45,24 +47,32 @@ class TestWidget : public QLabel
4547
{
4648
qDebug("cancelling!");
4749

48-
rend.cancel();
50+
if (job)
51+
{
52+
job->cancel();
53+
delete job;
54+
job = 0;
55+
}
4956
}
5057
else
5158
{
5259
qDebug("starting!");
5360

54-
if (rend.isRendering())
61+
if (job)
5562
{
5663
qDebug("need to cancel first!");
57-
rend.cancel();
58-
59-
// TODO: need to ensure that finished slot has been called
64+
job->cancel();
65+
delete job;
66+
job = 0;
6067
}
6168

6269
i.fill(Qt::gray);
6370

6471
painter = new QPainter(&i);
65-
rend.startWithCustomPainter(painter);
72+
73+
job = new QgsMapRendererCustomPainterJob(ms, painter);
74+
connect(job, SIGNAL(finished()), SLOT(f()));
75+
6676
timer.start();
6777
}
6878
}
@@ -93,7 +103,8 @@ protected slots:
93103
//QPixmap p;
94104
QImage i;
95105
QPainter* painter;
96-
QgsMapRendererV2 rend;
106+
QgsMapSettings ms;
107+
QgsMapRendererJob* job;
97108
QTimer timer;
98109
};
99110

‎src/core/qgsmaprendererjob.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@
88
#include "qgsmaplayer.h"
99
#include "qgsmaplayerregistry.h"
1010

11-
QgsMapRendererSequentialJob::QgsMapRendererSequentialJob(const QgsMapRendererSettings& settings)
12-
: QgsMapRendererJob(SequentialJob, settings)
11+
12+
QgsMapRendererQImageJob::QgsMapRendererQImageJob(QgsMapRendererJob::Type type, const QgsMapSettings& settings)
13+
: QgsMapRendererJob(type, settings)
14+
{
15+
}
16+
17+
18+
QgsMapRendererSequentialJob::QgsMapRendererSequentialJob(const QgsMapSettings& settings)
19+
: QgsMapRendererQImageJob(SequentialJob, settings)
1320
, mInternalJob(0)
1421
{
1522
}
@@ -57,7 +64,7 @@ void QgsMapRendererSequentialJob::internalFinished()
5764

5865

5966

60-
QgsMapRendererCustomPainterJob::QgsMapRendererCustomPainterJob(const QgsMapRendererSettings& settings, QPainter* painter)
67+
QgsMapRendererCustomPainterJob::QgsMapRendererCustomPainterJob(const QgsMapSettings& settings, QPainter* painter)
6168
: QgsMapRendererJob(CustomPainterJob, settings)
6269
, mPainter(painter)
6370
{
@@ -122,8 +129,8 @@ void QgsMapRendererCustomPainterJob::startRender()
122129
renderTime.start();
123130
#endif
124131

125-
mRenderContext.setMapToPixel( QgsMapToPixel( mSettings.mapUnitsPerPixel, mSettings.size.height(), mSettings.visibleExtent.yMinimum(), mSettings.visibleExtent.xMinimum() ) );
126-
mRenderContext.setExtent( mSettings.visibleExtent );
132+
mRenderContext.setMapToPixel( QgsMapToPixel( mSettings.mapUnitsPerPixel(), mSettings.outputSize().height(), mSettings.visibleExtent().yMinimum(), mSettings.visibleExtent().xMinimum() ) );
133+
mRenderContext.setExtent( mSettings.visibleExtent() );
127134

128135
mRenderContext.setDrawEditingInformation( false );
129136
mRenderContext.setPainter( mPainter );
@@ -196,7 +203,7 @@ void QgsMapRendererCustomPainterJob::startRender()
196203
}*/
197204

198205
// render all layers in the stack, starting at the base
199-
QListIterator<QString> li( mSettings.layers );
206+
QListIterator<QString> li( mSettings.layers() );
200207
li.toBack();
201208

202209
QgsRectangle r1, r2;
@@ -251,7 +258,7 @@ void QgsMapRendererCustomPainterJob::startRender()
251258
mypContextPainter->setCompositionMode( ml->blendMode() );
252259
}
253260

254-
if ( !ml->hasScaleBasedVisibility() || ( ml->minimumScale() <= mSettings.scale && mSettings.scale < ml->maximumScale() ) ) //|| mOverview )
261+
if ( !ml->hasScaleBasedVisibility() || ( ml->minimumScale() <= mSettings.scale() && mSettings.scale() < ml->maximumScale() ) ) //|| mOverview )
255262
{
256263
connect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );
257264

@@ -547,4 +554,3 @@ void QgsMapRendererCustomPainterJob::startRender()
547554

548555
}
549556

550-

‎src/core/qgsmaprendererjob.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class QgsMapRendererJob : public QObject
2222
};
2323

2424

25-
QgsMapRendererJob(Type type, const QgsMapRendererSettings& settings) : mType(type), mSettings(settings) { }
25+
QgsMapRendererJob(Type type, const QgsMapSettings& settings) : mType(type), mSettings(settings) { }
2626

2727
virtual ~QgsMapRendererJob() {}
2828

@@ -34,6 +34,8 @@ class QgsMapRendererJob : public QObject
3434
//! Stop the rendering job - does not return until the job has terminated.
3535
virtual void cancel() = 0;
3636

37+
// TODO: isActive() ?
38+
3739
signals:
3840

3941
//! emitted when asynchronous rendering is finished (or canceled).
@@ -43,14 +45,14 @@ class QgsMapRendererJob : public QObject
4345

4446
Type mType;
4547

46-
QgsMapRendererSettings mSettings;
48+
QgsMapSettings mSettings;
4749
};
4850

4951

50-
class QgsMapRendererJobWithPreview : public QgsMapRendererJob
52+
class QgsMapRendererQImageJob : public QgsMapRendererJob
5153
{
52-
5354
public:
55+
QgsMapRendererQImageJob(Type type, const QgsMapSettings& settings);
5456

5557
//! Get a preview/resulting image - in case QPainter has not been provided.
5658
//! With QPainter specified, it will return invalid QImage (there's no way to provide it).
@@ -62,11 +64,11 @@ class QgsMapRendererCustomPainterJob;
6264

6365

6466
/** job implementation that renders everything sequentially in one thread */
65-
class QgsMapRendererSequentialJob : public QgsMapRendererJobWithPreview
67+
class QgsMapRendererSequentialJob : public QgsMapRendererQImageJob
6668
{
6769
Q_OBJECT
6870
public:
69-
QgsMapRendererSequentialJob(const QgsMapRendererSettings& settings);
71+
QgsMapRendererSequentialJob(const QgsMapSettings& settings);
7072

7173
virtual void start();
7274
virtual void cancel();
@@ -103,7 +105,7 @@ class QgsMapRendererCustomPainterJob : public QgsMapRendererJob
103105
{
104106
Q_OBJECT
105107
public:
106-
QgsMapRendererCustomPainterJob(const QgsMapRendererSettings& settings, QPainter* painter);
108+
QgsMapRendererCustomPainterJob(const QgsMapSettings& settings, QPainter* painter);
107109

108110
virtual void start();
109111
virtual void cancel();

‎src/core/qgsmaprendererv2.cpp

Lines changed: 45 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -24,99 +24,24 @@ usage in QgsComposer
2424

2525

2626

27-
28-
QgsMapRendererV2::QgsMapRendererV2()
29-
: mActiveJob(0)
30-
, mScaleCalculator(new QgsScaleCalculator())
31-
{
32-
}
33-
34-
QgsMapRendererV2::~QgsMapRendererV2()
35-
{
36-
// make sure there is no job running
37-
cancel();
38-
39-
}
40-
41-
bool QgsMapRendererV2::start(bool parallel)
42-
{
43-
if (mActiveJob)
44-
return false;
45-
46-
if (parallel)
47-
{
48-
Q_ASSERT(false && "parallel job not implemented yet");
49-
return false;
50-
}
51-
else
52-
{
53-
mActiveJob = new QgsMapRendererSequentialJob(mSettings);
54-
}
55-
56-
connect(mActiveJob, SIGNAL(finished()), this, SLOT(onJobFinished()));
57-
58-
mActiveJob->start();
59-
return true;
60-
}
61-
62-
63-
bool QgsMapRendererV2::startWithCustomPainter(QPainter *painter)
64-
{
65-
if (mActiveJob)
66-
return false;
67-
68-
mActiveJob = new QgsMapRendererCustomPainterJob(mSettings, painter);
69-
70-
connect(mActiveJob, SIGNAL(finished()), this, SLOT(onJobFinished()));
71-
72-
mActiveJob->start();
73-
return true;
74-
}
75-
76-
bool QgsMapRendererV2::cancel()
77-
{
78-
if (!mActiveJob)
79-
return false;
80-
81-
mActiveJob->cancel();
82-
return true;
83-
}
84-
85-
86-
void QgsMapRendererV2::onJobFinished()
87-
{
88-
qDebug("onJobFinished");
89-
Q_ASSERT(mActiveJob);
90-
91-
emit finished();
92-
93-
mActiveJob->deleteLater();
94-
mActiveJob = 0;
95-
}
96-
97-
98-
99-
100-
101-
102-
QgsRectangle QgsMapRendererV2::extent() const
27+
QgsRectangle QgsMapSettings::extent() const
10328
{
104-
return mSettings.extent;
29+
return mExtent;
10530
}
10631

107-
void QgsMapRendererV2::setExtent(const QgsRectangle& extent)
32+
void QgsMapSettings::setExtent(const QgsRectangle& extent)
10833
{
109-
mSettings.extent = extent;
34+
mExtent = extent;
11035
}
11136

11237

113-
void QgsMapRendererV2::updateDerived()
38+
void QgsMapSettings::updateDerived()
11439
{
115-
QgsRectangle extent = mSettings.extent;
40+
QgsRectangle extent = mExtent;
11641

11742
if ( extent.isEmpty() )
11843
{
119-
mSettings.valid = false;
44+
mValid = false;
12045
return;
12146
}
12247

@@ -147,106 +72,106 @@ void QgsMapRendererV2::updateDerived()
14772
static const double minProportion = 1e-12;
14873
if ( xRange < minProportion || yRange < minProportion )
14974
{
150-
mSettings.valid = false;
75+
mValid = false;
15176
return;
15277
}
15378
}
15479

155-
double myHeight = mSettings.size.height();
156-
double myWidth = mSettings.size.width();
80+
double myHeight = mSize.height();
81+
double myWidth = mSize.width();
15782

15883
if ( !myWidth || !myHeight )
15984
{
160-
mSettings.valid = false;
85+
mValid = false;
16186
return;
16287
}
16388

16489
// calculate the translation and scaling parameters
165-
double mapUnitsPerPixelY = mSettings.extent.height() / myHeight;
166-
double mapUnitsPerPixelX = mSettings.extent.width() / myWidth;
167-
mSettings.mapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
90+
double mapUnitsPerPixelY = mExtent.height() / myHeight;
91+
double mapUnitsPerPixelX = mExtent.width() / myWidth;
92+
mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
16893

16994
// calculate the actual extent of the mapCanvas
170-
double dxmin = mSettings.extent.xMinimum(), dxmax = mSettings.extent.xMaximum(),
171-
dymin = mSettings.extent.yMinimum(), dymax = mSettings.extent.yMaximum(), whitespace;
95+
double dxmin = mExtent.xMinimum(), dxmax = mExtent.xMaximum(),
96+
dymin = mExtent.yMinimum(), dymax = mExtent.yMaximum(), whitespace;
17297

17398
if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
17499
{
175-
whitespace = (( myWidth * mSettings.mapUnitsPerPixel ) - mSettings.extent.width() ) * 0.5;
100+
whitespace = (( myWidth * mMapUnitsPerPixel ) - mExtent.width() ) * 0.5;
176101
dxmin -= whitespace;
177102
dxmax += whitespace;
178103
}
179104
else
180105
{
181-
whitespace = (( myHeight * mSettings.mapUnitsPerPixel ) - mSettings.extent.height() ) * 0.5;
106+
whitespace = (( myHeight * mMapUnitsPerPixel ) - mExtent.height() ) * 0.5;
182107
dymin -= whitespace;
183108
dymax += whitespace;
184109
}
185110

186-
mSettings.visibleExtent.set( dxmin, dymin, dxmax, dymax );
111+
mVisibleExtent.set( dxmin, dymin, dxmax, dymax );
187112

188113
// update the scale
189-
mSettings.scale = mScaleCalculator->calculate( mSettings.extent, mSettings.size.width() );
114+
mScale = mScaleCalculator.calculate( mExtent, mSize.width() );
190115

191116
QgsDebugMsg( QString( "Map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mapUnitsPerPixelX ) ).arg( qgsDoubleToString( mapUnitsPerPixelY ) ) );
192117
QgsDebugMsg( QString( "Pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( myWidth ) ).arg( qgsDoubleToString( myHeight ) ) );
193-
QgsDebugMsg( QString( "Extent dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mSettings.extent.width() ) ).arg( qgsDoubleToString( mSettings.extent.height() ) ) );
194-
QgsDebugMsg( mSettings.extent.toString() );
195-
QgsDebugMsg( QString( "Adjusted map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mSettings.visibleExtent.width() / myWidth ) ).arg( qgsDoubleToString( mSettings.visibleExtent.height() / myHeight ) ) );
196-
QgsDebugMsg( QString( "Recalced pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mSettings.visibleExtent.width() / mSettings.mapUnitsPerPixel ) ).arg( qgsDoubleToString( mSettings.visibleExtent.height() / mSettings.mapUnitsPerPixel ) ) );
197-
QgsDebugMsg( QString( "Scale (assuming meters as map units) = 1:%1" ).arg( qgsDoubleToString( mSettings.scale ) ) );
118+
QgsDebugMsg( QString( "Extent dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() ) ).arg( qgsDoubleToString( mExtent.height() ) ) );
119+
QgsDebugMsg( mExtent.toString() );
120+
QgsDebugMsg( QString( "Adjusted map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / myWidth ) ).arg( qgsDoubleToString( mVisibleExtent.height() / myHeight ) ) );
121+
QgsDebugMsg( QString( "Recalced pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mVisibleExtent.width() / mMapUnitsPerPixel ) ).arg( qgsDoubleToString( mVisibleExtent.height() / mMapUnitsPerPixel ) ) );
122+
QgsDebugMsg( QString( "Scale (assuming meters as map units) = 1:%1" ).arg( qgsDoubleToString( mScale ) ) );
198123

199124
}
200125

201126

202-
QSize QgsMapRendererV2::outputSize() const
127+
QSize QgsMapSettings::outputSize() const
203128
{
204-
return mSettings.size;
129+
return mSize;
205130
}
206131

207-
void QgsMapRendererV2::setOutputSize(const QSize& size)
132+
void QgsMapSettings::setOutputSize(const QSize& size)
208133
{
209-
mSettings.size = size;
134+
mSize = size;
210135
}
211136

212-
double QgsMapRendererV2::outputDpi() const
137+
double QgsMapSettings::outputDpi() const
213138
{
214-
return mSettings.dpi;
139+
return mDpi;
215140
}
216141

217-
void QgsMapRendererV2::setOutputDpi(double dpi)
142+
void QgsMapSettings::setOutputDpi(double dpi)
218143
{
219-
mSettings.dpi = dpi;
144+
mDpi = dpi;
220145
}
221146

222147

223-
QStringList QgsMapRendererV2::layers() const
148+
QStringList QgsMapSettings::layers() const
224149
{
225-
return mSettings.layers;
150+
return mLayers;
226151
}
227152

228-
void QgsMapRendererV2::setLayers(const QStringList& layers)
153+
void QgsMapSettings::setLayers(const QStringList& layers)
229154
{
230-
mSettings.layers = layers;
155+
mLayers = layers;
231156
}
232157

233158

234-
bool QgsMapRendererV2::hasValidSettings() const
159+
bool QgsMapSettings::hasValidSettings() const
235160
{
236-
return mSettings.valid;
161+
return mValid;
237162
}
238163

239-
QgsRectangle QgsMapRendererV2::visibleExtent() const
164+
QgsRectangle QgsMapSettings::visibleExtent() const
240165
{
241-
return mSettings.visibleExtent;
166+
return mVisibleExtent;
242167
}
243168

244-
double QgsMapRendererV2::mapUnitsPerPixel() const
169+
double QgsMapSettings::mapUnitsPerPixel() const
245170
{
246-
return mSettings.mapUnitsPerPixel;
171+
return mMapUnitsPerPixel;
247172
}
248173

249-
double QgsMapRendererV2::scale() const
174+
double QgsMapSettings::scale() const
250175
{
251-
return mSettings.scale;
176+
return mScale;
252177
}

‎src/core/qgsmaprendererv2.h

Lines changed: 17 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,12 @@ class QgsScaleCalculator;
1313
class QgsMapRendererJob;
1414

1515

16+
#include "qgsscalecalculator.h"
1617

17-
18-
struct QgsMapRendererSettings
18+
struct QgsMapSettings
1919
{
2020
// TODO
2121

22-
double dpi;
23-
24-
QSize size;
25-
26-
QgsRectangle extent;
27-
28-
QStringList layers;
29-
30-
bool projectionsEnabled;
31-
QgsCoordinateReferenceSystem destCRS;
32-
33-
// derived properties
34-
bool valid; //!< whether the actual settings are valid (set in updateDerived())
35-
QgsRectangle visibleExtent; //!< extent with some additional white space that matches the output aspect ratio
36-
double mapUnitsPerPixel;
37-
double scale;
38-
39-
40-
// TODO: utility functions
41-
42-
43-
};
44-
45-
46-
class QgsMapRendererV2 : public QObject
47-
{
48-
Q_OBJECT
49-
public:
50-
51-
QgsMapRendererV2();
52-
~QgsMapRendererV2();
53-
54-
//
55-
// getters/setters for rendering settings
56-
//
57-
5822
QgsRectangle extent() const;
5923
void setExtent(const QgsRectangle& rect);
6024

@@ -74,47 +38,31 @@ class QgsMapRendererV2 : public QObject
7438
double mapUnitsPerPixel() const;
7539
double scale() const;
7640

77-
//! Access all map renderer settings at once
78-
const QgsMapRendererSettings& settings() const { return mSettings; }
79-
80-
//
81-
// rendering control
82-
//
83-
84-
//! start rendering to a QImage with the current settings
85-
bool start(bool parallel = false);
86-
87-
//! start rendering with a custom painter (
88-
bool startWithCustomPainter(QPainter* painter);
41+
// TODO: utility functions
8942

90-
//! cancel the rendering job and wait until it stops
91-
bool cancel();
9243

93-
//! block until the rendering is done
94-
void waitForFinished();
44+
protected:
9545

96-
bool isRendering() const { return mActiveJob != 0; }
46+
double mDpi;
9747

98-
const QgsMapRendererJob* activeJob() const { return mActiveJob; }
48+
QSize mSize;
9949

100-
signals:
101-
void finished();
50+
QgsRectangle mExtent;
10251

103-
protected slots:
104-
void onJobFinished();
52+
QStringList mLayers;
10553

106-
protected:
107-
void updateScale();
108-
void adjustExtentToSize();
54+
bool mProjectionsEnabled;
55+
QgsCoordinateReferenceSystem mDestCRS;
10956

110-
protected:
111-
112-
QgsMapRendererSettings mSettings;
57+
// derived properties
58+
bool mValid; //!< whether the actual settings are valid (set in updateDerived())
59+
QgsRectangle mVisibleExtent; //!< extent with some additional white space that matches the output aspect ratio
60+
double mMapUnitsPerPixel;
61+
double mScale;
11362

114-
QgsScaleCalculator* mScaleCalculator;
11563

116-
//! currently running renderer job (null if there is none)
117-
QgsMapRendererJob* mActiveJob;
64+
// utiity stuff
65+
QgsScaleCalculator mScaleCalculator;
11866
};
11967

12068

‎src/gui/qgsmapcanvas.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ QgsMapCanvasMap* QgsMapCanvas::map()
186186
return mMap;
187187
}
188188

189-
/*QgsMapRenderer* QgsMapCanvas::mapRenderer()
189+
QgsMapRenderer* QgsMapCanvas::mapRenderer()
190190
{
191191
return mMapRenderer;
192-
}*/
192+
}
193193

194194

195195
QgsMapLayer* QgsMapCanvas::layer( int index )
@@ -350,7 +350,7 @@ void QgsMapCanvas::enableOverviewMode( QgsMapOverviewCanvas* overview )
350350
}
351351
}
352352

353-
const QgsMapRendererSettings &QgsMapCanvas::mapRendererSettings() const
353+
const QgsMapSettings &QgsMapCanvas::mapSettings() const
354354
{
355355
return mMap->settings();
356356
}

‎src/gui/qgsmapcanvas.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class QgsHighlight;
5757
class QgsVectorLayer;
5858

5959
class QgsMapRenderer;
60-
class QgsMapRendererSettings;
60+
class QgsMapSettings;
6161
class QgsMapCanvasMap;
6262
class QgsMapOverviewCanvas;
6363
class QgsMapTool;
@@ -119,13 +119,13 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
119119

120120
void enableOverviewMode( QgsMapOverviewCanvas* overview );
121121

122-
const QgsMapRendererSettings& mapRendererSettings() const;
122+
const QgsMapSettings& mapSettings() const;
123123

124124
//! @deprecated since 2.1 - there could be more than just one "map" items
125125
QgsMapCanvasMap* map();
126126

127127
//! @deprecated since 2.1 - use mapRendererSettings() for anything related to current renderer settings
128-
// temporarily disabled QgsMapRenderer* mapRenderer();
128+
Q_DECL_DEPRECATED QgsMapRenderer* mapRenderer();
129129

130130
//! Accessor for the canvas paint device
131131
//! @deprecated since 2.1

‎src/gui/qgsmapcanvasmap.cpp

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,30 @@
2525
QgsMapCanvasMap::QgsMapCanvasMap( QgsMapCanvas* canvas )
2626
: mCanvas( canvas )
2727
, mDirty(true)
28+
, mJob(0)
2829
{
29-
mRend = new QgsMapRendererV2();
30-
3130
setZValue( -10 );
3231
setPos( 0, 0 );
3332
resize( QSize( 1, 1 ) );
3433

35-
connect(mRend, SIGNAL(finished()), SLOT(finish()));
36-
3734
connect(&mTimer, SIGNAL(timeout()), SLOT(onMapUpdateTimeout()));
3835
mTimer.setInterval(400);
3936

4037
}
4138

4239
QgsMapCanvasMap::~QgsMapCanvasMap()
4340
{
44-
delete mRend;
45-
mRend = 0;
41+
delete mJob;
4642
}
4743

4844
void QgsMapCanvasMap::refresh()
4945
{
50-
if (mRend->isRendering())
46+
if (mJob)
5147
{
5248
qDebug("need to cancel first!");
53-
mRend->cancel();
49+
mJob->cancel();
50+
mJob->deleteLater();
51+
mJob = 0;
5452
}
5553

5654
mDirty = true;
@@ -61,30 +59,37 @@ void QgsMapCanvasMap::paint( QPainter* p, const QStyleOptionGraphicsItem*, QWidg
6159
{
6260
qDebug("paint()");
6361

62+
bool paintedAlready = false;
63+
6464
if (mDirty)
6565
{
66-
if (mRend->isRendering())
66+
if (mJob)
6767
{
6868
qDebug("already rendering");
6969
}
7070
else
7171
{
7272
qDebug("need to render");
7373

74+
// draw the image before it will be wiped out
75+
// TODO: does not work correctly with panning by dragging
76+
p->drawImage( 0, 0, mImage );
77+
paintedAlready = true;
78+
7479
QStringList layerIds;
7580
foreach (QgsMapLayer* l, mCanvas->layers())
7681
layerIds.append(l->id());
7782

78-
mRend->setLayers(layerIds);
79-
mRend->setExtent(mCanvas->extent());
80-
mRend->setOutputSize(mImage.size());
81-
mRend->setOutputDpi(120);
82-
mRend->updateDerived();
83+
mSettings.setLayers(layerIds);
84+
mSettings.setExtent(mCanvas->extent());
85+
mSettings.setOutputSize(mImage.size());
86+
mSettings.setOutputDpi(120);
87+
mSettings.updateDerived();
8388

84-
const QgsMapRendererSettings& s = mRend->settings();
85-
mMapToPixel = QgsMapToPixel( s.mapUnitsPerPixel, s.size.height(), s.visibleExtent.yMinimum(), s.visibleExtent.xMinimum() );
89+
const QgsMapSettings& s = mSettings;
90+
mMapToPixel = QgsMapToPixel( s.mapUnitsPerPixel(), s.outputSize().height(), s.visibleExtent().yMinimum(), s.visibleExtent().xMinimum() );
8691

87-
qDebug("----------> EXTENT %f,%f", mRend->extent().xMinimum(), mRend->extent().yMinimum());
92+
qDebug("----------> EXTENT %f,%f", mSettings.extent().xMinimum(), mSettings.extent().yMinimum());
8893

8994
mImage.fill(mBgColor.rgb());
9095

@@ -97,15 +102,18 @@ void QgsMapCanvasMap::paint( QPainter* p, const QStyleOptionGraphicsItem*, QWidg
97102
if ( mAntiAliasing )
98103
mPainter->setRenderHint( QPainter::Antialiasing );
99104

100-
mRend->startWithCustomPainter(mPainter);
105+
// create the renderer job
106+
Q_ASSERT(mJob == 0);
107+
mJob = new QgsMapRendererCustomPainterJob(mSettings, mPainter);
108+
connect(mJob, SIGNAL(finished()), SLOT(finish()));
109+
mJob->start();
101110

102111
mTimer.start();
103-
104-
//p->drawImage(0,0, mLastImage);
105-
//return; // do not redraw the image
106112
}
107113
}
108114

115+
if (!paintedAlready)
116+
{
109117
#ifdef EGA_MODE
110118
QImage i2( mImage.size()/3, mImage.format() );
111119
QPainter p2(&i2);
@@ -115,17 +123,17 @@ void QgsMapCanvasMap::paint( QPainter* p, const QStyleOptionGraphicsItem*, QWidg
115123
#else
116124
p->drawImage( 0, 0, mImage );
117125
#endif
118-
126+
}
119127
}
120128

121129
QRectF QgsMapCanvasMap::boundingRect() const
122130
{
123131
return QRectF( 0, 0, mImage.width(), mImage.height() );
124132
}
125133

126-
const QgsMapRendererSettings &QgsMapCanvasMap::settings() const
134+
const QgsMapSettings &QgsMapCanvasMap::settings() const
127135
{
128-
return mRend->settings();
136+
return mSettings;
129137
}
130138

131139
QgsMapToPixel *QgsMapCanvasMap::coordinateTransform()
@@ -136,10 +144,12 @@ QgsMapToPixel *QgsMapCanvasMap::coordinateTransform()
136144

137145
void QgsMapCanvasMap::resize( QSize size )
138146
{
139-
if (mRend->isRendering())
147+
if (mJob)
140148
{
141149
qDebug("need to cancel first!");
142-
mRend->cancel();
150+
mJob->cancel();
151+
mJob->deleteLater();
152+
mJob = 0;
143153
}
144154

145155
QgsDebugMsg( QString( "resizing to %1x%2" ).arg( size.width() ).arg( size.height() ) );

‎src/gui/qgsmapcanvasmap.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
#include <qgis.h>
2424
#include <qgsmaptopixel.h>
2525

26+
#include <qgsmaprendererjob.h>
27+
2628
class QgsMapRenderer;
27-
class QgsMapRendererSettings;
28-
class QgsMapRendererV2;
29+
class QgsMapSettings;
2930
class QgsMapCanvas;
3031

3132
/** \ingroup gui
@@ -65,7 +66,7 @@ class GUI_EXPORT QgsMapCanvasMap : public QObject, public QGraphicsRectItem
6566
//! @deprecated in 2.1 - does nothing. Kept for API compatibility
6667
void updateContents() {}
6768

68-
const QgsMapRendererSettings& settings() const;
69+
const QgsMapSettings& settings() const;
6970

7071
QgsMapToPixel* coordinateTransform(); // TODO: rename!
7172

@@ -90,7 +91,9 @@ public slots:
9091

9192
bool mDirty; //!< whether a new rendering job should be started upon next paint() call
9293

93-
QgsMapRendererV2* mRend;
94+
QgsMapSettings mSettings;
95+
96+
QgsMapRendererCustomPainterJob* mJob;
9497

9598
QPainter* mPainter;
9699

0 commit comments

Comments
 (0)
Please sign in to comment.