@@ -140,18 +140,24 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
140
140
141
141
if ( layer && layer->isSpatial () )
142
142
{
143
- menu->addAction ( actions->actionZoomToLayer ( mCanvas , menu ) );
143
+ QAction *zoomToLayer = actions->actionZoomToLayer ( mCanvas , menu );
144
+ zoomToLayer->setEnabled ( layer->isValid () );
145
+ menu->addAction ( zoomToLayer );
144
146
if ( vlayer )
145
147
{
146
148
QAction *actionZoomSelected = actions->actionZoomToSelection ( mCanvas , menu );
147
- actionZoomSelected->setEnabled ( !vlayer->selectedFeatureIds ().isEmpty () );
149
+ actionZoomSelected->setEnabled ( vlayer-> isValid () && !vlayer->selectedFeatureIds ().isEmpty () );
148
150
menu->addAction ( actionZoomSelected );
149
151
}
150
152
menu->addAction ( actions->actionShowInOverview ( menu ) );
151
153
}
152
154
153
155
if ( vlayer )
154
- menu->addAction ( actions->actionShowFeatureCount ( menu ) );
156
+ {
157
+ QAction *showFeatureCount = actions->actionShowFeatureCount ( menu );
158
+ menu->addAction ( showFeatureCount );
159
+ showFeatureCount->setEnabled ( vlayer->isValid () );
160
+ }
155
161
156
162
QAction *actionCopyLayer = new QAction ( tr ( " Copy Layer" ), menu );
157
163
connect ( actionCopyLayer, &QAction::triggered, QgisApp::instance (), &QgisApp::copyLayer );
@@ -161,10 +167,14 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
161
167
162
168
if ( rlayer )
163
169
{
164
- menu->addAction ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionZoomActual.svg" ) ), tr ( " &Zoom to Native Resolution (100%)" ), QgisApp::instance (), &QgisApp::legendLayerZoomNative );
170
+ QAction *zoomToNative = menu->addAction ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionZoomActual.svg" ) ), tr ( " &Zoom to Native Resolution (100%)" ), QgisApp::instance (), &QgisApp::legendLayerZoomNative );
171
+ zoomToNative->setEnabled ( rlayer->isValid () );
165
172
166
173
if ( rlayer->rasterType () != QgsRasterLayer::Palette )
167
- menu->addAction ( tr ( " &Stretch Using Current Extent" ), QgisApp::instance (), &QgisApp::legendLayerStretchUsingCurrentExtent );
174
+ {
175
+ QAction *stretch = menu->addAction ( tr ( " &Stretch Using Current Extent" ), QgisApp::instance (), &QgisApp::legendLayerStretchUsingCurrentExtent );
176
+ stretch->setEnabled ( rlayer->isValid () );
177
+ }
168
178
}
169
179
170
180
addCustomLayerActions ( menu, layer );
@@ -208,8 +218,9 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
208
218
// attribute table
209
219
QgsSettings settings;
210
220
QgsAttributeTableFilterModel::FilterMode initialMode = settings.enumValue ( QStringLiteral ( " qgis/attributeTableBehavior" ), QgsAttributeTableFilterModel::ShowAll );
211
- menu->addAction ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionOpenTable.svg" ) ), tr ( " &Open Attribute Table" ),
212
- QgisApp::instance (), [ = ] { QgisApp::instance ()->attributeTable ( initialMode ); } );
221
+ QAction *attributeTable = menu->addAction ( QgsApplication::getThemeIcon ( QStringLiteral ( " /mActionOpenTable.svg" ) ), tr ( " &Open Attribute Table" ),
222
+ QgisApp::instance (), [ = ] { QgisApp::instance ()->attributeTable ( initialMode ); } );
223
+ attributeTable->setEnabled ( vlayer->isValid () );
213
224
214
225
// allow editing
215
226
unsigned int cap = vlayer->dataProvider ()->capabilities ();
@@ -219,7 +230,7 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
219
230
{
220
231
menu->addAction ( toggleEditingAction );
221
232
toggleEditingAction->setChecked ( vlayer->isEditable () );
222
- toggleEditingAction->setEnabled ( true );
233
+ toggleEditingAction->setEnabled ( vlayer-> isValid () );
223
234
}
224
235
if ( saveLayerEditsAction && vlayer->isModified () )
225
236
{
@@ -298,10 +309,11 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
298
309
QMenu *menuExportVector = new QMenu ( tr ( " Export" ), menu );
299
310
QAction *actionSaveAs = new QAction ( tr ( " Save Features As…" ), menuExportVector );
300
311
connect ( actionSaveAs, &QAction::triggered, QgisApp::instance (), [ = ] { QgisApp::instance ()->saveAsFile (); } );
312
+ actionSaveAs->setEnabled ( vlayer->isValid () );
301
313
menuExportVector->addAction ( actionSaveAs );
302
314
QAction *actionSaveSelectedFeaturesAs = new QAction ( tr ( " Save Selected Features As…" ), menuExportVector );
303
315
connect ( actionSaveSelectedFeaturesAs, &QAction::triggered, QgisApp::instance (), [ = ] { QgisApp::instance ()->saveAsFile ( nullptr , true ); } );
304
- actionSaveSelectedFeaturesAs->setEnabled ( vlayer->selectedFeatureCount () > 0 );
316
+ actionSaveSelectedFeaturesAs->setEnabled ( vlayer->isValid () && vlayer-> selectedFeatureCount () > 0 );
305
317
menuExportVector->addAction ( actionSaveSelectedFeaturesAs );
306
318
QAction *actionSaveAsDefinitionLayer = new QAction ( tr ( " Save as Layer Definition File…" ), menuExportVector );
307
319
connect ( actionSaveAsDefinitionLayer, &QAction::triggered, QgisApp::instance (), &QgisApp::saveAsLayerDefinition );
@@ -322,6 +334,7 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
322
334
QAction *actionSaveStyle = new QAction ( tr ( " Save as QGIS Layer Style File…" ), menuExportRaster );
323
335
connect ( actionSaveAs, &QAction::triggered, QgisApp::instance (), [ = ] { QgisApp::instance ()->saveAsFile (); } );
324
336
menuExportRaster->addAction ( actionSaveAs );
337
+ actionSaveAs->setEnabled ( rlayer->isValid () );
325
338
connect ( actionSaveAsDefinitionLayer, &QAction::triggered, QgisApp::instance (), &QgisApp::saveAsLayerDefinition );
326
339
menuExportRaster->addAction ( actionSaveAsDefinitionLayer );
327
340
connect ( actionSaveStyle, &QAction::triggered, QgisApp::instance (), [ = ] { QgisApp::instance ()->saveStyleFile (); } );
0 commit comments