Skip to content
Permalink
Browse files
Asyncronously render composer map previews
(Forward port from Sourcepole fork)
  • Loading branch information
manisandro authored and nyalldawson committed May 6, 2017
1 parent 8d03642 commit 855e1f6986c0395587fe7828fc78a586972067eb
Showing with 36 additions and 8 deletions.
  1. +29 −8 src/core/composer/qgscomposermap.cpp
  2. +7 −0 src/core/composer/qgscomposermap.h
@@ -206,12 +206,20 @@ void QgsComposerMap::cache()
return;
}

if ( mDrawing )
if ( mPainterJob )
{
return;
if ( mPainterCancelWait )
{
return; // Already waiting
}
QgsDebugMsg( "Aborting composer painter job" );
mPainterCancelWait = true;
mPainterJob->cancel();
mPainterCancelWait = false;
}

mDrawing = true;
Q_ASSERT( !mPainterJob );
Q_ASSERT( !mPainter );

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

QPainter p( &mCacheImage );
mPainter = new QPainter( &mCacheImage );
QgsMapSettings settings( mapSettings( ext, QSizeF( w, h ), mCacheImage.logicalDpiX() ) );
mPainterJob = new QgsMapRendererCustomPainterJob( settings, mPainter );
connect( mPainterJob, SIGNAL( finished() ), this, SLOT( painterJobFinished() ) );
QgsDebugMsg( "Starting new composer painter job" );
mPainterJob->start();
}

draw( &p, ext, QSizeF( w, h ), mCacheImage.logicalDpiX() );
p.end();
void QgsComposerMap::painterJobFinished()
{
QgsDebugMsg( "Finished composer painter job" );
mPainter->end();
delete mPainterJob;
mPainterJob = nullptr;
delete mPainter;
mPainter = nullptr;
mCacheUpdated = true;

mDrawing = false;
updateItem();
}

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

if ( mPreviewMode != QgsComposerMap::Rectangle && !mCacheUpdated )
{
QgsDebugMsg( "Requesting new cache image item" );
cache();
}
QgsDebugMsg( "Updating item" );
QgsComposerItem::updateItem();
}

@@ -43,6 +43,7 @@ class QgsFillSymbol;
class QgsLineSymbol;
class QgsVectorLayer;
class QgsAnnotation;
class QgsMapRendererCustomPainterJob;

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

void painterJobFinished();

private:

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

QPainter *mPainter = nullptr;
QgsMapRendererCustomPainterJob *mPainterJob = nullptr;
bool mPainterCancelWait = false;

void init();

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

0 comments on commit 855e1f6

Please sign in to comment.