Skip to content
Permalink
Browse files
Disable a bunch of actions which don't apply to vector layers
without geometry (fix #15933)
  • Loading branch information
nyalldawson committed Dec 4, 2016
1 parent e927447 commit 6a61179451aafdfbce481c9131a7631865bd35d2
Showing with 29 additions and 13 deletions.
  1. +24 −11 src/app/qgisapp.cpp
  2. +5 −2 src/app/qgsapplayertreeviewmenuprovider.cpp
@@ -10600,6 +10600,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
bool isEditable = vlayer->isEditable();
bool layerHasSelection = vlayer->selectedFeatureCount() > 0;
bool layerHasActions = !vlayer->actions()->actions( QStringLiteral( "Canvas" ) ).isEmpty() || !QgsMapLayerActionRegistry::instance()->mapLayerActions( vlayer ).isEmpty();
bool isSpatial = vlayer->isSpatial();

mActionLocalHistogramStretch->setEnabled( false );
mActionFullHistogramStretch->setEnabled( false );
@@ -10610,14 +10611,16 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionIncreaseContrast->setEnabled( false );
mActionDecreaseContrast->setEnabled( false );
mActionZoomActualSize->setEnabled( false );
mActionLabeling->setEnabled( true );
mActionDiagramProperties->setEnabled( true );

mActionSelectFeatures->setEnabled( true );
mActionSelectPolygon->setEnabled( true );
mActionSelectFreehand->setEnabled( true );
mActionSelectRadius->setEnabled( true );
mActionIdentify->setEnabled( true );
mActionZoomToLayer->setEnabled( isSpatial );
mActionZoomToSelected->setEnabled( isSpatial );
mActionLabeling->setEnabled( isSpatial );
mActionDiagramProperties->setEnabled( isSpatial );

mActionSelectFeatures->setEnabled( isSpatial );
mActionSelectPolygon->setEnabled( isSpatial );
mActionSelectFreehand->setEnabled( isSpatial );
mActionSelectRadius->setEnabled( isSpatial );
mActionIdentify->setEnabled( isSpatial );
mActionSelectByExpression->setEnabled( true );
mActionSelectByForm->setEnabled( true );
mActionOpenTable->setEnabled( true );
@@ -10640,7 +10643,7 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
bool canDeleteFeatures = dprovider->capabilities() & QgsVectorDataProvider::DeleteFeatures;
bool canAddFeatures = dprovider->capabilities() & QgsVectorDataProvider::AddFeatures;
bool canSupportEditing = dprovider->capabilities() & QgsVectorDataProvider::EditingCapabilities;
bool canChangeGeometry = dprovider->capabilities() & QgsVectorDataProvider::ChangeGeometries;
bool canChangeGeometry = isSpatial && dprovider->capabilities() & QgsVectorDataProvider::ChangeGeometries;

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

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

mActionAddFeature->setEnabled( isEditable && canAddFeatures );
mActionCircularStringCurvePoint->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry ) && vlayer->geometryType() != QgsWkbTypes::PointGeometry );
mActionCircularStringRadius->setEnabled( isEditable && ( canAddFeatures || canChangeGeometry ) );
mActionCircularStringCurvePoint->setEnabled( isEditable && isSpatial && ( canAddFeatures || canChangeGeometry ) && vlayer->geometryType() != QgsWkbTypes::PointGeometry );
mActionCircularStringRadius->setEnabled( isEditable && isSpatial && ( canAddFeatures || canChangeGeometry ) );

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

mActionOpenFieldCalc->setEnabled( true );
@@ -10807,6 +10818,8 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
mActionSelectFreehand->setEnabled( false );
mActionSelectRadius->setEnabled( false );
mActionZoomActualSize->setEnabled( true );
mActionZoomToLayer->setEnabled( true );
mActionZoomToSelected->setEnabled( false );
mActionOpenTable->setEnabled( false );
mActionSelectAll->setEnabled( false );
mActionInvertSelection->setEnabled( false );
@@ -99,8 +99,11 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( layer );
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );

menu->addAction( actions->actionZoomToLayer( mCanvas, menu ) );
menu->addAction( actions->actionShowInOverview( menu ) );
if ( layer && layer->isSpatial() )
{
menu->addAction( actions->actionZoomToLayer( mCanvas, menu ) );
menu->addAction( actions->actionShowInOverview( menu ) );
}

if ( rlayer )
{

0 comments on commit 6a61179

Please sign in to comment.