Skip to content

Commit 4f29c58

Browse files
committed
Avoid hang on WMS legends with missing graphics (fix #12234)
1 parent 390d832 commit 4f29c58

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/providers/wms/qgswmsprovider.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -3041,6 +3041,7 @@ QImage QgsWmsProvider::getLegendGraphic( double scale, bool forceRefresh, const
30413041
mLegendGraphicFetcher.reset( new QgsWmsLegendDownloadHandler( *QgsNetworkAccessManager::instance(), mSettings, url ) );
30423042
if ( ! mLegendGraphicFetcher ) return QImage();
30433043
connect( mLegendGraphicFetcher.data(), SIGNAL( finish( const QImage& ) ), this, SLOT( getLegendGraphicReplyFinished( const QImage& ) ) );
3044+
connect( mLegendGraphicFetcher.data(), SIGNAL( error( const QString& ) ), this, SLOT( getLegendGraphicReplyErrored( const QString& ) ) );
30443045
connect( mLegendGraphicFetcher.data(), SIGNAL( progress( qint64, qint64 ) ), this, SLOT( getLegendGraphicReplyProgress( qint64, qint64 ) ) );
30453046
mLegendGraphicFetcher->start( );
30463047

@@ -3119,6 +3120,21 @@ void QgsWmsProvider::getLegendGraphicReplyFinished( const QImage& img )
31193120
}
31203121
}
31213122

3123+
void QgsWmsProvider::getLegendGraphicReplyErrored( const QString& message )
3124+
{
3125+
QgsDebugMsg( QString( "get legend failed: %1" ).arg( message ) );
3126+
3127+
QObject* reply = sender();
3128+
3129+
if ( reply == mLegendGraphicFetcher.data() )
3130+
{
3131+
QEventLoop *loop = qobject_cast< QEventLoop *>( reply->property( "eventLoop" ).value< QObject *>() );
3132+
if ( loop )
3133+
QMetaObject::invokeMethod( loop, "quit", Qt::QueuedConnection );
3134+
mLegendGraphicFetcher.reset();
3135+
}
3136+
}
3137+
31223138
void QgsWmsProvider::getLegendGraphicReplyProgress( qint64 bytesReceived, qint64 bytesTotal )
31233139
{
31243140
QString msg = tr( "%1 of %2 bytes of GetLegendGraphic downloaded." ).arg( bytesReceived ).arg( bytesTotal < 0 ? QString( "unknown number of" ) : QString::number( bytesTotal ) );

src/providers/wms/qgswmsprovider.h

+1
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ class QgsWmsProvider : public QgsRasterDataProvider
367367
private slots:
368368
void identifyReplyFinished();
369369
void getLegendGraphicReplyFinished( const QImage& );
370+
void getLegendGraphicReplyErrored( const QString& message );
370371
void getLegendGraphicReplyProgress( qint64, qint64 );
371372

372373
private:

0 commit comments

Comments
 (0)