Skip to content

Commit

Permalink
Fix "Set Project CRS from Layer" action in layer right click menu
Browse files Browse the repository at this point in the history
resets layer to have no CRS after changing the project CRS
  • Loading branch information
nyalldawson committed Sep 23, 2020
1 parent bddd3ed commit a674cb7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/app/qgsapplayertreeviewmenuprovider.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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 )
{
Expand Down
3 changes: 1 addition & 2 deletions src/app/qgsapplayertreeviewmenuprovider.h
Expand Up @@ -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();
};
Expand Down

0 comments on commit a674cb7

Please sign in to comment.