Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 4bc561c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/app/qgsapplayertreeviewmenuprovider.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsmaplayerstyleguiutils.cpp
Expand Up @@ -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 ) );
Expand Down
21 changes: 12 additions & 9 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -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() );
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgssnappingwidget.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 4bc561c

Please sign in to comment.