@@ -115,16 +115,9 @@ QgsComposerMap::~QgsComposerMap()
115
115
{
116
116
delete mOverviewStack ;
117
117
delete mGridStack ;
118
-
119
- if ( mPainterJob )
120
- {
121
- disconnect ( mPainterJob .get (), &QgsMapRendererCustomPainterJob::finished, this , &QgsComposerMap::painterJobFinished );
122
- mPainterJob ->cancel ();
123
- mPainter ->end ();
124
- }
125
118
}
126
119
127
- /* This function is called by paint() to render the map. It does not override any functions
120
+ /* This function is called by paint() and cache() to render the map. It does not override any functions
128
121
from QGraphicsItem. */
129
122
void QgsComposerMap::draw ( QPainter *painter, const QgsRectangle &extent, QSizeF size, double dpi, double *forceWidthScale )
130
123
{
@@ -213,28 +206,12 @@ void QgsComposerMap::cache()
213
206
return ;
214
207
}
215
208
216
- if ( mPainterJob )
217
- {
218
- disconnect ( mPainterJob .get (), &QgsMapRendererCustomPainterJob::finished, this , &QgsComposerMap::painterJobFinished );
219
- QgsMapRendererCustomPainterJob *oldJob = mPainterJob .release ();
220
- QPainter *oldPainter = mPainter .release ();
221
- QImage *oldImage = mCacheRenderingImage .release ();
222
- connect ( oldJob, &QgsMapRendererCustomPainterJob::finished, this , [oldPainter, oldJob, oldImage]
223
- {
224
- oldJob->deleteLater ();
225
- delete oldPainter;
226
- delete oldImage;
227
- } );
228
- oldJob->cancelWithoutBlocking ();
229
- }
230
- else
209
+ if ( mDrawing )
231
210
{
232
- mCacheRenderingImage . reset ( nullptr ) ;
211
+ return ;
233
212
}
234
213
235
- Q_ASSERT ( !mPainterJob );
236
- Q_ASSERT ( !mPainter );
237
- Q_ASSERT ( !mCacheRenderingImage );
214
+ mDrawing = true ;
238
215
239
216
double horizontalVScaleFactor = horizontalViewScaleFactor ();
240
217
if ( horizontalVScaleFactor < 0 )
@@ -265,51 +242,38 @@ void QgsComposerMap::cache()
265
242
}
266
243
}
267
244
268
- if ( w <= 0 || h <= 0 )
269
- return ;
270
-
271
- mCacheRenderingImage .reset ( new QImage ( w, h, QImage::Format_ARGB32 ) );
245
+ mCacheImage = QImage ( w, h, QImage::Format_ARGB32 );
272
246
273
247
// set DPI of the image
274
- mCacheRenderingImage -> setDotsPerMeterX ( 1000 * w / widthMM );
275
- mCacheRenderingImage -> setDotsPerMeterY ( 1000 * h / heightMM );
248
+ mCacheImage . setDotsPerMeterX ( 1000 * w / widthMM );
249
+ mCacheImage . setDotsPerMeterY ( 1000 * h / heightMM );
276
250
277
251
if ( hasBackground () )
278
252
{
279
253
// Initially fill image with specified background color. This ensures that layers with blend modes will
280
254
// preview correctly
281
- mCacheRenderingImage -> fill ( backgroundColor ().rgba () );
255
+ mCacheImage . fill ( backgroundColor ().rgba () );
282
256
}
283
257
else
284
258
{
285
259
// no background, but start with empty fill to avoid artifacts
286
- mCacheRenderingImage -> fill ( QColor ( 255 , 255 , 255 , 0 ).rgba () );
260
+ mCacheImage . fill ( QColor ( 255 , 255 , 255 , 0 ).rgba () );
287
261
}
288
262
289
- mPainter .reset ( new QPainter ( mCacheRenderingImage .get () ) );
290
- QgsMapSettings settings ( mapSettings ( ext, QSizeF ( w, h ), mCacheRenderingImage ->logicalDpiX () ) );
291
- mPainterJob .reset ( new QgsMapRendererCustomPainterJob ( settings, mPainter .get () ) );
292
- connect ( mPainterJob .get (), &QgsMapRendererCustomPainterJob::finished, this , &QgsComposerMap::painterJobFinished );
293
- mPainterJob ->start ();
294
- }
263
+ QPainter p ( &mCacheImage );
295
264
296
- void QgsComposerMap::painterJobFinished ()
297
- {
298
- mPainter ->end ();
299
- mPainterJob .reset ( nullptr );
300
- mPainter .reset ( nullptr );
265
+ draw ( &p, ext, QSizeF ( w, h ), mCacheImage .logicalDpiX () );
266
+ p.end ();
301
267
mCacheUpdated = true ;
302
- mCacheFinalImage = std::move ( mCacheRenderingImage );
303
- mLastRenderedImageOffsetX = 0 ;
304
- mLastRenderedImageOffsetY = 0 ;
305
- updateItem ();
268
+
269
+ mDrawing = false ;
306
270
}
307
271
308
272
void QgsComposerMap::paint ( QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *pWidget )
309
273
{
310
274
Q_UNUSED ( pWidget );
311
275
312
- if ( !mComposition || !painter || !painter-> device () )
276
+ if ( !mComposition || !painter )
313
277
{
314
278
return ;
315
279
}
@@ -319,9 +283,6 @@ void QgsComposerMap::paint( QPainter *painter, const QStyleOptionGraphicsItem *,
319
283
}
320
284
321
285
QRectF thisPaintRect = QRectF ( 0 , 0 , QGraphicsRectItem::rect ().width (), QGraphicsRectItem::rect ().height () );
322
- if ( thisPaintRect.width () == 0 || thisPaintRect.height () == 0 )
323
- return ;
324
-
325
286
painter->save ();
326
287
painter->setClipRect ( thisPaintRect );
327
288
@@ -336,40 +297,22 @@ void QgsComposerMap::paint( QPainter *painter, const QStyleOptionGraphicsItem *,
336
297
}
337
298
else if ( mComposition ->plotStyle () == QgsComposition::Preview )
338
299
{
339
- if ( !mCacheFinalImage || mCacheFinalImage ->isNull () )
340
- {
341
- // No initial render available - so draw some preview text alerting user
342
- drawBackground ( painter );
343
- painter->setBrush ( QBrush ( QColor ( 125 , 125 , 125 , 125 ) ) );
344
- painter->drawRect ( thisPaintRect );
345
- painter->setBrush ( Qt::NoBrush );
346
- QFont messageFont;
347
- messageFont.setPointSize ( 12 );
348
- painter->setFont ( messageFont );
349
- painter->setPen ( QColor ( 255 , 255 , 255 , 255 ) );
350
- painter->drawText ( thisPaintRect, Qt::AlignCenter | Qt::AlignHCenter, tr ( " Rendering map" ) );
351
- if ( !mPainterJob )
352
- {
353
- // this is the map's very first paint - trigger a cache update
354
- cache ();
355
- }
356
- }
357
- else
358
- {
359
- // Background color is already included in cached image, so no need to draw
300
+ if ( mCacheImage .isNull () )
301
+ cache ();
360
302
361
- double imagePixelWidth = mCacheFinalImage ->width (); // how many pixels of the image are for the map extent?
362
- double scale = rect ().width () / imagePixelWidth;
303
+ // Background color is already included in cached image, so no need to draw
363
304
364
- painter->save ();
305
+ double imagePixelWidth = mCacheImage .width (); // how many pixels of the image are for the map extent?
306
+ double scale = rect ().width () / imagePixelWidth;
365
307
366
- painter->translate ( mLastRenderedImageOffsetX + mXOffset , mLastRenderedImageOffsetY + mYOffset );
367
- painter->scale ( scale, scale );
368
- painter->drawImage ( 0 , 0 , *mCacheFinalImage );
308
+ painter->save ();
369
309
370
- // restore rotation
371
- painter->restore ();
372
- }
310
+ painter->translate ( mXOffset , mYOffset );
311
+ painter->scale ( scale, scale );
312
+ painter->drawImage ( 0 , 0 , mCacheImage );
313
+
314
+ // restore rotation
315
+ painter->restore ();
373
316
}
374
317
else if ( mComposition ->plotStyle () == QgsComposition::Print ||
375
318
mComposition ->plotStyle () == QgsComposition::Postscript )
@@ -622,8 +565,6 @@ void QgsComposerMap::resize( double dx, double dy )
622
565
623
566
void QgsComposerMap::moveContent ( double dx, double dy )
624
567
{
625
- mLastRenderedImageOffsetX -= dx;
626
- mLastRenderedImageOffsetY -= dy;
627
568
if ( !mDrawing )
628
569
{
629
570
transformShift ( dx, dy );
@@ -732,7 +673,7 @@ void QgsComposerMap::setSceneRect( const QRectF &rectangle )
732
673
mCacheUpdated = false ;
733
674
734
675
updateBoundingRect ();
735
- updateItem ();
676
+ update ();
736
677
emit itemChanged ();
737
678
emit extentChanged ();
738
679
}
0 commit comments