Skip to content

Commit

Permalink
layer context menu: disable CRS related menu entries from table layers (
Browse files Browse the repository at this point in the history
fixes #12654)

(cherry picked from commit 3d193e3)
  • Loading branch information
jef-n committed Jun 29, 2015
1 parent 391e99c commit e64100f
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/app/qgsapplayertreeviewmenuprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,18 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
}
else if ( QgsLayerTree::isLayer( node ) )
{
QgsMapLayer* layer = QgsLayerTree::toLayer( node )->layer();
QgsMapLayer *layer = QgsLayerTree::toLayer( node )->layer();
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->type() == QgsMapLayer::RasterLayer )
if ( rlayer )
{
menu->addAction( tr( "&Zoom to Best Scale (100%)" ), QgisApp::instance(), SLOT( legendLayerZoomNative() ) );

QgsRasterLayer* rasterLayer = qobject_cast<QgsRasterLayer *>( layer );
if ( rasterLayer && rasterLayer->rasterType() != QgsRasterLayer::Palette )
if ( rlayer->rasterType() != QgsRasterLayer::Palette )
menu->addAction( tr( "&Stretch Using Current Extent" ), QgisApp::instance(), SLOT( legendLayerStretchUsingCurrentExtent() ) );
}

Expand All @@ -81,21 +82,24 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()
// duplicate layer
QAction* duplicateLayersAction = menu->addAction( QgsApplication::getThemeIcon( "/mActionDuplicateLayer.svg" ), tr( "&Duplicate" ), QgisApp::instance(), SLOT( duplicateLayers() ) );

// set layer scale visibility
menu->addAction( tr( "&Set Layer Scale Visibility" ), QgisApp::instance(), SLOT( setLayerScaleVisibility() ) );
if ( !vlayer || vlayer->geometryType() != QGis::NoGeometry )
{
// set layer scale visibility
menu->addAction( tr( "&Set Layer Scale Visibility" ), QgisApp::instance(), SLOT( setLayerScaleVisibility() ) );

// set layer crs
menu->addAction( QgsApplication::getThemeIcon( "/mActionSetCRS.png" ), tr( "&Set Layer CRS" ), QgisApp::instance(), SLOT( setLayerCRS() ) );
// set layer crs
menu->addAction( QgsApplication::getThemeIcon( "/mActionSetCRS.png" ), tr( "&Set Layer CRS" ), QgisApp::instance(), SLOT( setLayerCRS() ) );

// assign layer crs to project
menu->addAction( QgsApplication::getThemeIcon( "/mActionSetProjectCRS.png" ), tr( "Set &Project CRS from Layer" ), QgisApp::instance(), SLOT( setProjectCRSFromLayer() ) );
// assign layer crs to project
menu->addAction( QgsApplication::getThemeIcon( "/mActionSetProjectCRS.png" ), tr( "Set &Project CRS from Layer" ), QgisApp::instance(), SLOT( setProjectCRSFromLayer() ) );
}

// style-related actions
if ( layer && mView->selectedLayerNodes().count() == 1 )
{
QMenu* menuStyleManager = new QMenu( tr( "Styles" ) );
QMenu *menuStyleManager = new QMenu( tr( "Styles" ) );

QgisApp* app = QgisApp::instance();
QgisApp *app = QgisApp::instance();
menuStyleManager->addAction( tr( "Copy Style" ), app, SLOT( copyStyle() ) );
if ( app->clipboard()->hasFormat( QGSCLIPBOARD_STYLE_MIME ) )
{
Expand All @@ -110,10 +114,8 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()

menu->addSeparator();

if ( layer && layer->type() == QgsMapLayer::VectorLayer )
if ( vlayer )
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( layer );

QAction *toggleEditingAction = QgisApp::instance()->actionToggleEditing();
QAction *saveLayerEditsAction = QgisApp::instance()->actionSaveActiveLayerEdits();
QAction *allEditsAction = QgisApp::instance()->actionAllEdits();
Expand Down Expand Up @@ -155,7 +157,7 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()

menu->addSeparator();
}
else if ( layer && layer->type() == QgsMapLayer::RasterLayer )
else if ( rlayer )
{
menu->addAction( tr( "Save As..." ), QgisApp::instance(), SLOT( saveAsRasterFile() ) );
menu->addAction( tr( "Save As Layer Definition File..." ), QgisApp::instance(), SLOT( saveAsLayerDefinition() ) );
Expand Down

0 comments on commit e64100f

Please sign in to comment.