Skip to content

Commit 4bc561c

Browse files
committed
Fix crashes when right clicking a layer with a broken source,
e.g. a layer loaded from a qlyr with missing layer reference
1 parent d1e2978 commit 4bc561c

4 files changed

+20
-12
lines changed

src/app/qgsapplayertreeviewmenuprovider.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
353353
menuStyleManager->addAction( tr( "Copy Style" ), app, SLOT( copyStyle() ) );
354354
}
355355

356-
if ( app->clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) )
356+
if ( layer && app->clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) )
357357
{
358358
if ( layer->type() == QgsMapLayer::VectorLayer )
359359
{
@@ -802,7 +802,9 @@ bool QgsAppLayerTreeViewMenuProvider::removeActionEnabled()
802802
const QList<QgsLayerTreeLayer *> selectedLayers = mView->selectedLayerNodes();
803803
for ( QgsLayerTreeLayer *nodeLayer : selectedLayers )
804804
{
805-
if ( !nodeLayer->layer()->flags().testFlag( QgsMapLayer::Removable ) )
805+
// be careful with the logic here -- if nodeLayer->layer() is false, will still must return true
806+
// to allow the broken layer to be removed from the project
807+
if ( nodeLayer->layer() && !nodeLayer->layer()->flags().testFlag( QgsMapLayer::Removable ) )
806808
return false;
807809
}
808810
return true;

src/app/qgsmaplayerstyleguiutils.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ QList<QAction *> QgsMapLayerStyleGuiUtils::actionsUseStyle( QgsMapLayer *layer,
7979

8080
void QgsMapLayerStyleGuiUtils::addStyleManagerActions( QMenu *m, QgsMapLayer *layer )
8181
{
82+
if ( ! layer )
83+
return;
84+
8285
m->addAction( actionAddStyle( layer, m ) );
8386
if ( layer->styleManager()->styles().count() > 1 )
8487
m->addAction( actionRemoveStyle( layer, m ) );

src/app/qgsprojectproperties.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -2084,16 +2084,19 @@ void QgsProjectProperties::checkOWS( QgsLayerTreeGroup *treeGroup, QStringList &
20842084
{
20852085
QgsLayerTreeLayer *treeLayer = static_cast<QgsLayerTreeLayer *>( treeNode );
20862086
QgsMapLayer *l = treeLayer->layer();
2087-
QString shortName = l->shortName();
2088-
if ( shortName.isEmpty() )
2089-
owsNames << l->name();
2090-
else
2091-
owsNames << shortName;
2092-
if ( l->type() == QgsMapLayer::VectorLayer )
2087+
if ( l )
20932088
{
2094-
QgsVectorLayer *vl = static_cast<QgsVectorLayer *>( l );
2095-
if ( vl->dataProvider()->encoding() == QLatin1String( "System" ) )
2096-
encodingMessages << tr( "Update layer \"%1\" encoding" ).arg( l->name() );
2089+
QString shortName = l->shortName();
2090+
if ( shortName.isEmpty() )
2091+
owsNames << l->name();
2092+
else
2093+
owsNames << shortName;
2094+
if ( l->type() == QgsMapLayer::VectorLayer )
2095+
{
2096+
QgsVectorLayer *vl = static_cast<QgsVectorLayer *>( l );
2097+
if ( vl->dataProvider()->encoding() == QLatin1String( "System" ) )
2098+
encodingMessages << tr( "Update layer \"%1\" encoding" ).arg( l->name() );
2099+
}
20972100
}
20982101
}
20992102
}

src/app/qgssnappingwidget.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ void QgsSnappingWidget::cleanGroup( QgsLayerTreeNode *node )
548548
QList<QgsLayerTreeNode *> toRemove;
549549
Q_FOREACH ( QgsLayerTreeNode *child, node->children() )
550550
{
551-
if ( QgsLayerTree::isLayer( child ) && QgsLayerTree::toLayer( child )->layer()->type() != QgsMapLayer::VectorLayer )
551+
if ( QgsLayerTree::isLayer( child ) && ( !QgsLayerTree::toLayer( child )->layer() || QgsLayerTree::toLayer( child )->layer()->type() != QgsMapLayer::VectorLayer ) )
552552
{
553553
toRemove << child;
554554
continue;

0 commit comments

Comments
 (0)