mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
[bugfix] Crash when exporting (invalid) legend to qlr
Fixes #18981 Save QLR crashes QGIS 3 This patch definitely prevents the crash but I'm not sure if we should also introduce the same check in QgsLayerTree::isLayer or even in QgsLayerTreeGroup::findLayers() or also when importing a qlr that might lead to invalid layer (like in this bug report).
This commit is contained in:
parent
8ef0d1f7d9
commit
ec909b0aab
@ -214,6 +214,11 @@ bool QgsLayerDefinition::exportLayerDefinition( QDomDocument doc, const QList<Qg
|
|||||||
QList<QgsLayerTreeLayer *> layers = root->findLayers();
|
QList<QgsLayerTreeLayer *> layers = root->findLayers();
|
||||||
Q_FOREACH ( QgsLayerTreeLayer *layer, layers )
|
Q_FOREACH ( QgsLayerTreeLayer *layer, layers )
|
||||||
{
|
{
|
||||||
|
if ( ! layer->layer() )
|
||||||
|
{
|
||||||
|
QgsDebugMsgLevel( QStringLiteral( "Not a valid map layer: skipping %1" ).arg( layer->name( ) ), 4 );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
QDomElement layerelm = doc.createElement( QStringLiteral( "maplayer" ) );
|
QDomElement layerelm = doc.createElement( QStringLiteral( "maplayer" ) );
|
||||||
layer->layer()->writeLayerXml( layerelm, doc, context );
|
layer->layer()->writeLayerXml( layerelm, doc, context );
|
||||||
layerselm.appendChild( layerelm );
|
layerselm.appendChild( layerelm );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user