Skip to content
Permalink
Browse files

Only show "Set Project CRS from Layer" when all selected layers

have the same CRS

Otherwise it's a confusing option
  • Loading branch information
nyalldawson committed Sep 23, 2020
1 parent 4c7fbc0 commit 0ea1e5f44952461e50c1c8f58fd8024fdeee3e6e
Showing with 33 additions and 4 deletions.
  1. +33 −4 src/app/qgsapplayertreeviewmenuprovider.cpp
@@ -335,10 +335,39 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
: tr( "No CRS" ), menuSetCRS );
actionCurrentCrs->setEnabled( false );
menuSetCRS->addAction( actionCurrentCrs );
// assign layer crs to project
QAction *actionSetProjectCrs = new QAction( tr( "Set &Project CRS from Layer" ), menuSetCRS );
connect( actionSetProjectCrs, &QAction::triggered, QgisApp::instance(), &QgisApp::setProjectCrsFromLayer );
menuSetCRS->addAction( actionSetProjectCrs );

const QList<QgsLayerTreeNode *> selectedNodes = mView->selectedNodes();
QgsCoordinateReferenceSystem layerCrs;
bool firstLayer = true;
bool allSameCrs = true;
for ( QgsLayerTreeNode *node : selectedNodes )
{
if ( QgsLayerTree::isLayer( node ) )
{
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
if ( nodeLayer->layer() )
{
if ( firstLayer )
{
layerCrs = nodeLayer->layer()->crs();
firstLayer = false;
}
else if ( nodeLayer->layer()->crs() != layerCrs )
{
allSameCrs = false;
break;
}
}
}
}

if ( allSameCrs && layerCrs.isValid() )
{
// assign layer crs to project
QAction *actionSetProjectCrs = new QAction( tr( "Set &Project CRS from Layer" ), menuSetCRS );
connect( actionSetProjectCrs, &QAction::triggered, QgisApp::instance(), &QgisApp::setProjectCrsFromLayer );
menuSetCRS->addAction( actionSetProjectCrs );
}

const QList< QgsCoordinateReferenceSystem> recentProjections = QgsCoordinateReferenceSystem::recentCoordinateReferenceSystems();
if ( !recentProjections.isEmpty() )

0 comments on commit 0ea1e5f

Please sign in to comment.
You can’t perform that action at this time.