Skip to content

Commit

Permalink
Avoid hang on WMS legends with missing graphics (fix #12234)
Browse files Browse the repository at this point in the history
Cherry-picked from 4f29c58
  • Loading branch information
nyalldawson committed Jul 9, 2015
1 parent 3387392 commit 56613cc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/providers/wms/qgswmsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3041,6 +3041,7 @@ QImage QgsWmsProvider::getLegendGraphic( double scale, bool forceRefresh, const
mLegendGraphicFetcher.reset( new QgsWmsLegendDownloadHandler( *QgsNetworkAccessManager::instance(), mSettings, url ) );
if ( ! mLegendGraphicFetcher ) return QImage();
connect( mLegendGraphicFetcher.data(), SIGNAL( finish( const QImage& ) ), this, SLOT( getLegendGraphicReplyFinished( const QImage& ) ) );
connect( mLegendGraphicFetcher.data(), SIGNAL( error( const QString& ) ), this, SLOT( getLegendGraphicReplyErrored( const QString& ) ) );
connect( mLegendGraphicFetcher.data(), SIGNAL( progress( qint64, qint64 ) ), this, SLOT( getLegendGraphicReplyProgress( qint64, qint64 ) ) );
mLegendGraphicFetcher->start( );

Expand Down Expand Up @@ -3119,6 +3120,22 @@ void QgsWmsProvider::getLegendGraphicReplyFinished( const QImage& img )
}
}

void QgsWmsProvider::getLegendGraphicReplyErrored( const QString& message )
{
Q_UNUSED( message );
QgsDebugMsg( QString( "get legend failed: %1" ).arg( message ) );

QObject* reply = sender();

if ( reply == mLegendGraphicFetcher.data() )
{
QEventLoop *loop = qobject_cast< QEventLoop *>( reply->property( "eventLoop" ).value< QObject *>() );
if ( loop )
QMetaObject::invokeMethod( loop, "quit", Qt::QueuedConnection );
mLegendGraphicFetcher.reset();
}
}

void QgsWmsProvider::getLegendGraphicReplyProgress( qint64 bytesReceived, qint64 bytesTotal )
{
QString msg = tr( "%1 of %2 bytes of GetLegendGraphic downloaded." ).arg( bytesReceived ).arg( bytesTotal < 0 ? QString( "unknown number of" ) : QString::number( bytesTotal ) );
Expand Down
1 change: 1 addition & 0 deletions src/providers/wms/qgswmsprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ class QgsWmsProvider : public QgsRasterDataProvider
private slots:
void identifyReplyFinished();
void getLegendGraphicReplyFinished( const QImage& );
void getLegendGraphicReplyErrored( const QString& message );
void getLegendGraphicReplyProgress( qint64, qint64 );

private:
Expand Down

0 comments on commit 56613cc

Please sign in to comment.