Skip to content
Permalink
Browse files

Fix crashes when right clicking a layer with a broken source,

e.g. a layer loaded from a qlyr with missing layer reference
  • Loading branch information
nyalldawson committed Oct 26, 2018
1 parent d1e2978 commit 4bc561cc5cb46e278999cf0ac990db8f1167299e
@@ -353,7 +353,7 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
menuStyleManager->addAction( tr( "Copy Style" ), app, SLOT( copyStyle() ) );
}

if ( app->clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) )
if ( layer && app->clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) )
{
if ( layer->type() == QgsMapLayer::VectorLayer )
{
@@ -802,7 +802,9 @@ bool QgsAppLayerTreeViewMenuProvider::removeActionEnabled()
const QList<QgsLayerTreeLayer *> selectedLayers = mView->selectedLayerNodes();
for ( QgsLayerTreeLayer *nodeLayer : selectedLayers )
{
if ( !nodeLayer->layer()->flags().testFlag( QgsMapLayer::Removable ) )
// be careful with the logic here -- if nodeLayer->layer() is false, will still must return true
// to allow the broken layer to be removed from the project
if ( nodeLayer->layer() && !nodeLayer->layer()->flags().testFlag( QgsMapLayer::Removable ) )
return false;
}
return true;
@@ -79,6 +79,9 @@ QList<QAction *> QgsMapLayerStyleGuiUtils::actionsUseStyle( QgsMapLayer *layer,

void QgsMapLayerStyleGuiUtils::addStyleManagerActions( QMenu *m, QgsMapLayer *layer )
{
if ( ! layer )
return;

m->addAction( actionAddStyle( layer, m ) );
if ( layer->styleManager()->styles().count() > 1 )
m->addAction( actionRemoveStyle( layer, m ) );
@@ -2084,16 +2084,19 @@ void QgsProjectProperties::checkOWS( QgsLayerTreeGroup *treeGroup, QStringList &
{
QgsLayerTreeLayer *treeLayer = static_cast<QgsLayerTreeLayer *>( treeNode );
QgsMapLayer *l = treeLayer->layer();
QString shortName = l->shortName();
if ( shortName.isEmpty() )
owsNames << l->name();
else
owsNames << shortName;
if ( l->type() == QgsMapLayer::VectorLayer )
if ( l )
{
QgsVectorLayer *vl = static_cast<QgsVectorLayer *>( l );
if ( vl->dataProvider()->encoding() == QLatin1String( "System" ) )
encodingMessages << tr( "Update layer \"%1\" encoding" ).arg( l->name() );
QString shortName = l->shortName();
if ( shortName.isEmpty() )
owsNames << l->name();
else
owsNames << shortName;
if ( l->type() == QgsMapLayer::VectorLayer )
{
QgsVectorLayer *vl = static_cast<QgsVectorLayer *>( l );
if ( vl->dataProvider()->encoding() == QLatin1String( "System" ) )
encodingMessages << tr( "Update layer \"%1\" encoding" ).arg( l->name() );
}
}
}
}
@@ -548,7 +548,7 @@ void QgsSnappingWidget::cleanGroup( QgsLayerTreeNode *node )
QList<QgsLayerTreeNode *> toRemove;
Q_FOREACH ( QgsLayerTreeNode *child, node->children() )
{
if ( QgsLayerTree::isLayer( child ) && QgsLayerTree::toLayer( child )->layer()->type() != QgsMapLayer::VectorLayer )
if ( QgsLayerTree::isLayer( child ) && ( !QgsLayerTree::toLayer( child )->layer() || QgsLayerTree::toLayer( child )->layer()->type() != QgsMapLayer::VectorLayer ) )
{
toRemove << child;
continue;

0 comments on commit 4bc561c

Please sign in to comment.
You can’t perform that action at this time.