Skip to content

Commit 855e1f6

Browse files
manisandronyalldawson
authored andcommitted
Asyncronously render composer map previews
(Forward port from Sourcepole fork)
1 parent 8d03642 commit 855e1f6

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

src/core/composer/qgscomposermap.cpp

+29-8
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,20 @@ void QgsComposerMap::cache()
206206
return;
207207
}
208208

209-
if ( mDrawing )
209+
if ( mPainterJob )
210210
{
211-
return;
211+
if ( mPainterCancelWait )
212+
{
213+
return; // Already waiting
214+
}
215+
QgsDebugMsg( "Aborting composer painter job" );
216+
mPainterCancelWait = true;
217+
mPainterJob->cancel();
218+
mPainterCancelWait = false;
212219
}
213220

214-
mDrawing = true;
221+
Q_ASSERT( !mPainterJob );
222+
Q_ASSERT( !mPainter );
215223

216224
double horizontalVScaleFactor = horizontalViewScaleFactor();
217225
if ( horizontalVScaleFactor < 0 )
@@ -260,13 +268,24 @@ void QgsComposerMap::cache()
260268
mCacheImage.fill( QColor( 255, 255, 255, 0 ).rgba() );
261269
}
262270

263-
QPainter p( &mCacheImage );
271+
mPainter = new QPainter( &mCacheImage );
272+
QgsMapSettings settings( mapSettings( ext, QSizeF( w, h ), mCacheImage.logicalDpiX() ) );
273+
mPainterJob = new QgsMapRendererCustomPainterJob( settings, mPainter );
274+
connect( mPainterJob, SIGNAL( finished() ), this, SLOT( painterJobFinished() ) );
275+
QgsDebugMsg( "Starting new composer painter job" );
276+
mPainterJob->start();
277+
}
264278

265-
draw( &p, ext, QSizeF( w, h ), mCacheImage.logicalDpiX() );
266-
p.end();
279+
void QgsComposerMap::painterJobFinished()
280+
{
281+
QgsDebugMsg( "Finished composer painter job" );
282+
mPainter->end();
283+
delete mPainterJob;
284+
mPainterJob = nullptr;
285+
delete mPainter;
286+
mPainter = nullptr;
267287
mCacheUpdated = true;
268-
269-
mDrawing = false;
288+
updateItem();
270289
}
271290

272291
void QgsComposerMap::paint( QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *pWidget )
@@ -1031,8 +1050,10 @@ void QgsComposerMap::updateItem()
10311050

10321051
if ( mPreviewMode != QgsComposerMap::Rectangle && !mCacheUpdated )
10331052
{
1053+
QgsDebugMsg( "Requesting new cache image item" );
10341054
cache();
10351055
}
1056+
QgsDebugMsg( "Updating item" );
10361057
QgsComposerItem::updateItem();
10371058
}
10381059

src/core/composer/qgscomposermap.h

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class QgsFillSymbol;
4343
class QgsLineSymbol;
4444
class QgsVectorLayer;
4545
class QgsAnnotation;
46+
class QgsMapRendererCustomPainterJob;
4647

4748
/** \ingroup core
4849
* \class QgsComposerMap
@@ -491,6 +492,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
491492
private slots:
492493
void layersAboutToBeRemoved( QList<QgsMapLayer *> layers );
493494

495+
void painterJobFinished();
496+
494497
private:
495498

496499
//! Unique identifier
@@ -587,6 +590,10 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
587590
//! Margin size for atlas driven extents (percentage of feature size) - when in auto scaling mode
588591
double mAtlasMargin = 0.10;
589592

593+
QPainter *mPainter = nullptr;
594+
QgsMapRendererCustomPainterJob *mPainterJob = nullptr;
595+
bool mPainterCancelWait = false;
596+
590597
void init();
591598

592599
//! Resets the item tooltip to reflect current map id

0 commit comments

Comments
 (0)