@@ -9320,16 +9320,14 @@ void QgisApp::removeLayer()
9320
9320
}
9321
9321
}
9322
9322
9323
+ // extra check for required layers
9324
+ // In theory it should not be needed because the remove action should be disabled
9325
+ // if there are required layers in the selection...
9323
9326
const QSet<QgsMapLayer *> requiredLayers = QgsProject::instance()->requiredLayers();
9324
9327
for ( QgsMapLayer *layer : selectedLayers )
9325
9328
{
9326
9329
if ( requiredLayers.contains( layer ) )
9327
- {
9328
- QMessageBox::warning( this, tr( "Required layers" ),
9329
- tr( "The layer '%1' is marked as a required and therefore it cannot be removed from the project.\n\n"
9330
- "If you really need to remove the layer, unmark it as required in the Project Properties window > Data Sources tab." ).arg( layer->name() ) );
9331
9330
return;
9332
- }
9333
9331
}
9334
9332
9335
9333
if ( !activeTaskDescriptions.isEmpty() )
@@ -11587,7 +11585,7 @@ void QgisApp::selectionChanged( QgsMapLayer *layer )
11587
11585
11588
11586
void QgisApp::legendLayerSelectionChanged()
11589
11587
{
11590
- QList<QgsLayerTreeLayer *> selectedLayers = mLayerTreeView ? mLayerTreeView->selectedLayerNodes() : QList<QgsLayerTreeLayer *>();
11588
+ const QList<QgsLayerTreeLayer *> selectedLayers = mLayerTreeView ? mLayerTreeView->selectedLayerNodes() : QList<QgsLayerTreeLayer *>();
11591
11589
11592
11590
mActionDuplicateLayer->setEnabled( !selectedLayers.isEmpty() );
11593
11591
mActionSetLayerScaleVisibility->setEnabled( !selectedLayers.isEmpty() );
@@ -11613,6 +11611,19 @@ void QgisApp::legendLayerSelectionChanged()
11613
11611
mLegendExpressionFilterButton->setChecked( exprEnabled );
11614
11612
}
11615
11613
}
11614
+
11615
+ // remove action - check for required layers
11616
+ bool removeEnabled = true;
11617
+ const QSet<QgsMapLayer *> requiredLayers = QgsProject::instance()->requiredLayers();
11618
+ for ( QgsLayerTreeLayer *nodeLayer : selectedLayers )
11619
+ {
11620
+ if ( requiredLayers.contains( nodeLayer->layer() ) )
11621
+ {
11622
+ removeEnabled = false;
11623
+ break;
11624
+ }
11625
+ }
11626
+ mActionRemoveLayer->setEnabled( removeEnabled );
11616
11627
}
11617
11628
11618
11629
void QgisApp::layerEditStateChanged()
0 commit comments