Skip to content
Permalink
Browse files
WMS: don't crash on invalid layers
Fixes #43580
  • Loading branch information
elpaso committed Jun 7, 2021
1 parent cc0d9b1 commit cbcf762199e35a29e3b238e8d7479672442a0b3a
Showing with 24 additions and 16 deletions.
  1. +24 −16 src/core/layertree/qgslayertreemodellegendnode.cpp
@@ -1184,23 +1184,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 cbcf762

Please sign in to comment.