Skip to content

Commit

Permalink
Make sure we do not miss cancellation request at the beginning
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Sep 1, 2016
1 parent fdeac81 commit 8d832d8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -3337,7 +3337,18 @@ QgsWmsImageDownloadHandler::QgsWmsImageDownloadHandler( const QString& providerU
: mProviderUri( providerUri )
, mCachedImage( image )
, mEventLoop( new QEventLoop )
, mFeedback( feedback )
{
if ( feedback )
{
connect( feedback, SIGNAL( cancelled() ), this, SLOT( cancelled() ), Qt::QueuedConnection );

// rendering could have been cancelled before we started to listen to cancelled() signal
// so let's check before doing the download and maybe quit prematurely
if ( feedback->isCancelled() )
return;
}

QNetworkRequest request( url );
auth.setAuthorization( request );
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
Expand All @@ -3346,9 +3357,6 @@ QgsWmsImageDownloadHandler::QgsWmsImageDownloadHandler( const QString& providerU
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ) );

Q_ASSERT( mCacheReply->thread() == QThread::currentThread() );

if ( feedback )
connect( feedback, SIGNAL( cancelled() ), this, SLOT( cancelled() ), Qt::QueuedConnection );
}

QgsWmsImageDownloadHandler::~QgsWmsImageDownloadHandler()
Expand All @@ -3358,6 +3366,9 @@ QgsWmsImageDownloadHandler::~QgsWmsImageDownloadHandler()

void QgsWmsImageDownloadHandler::downloadBlocking()
{
if ( mFeedback && mFeedback->isCancelled() )
return; // nothing to do

mEventLoop->exec( QEventLoop::ExcludeUserInputEvents );

Q_ASSERT( !mCacheReply );
Expand Down Expand Up @@ -3497,6 +3508,16 @@ QgsWmsTiledImageDownloadHandler::QgsWmsTiledImageDownloadHandler( const QString&
, mSmoothPixmapTransform( smoothPixmapTransform )
, mFeedback( feedback )
{
if ( feedback )
{
connect( feedback, SIGNAL( cancelled() ), this, SLOT( cancelled() ), Qt::QueuedConnection );

// rendering could have been cancelled before we started to listen to cancelled() signal
// so let's check before doing the download and maybe quit prematurely
if ( feedback->isCancelled() )
return;
}

Q_FOREACH ( const TileRequest& r, requests )
{
QNetworkRequest request( r.url );
Expand All @@ -3513,9 +3534,6 @@ QgsWmsTiledImageDownloadHandler::QgsWmsTiledImageDownloadHandler( const QString&

mReplies << reply;
}

if ( feedback )
connect( feedback, SIGNAL( cancelled() ), this, SLOT( cancelled() ), Qt::QueuedConnection );
}

QgsWmsTiledImageDownloadHandler::~QgsWmsTiledImageDownloadHandler()
Expand All @@ -3525,6 +3543,9 @@ QgsWmsTiledImageDownloadHandler::~QgsWmsTiledImageDownloadHandler()

void QgsWmsTiledImageDownloadHandler::downloadBlocking()
{
if ( mFeedback && mFeedback->isCancelled() )
return; // nothing to do

mEventLoop->exec( QEventLoop::ExcludeUserInputEvents );

Q_ASSERT( mReplies.isEmpty() );
Expand Down
2 changes: 2 additions & 0 deletions src/providers/wms/qgswmsprovider.h
Expand Up @@ -571,6 +571,8 @@ class QgsWmsImageDownloadHandler : public QObject
QImage* mCachedImage;

QEventLoop* mEventLoop;

QgsRasterBlockFeedback* mFeedback;
};


Expand Down

0 comments on commit 8d832d8

Please sign in to comment.