[gui] Do not add the "Save As…" action for unsupported layer types

as suggested during the PR review
This commit is contained in:
Andrea Giudiceandrea 2025-08-07 00:32:19 +02:00 committed by Nyall Dawson
parent 6fc3ba3433
commit 9cb72d02ae

View File

@ -670,13 +670,11 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
{
QMenu *menuExportRaster = new QMenu( tr( "E&xport" ), menu );
menuExportRaster->setObjectName( QStringLiteral( "exportMenu" ) );
if ( mView->selectedLayerNodes().count() == 1 )
if ( mView->selectedLayerNodes().count() == 1 && ( ( pcLayer && pcLayer->isValid() && pcLayer->dataProvider()->hasValidIndex() ) || ( rlayer && rlayer->isValid() ) ) )
{
QAction *actionSaveAs = new QAction( tr( "Save &As…" ), menuExportRaster );
connect( actionSaveAs, &QAction::triggered, QgisApp::instance(), [] { QgisApp::instance()->saveAsFile(); } );
menuExportRaster->addAction( actionSaveAs );
const bool enableSaveAs = ( pcLayer && pcLayer->isValid() && pcLayer->dataProvider()->hasValidIndex() ) || ( rlayer && rlayer->isValid() );
actionSaveAs->setEnabled( enableSaveAs );
}
QAction *actionSaveAsDefinitionLayer = new QAction( tr( "Save as Layer &Definition File…" ), menuExportRaster );
QAction *actionSaveStyle = new QAction( tr( "Save as &QGIS Layer Style File…" ), menuExportRaster );