Skip to content
Permalink
Browse files

Fix "Set Project CRS from Layer" action in layer right click menu

resets layer to have no CRS after changing the project CRS
  • Loading branch information
nyalldawson committed Sep 23, 2020
1 parent bddd3ed commit a674cb7b972e2e0c79a4ac8fcb87a8d4a9664200
Showing with 8 additions and 8 deletions.
  1. +7 −6 src/app/qgsapplayertreeviewmenuprovider.cpp
  2. +1 −2 src/app/qgsapplayertreeviewmenuprovider.h
@@ -349,13 +349,17 @@ QMenu *QgsAppLayerTreeViewMenuProvider::createContextMenu()
{
QAction *action = menuSetCRS->addAction( tr( "Set to %1" ).arg( crs.userFriendlyIdentifier( QgsCoordinateReferenceSystem::ShortString ) ) );
action->setProperty( "crs", crs.toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED ) );

connect( action, &QAction::triggered, this, [ = ]
{
setLayerCrs( crs );
} );

i++;
if ( i == 2 )
break;
}
}
// Connect once for the entire submenu.
connect( menuSetCRS, &QMenu::triggered, this, &QgsAppLayerTreeViewMenuProvider::setLayerCrs );

// set layer crs
menuSetCRS->addSeparator();
@@ -1023,11 +1027,8 @@ bool QgsAppLayerTreeViewMenuProvider::removeActionEnabled()
return true;
}

void QgsAppLayerTreeViewMenuProvider::setLayerCrs( QAction *action )
void QgsAppLayerTreeViewMenuProvider::setLayerCrs( const QgsCoordinateReferenceSystem &crs )
{
const QString wkt = action->property( "crs" ).toString();
const QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem( wkt );

const auto constSelectedNodes = mView->selectedNodes();
for ( QgsLayerTreeNode *node : constSelectedNodes )
{
@@ -71,8 +71,7 @@ class QgsAppLayerTreeViewMenuProvider : public QObject, public QgsLayerTreeViewM
void copySymbolLegendNodeSymbol( const QString &layerId, const QString &ruleKey );
void pasteSymbolLegendNodeSymbol( const QString &layerId, const QString &ruleKey );
void setSymbolLegendNodeColor( const QColor &color );
// Set layer CRS corresponding to the text of the given action
void setLayerCrs( QAction *action );
void setLayerCrs( const QgsCoordinateReferenceSystem &crs );
private:
bool removeActionEnabled();
};

0 comments on commit a674cb7

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