Skip to content

Commit 6a61179

Browse files
committed
Disable a bunch of actions which don't apply to vector layers
without geometry (fix #15933)
1 parent e927447 commit 6a61179

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

src/app/qgisapp.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10600,6 +10600,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
1060010600
bool isEditable = vlayer->isEditable();
1060110601
bool layerHasSelection = vlayer->selectedFeatureCount() > 0;
1060210602
bool layerHasActions = !vlayer->actions()->actions( QStringLiteral( "Canvas" ) ).isEmpty() || !QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer ).isEmpty();
10603+
bool isSpatial = vlayer->isSpatial();
1060310604

1060410605
mActionLocalHistogramStretch->setEnabled( false );
1060510606
mActionFullHistogramStretch->setEnabled( false );
@@ -10610,14 +10611,16 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
1061010611
mActionIncreaseContrast->setEnabled( false );
1061110612
mActionDecreaseContrast->setEnabled( false );
1061210613
mActionZoomActualSize->setEnabled( false );
10613-
mActionLabeling->setEnabled( true );
10614-
mActionDiagramProperties->setEnabled( true );
10615-
10616-
mActionSelectFeatures->setEnabled( true );
10617-
mActionSelectPolygon->setEnabled( true );
10618-
mActionSelectFreehand->setEnabled( true );
10619-
mActionSelectRadius->setEnabled( true );
10620-
mActionIdentify->setEnabled( true );
10614+
mActionZoomToLayer->setEnabled( isSpatial );
10615+
mActionZoomToSelected->setEnabled( isSpatial );
10616+
mActionLabeling->setEnabled( isSpatial );
10617+
mActionDiagramProperties->setEnabled( isSpatial );
10618+
10619+
mActionSelectFeatures->setEnabled( isSpatial );
10620+
mActionSelectPolygon->setEnabled( isSpatial );
10621+
mActionSelectFreehand->setEnabled( isSpatial );
10622+
mActionSelectRadius->setEnabled( isSpatial );
10623+
mActionIdentify->setEnabled( isSpatial );
1062110624
mActionSelectByExpression->setEnabled( true );
1062210625
mActionSelectByForm->setEnabled( true );
1062310626
mActionOpenTable->setEnabled( true );
@@ -10640,7 +10643,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
1064010643
bool canDeleteFeatures = dprovider->capabilities() & QgsVectorDataProvider::DeleteFeatures;
1064110644
bool canAddFeatures = dprovider->capabilities() & QgsVectorDataProvider::AddFeatures;
1064210645
bool canSupportEditing = dprovider->capabilities() & QgsVectorDataProvider::EditingCapabilities;
10643-
bool canChangeGeometry = dprovider->capabilities() & QgsVectorDataProvider::ChangeGeometries;
10646+
bool canChangeGeometry = isSpatial && dprovider->capabilities() & QgsVectorDataProvider::ChangeGeometries;
1064410647

1064510648
mActionLayerSubsetString->setEnabled( !isEditable && dprovider->supportsSubsetString() );
1064610649

@@ -10660,8 +10663,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
1066010663
mActionPasteFeatures->setEnabled( isEditable && canAddFeatures && !clipboard()->isEmpty() );
1066110664

1066210665
mActionAddFeature->setEnabled( isEditable && canAddFeatures );
10663-
mActionCircularStringCurvePoint->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry ) && vlayer->geometryType() != QgsWkbTypes::PointGeometry );
10664-
mActionCircularStringRadius->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry ) );
10666+
mActionCircularStringCurvePoint->setEnabled( isEditable && isSpatial && ( canAddFeatures || canChangeGeometry ) && vlayer->geometryType() != QgsWkbTypes::PointGeometry );
10667+
mActionCircularStringRadius->setEnabled( isEditable && isSpatial && ( canAddFeatures || canChangeGeometry ) );
1066510668

1066610669
//does provider allow deleting of features?
1066710670
mActionDeleteSelected->setEnabled( isEditable && canDeleteFeatures && layerHasSelection );
@@ -10757,6 +10760,14 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
1075710760
else if ( vlayer->geometryType() == QgsWkbTypes::NullGeometry )
1075810761
{
1075910762
mActionAddFeature->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "/mActionNewTableRow.svg" ) ) );
10763+
mActionAddRing->setEnabled( false );
10764+
mActionFillRing->setEnabled( false );
10765+
mActionReshapeFeatures->setEnabled( false );
10766+
mActionSplitFeatures->setEnabled( false );
10767+
mActionSplitParts->setEnabled( false );
10768+
mActionSimplifyFeature->setEnabled( false );
10769+
mActionDeleteRing->setEnabled( false );
10770+
mActionOffsetCurve->setEnabled( false );
1076010771
}
1076110772

1076210773
mActionOpenFieldCalc->setEnabled( true );
@@ -10807,6 +10818,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
1080710818
mActionSelectFreehand->setEnabled( false );
1080810819
mActionSelectRadius->setEnabled( false );
1080910820
mActionZoomActualSize->setEnabled( true );
10821+
mActionZoomToLayer->setEnabled( true );
10822+
mActionZoomToSelected->setEnabled( false );
1081010823
mActionOpenTable->setEnabled( false );
1081110824
mActionSelectAll->setEnabled( false );
1081210825
mActionInvertSelection->setEnabled( false );

src/app/qgsapplayertreeviewmenuprovider.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
9999
QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( layer );
100100
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
101101

102-
menu->addAction( actions->actionZoomToLayer( mCanvas, menu ) );
103-
menu->addAction( actions->actionShowInOverview( menu ) );
102+
if ( layer && layer->isSpatial() )
103+
{
104+
menu->addAction( actions->actionZoomToLayer( mCanvas, menu ) );
105+
menu->addAction( actions->actionShowInOverview( menu ) );
106+
}
104107

105108
if ( rlayer )
106109
{

0 commit comments

Comments
 (0)