Skip to content
Permalink
Browse files
WMS: don't crash on invalid layers
Fixes #43580
  • Loading branch information
elpaso authored and nyalldawson committed Jun 8, 2021
1 parent acdcfc3 commit 08e7b27ddc940c0923619a7aeb97c52db6b242e4
Showing with 24 additions and 16 deletions.
  1. +24 −16 src/core/layertree/qgslayertreemodellegendnode.cpp
@@ -1071,23 +1071,31 @@ QImage QgsWmsLegendNode::getLegendGraphic() const
// and start a new one ?

QgsRasterLayer *layer = qobject_cast<QgsRasterLayer *>( mLayerNode->layer() );
const QgsLayerTreeModel *mod = model();
if ( ! mod )
return mImage;
const QgsMapSettings *ms = mod->legendFilterMapSettings();

QgsRasterDataProvider *prov = layer->dataProvider();
if ( ! prov )
return mImage;

Q_ASSERT( ! mFetcher );
mFetcher.reset( prov->getLegendGraphicFetcher( ms ) );
if ( mFetcher )

if ( layer && layer->isValid() )
{
const QgsLayerTreeModel *mod = model();
if ( ! mod )
return mImage;
const QgsMapSettings *ms = mod->legendFilterMapSettings();

QgsRasterDataProvider *prov = layer->dataProvider();
if ( ! prov )
return mImage;

Q_ASSERT( ! mFetcher );
mFetcher.reset( prov->getLegendGraphicFetcher( ms ) );
if ( mFetcher )
{
connect( mFetcher.get(), &QgsImageFetcher::finish, this, &QgsWmsLegendNode::getLegendGraphicFinished );
connect( mFetcher.get(), &QgsImageFetcher::error, this, &QgsWmsLegendNode::getLegendGraphicErrored );
connect( mFetcher.get(), &QgsImageFetcher::progress, this, &QgsWmsLegendNode::getLegendGraphicProgress );
mFetcher->start();
}
}
else
{
connect( mFetcher.get(), &QgsImageFetcher::finish, this, &QgsWmsLegendNode::getLegendGraphicFinished );
connect( mFetcher.get(), &QgsImageFetcher::error, this, &QgsWmsLegendNode::getLegendGraphicErrored );
connect( mFetcher.get(), &QgsImageFetcher::progress, this, &QgsWmsLegendNode::getLegendGraphicProgress );
mFetcher->start();
QgsDebugMsg( tr( "Failed to download legend graphics: layer is not valid." ) );
}
}

0 comments on commit 08e7b27

Please sign in to comment.