Skip to content

Commit c219001

Browse files
author
borysiasty
committedMar 10, 2011
[FEATURE] Assign layer CRS to project (legend context menu)
git-svn-id: http://svn.osgeo.org/qgis/trunk@15424 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent f5b5efc commit c219001

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed
 

‎src/app/legend/qgslegendlayer.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,11 @@ void QgsLegendLayer::addToPopupMenu( QMenu& theMenu )
431431
// remove from canvas
432432
theMenu.addAction( QgisApp::getThemeIcon( "/mActionRemoveLayer.png" ), tr( "&Remove" ), QgisApp::instance(), SLOT( removeLayer() ) );
433433

434-
// remove from canvas
434+
// set layer crs
435435
theMenu.addAction( QgisApp::getThemeIcon( "/mActionSetCRS.png" ), tr( "&Set layer CRS" ), QgisApp::instance(), SLOT( setLayerCRS() ) );
436+
437+
// assign layer crs to project
438+
theMenu.addAction( QgisApp::getThemeIcon( "/mActionSetProjectCRS.png" ), tr( "Assign layer CRS to &project" ), QgisApp::instance(), SLOT( setProjectCRSFromLayer() ) );
436439

437440
theMenu.addSeparator();
438441

‎src/app/qgisapp.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ void QgisApp::createActions()
792792
connect( mActionLayerSelectionSaveAs, SIGNAL( triggered() ), this, SLOT( saveSelectionAsVectorFile() ) );
793793
connect( mActionRemoveLayer, SIGNAL( triggered() ), this, SLOT( removeLayer() ) );
794794
connect( mActionSetLayerCRS, SIGNAL( triggered() ), this, SLOT( setLayerCRS() ) );
795+
connect( mActionSetProjectCRSFromLayer, SIGNAL( triggered() ), this, SLOT( setProjectCRSFromLayer() ) );
795796
connect( mActionTileScale, SIGNAL( triggered() ), this, SLOT( showTileScale() ) );
796797
connect( mActionGpsTool, SIGNAL( triggered() ), this, SLOT( showGpsTool() ) );
797798
connect( mActionLayerProperties, SIGNAL( triggered() ), this, SLOT( layerProperties() ) );
@@ -1339,6 +1340,7 @@ void QgisApp::setTheme( QString theThemeName )
13391340
#endif
13401341
mActionRemoveLayer->setIcon( getThemeIcon( "/mActionRemoveLayer.png" ) );
13411342
mActionSetLayerCRS->setIcon( getThemeIcon( "/mActionSetLayerCRS.png" ) );
1343+
mActionSetProjectCRSFromLayer->setIcon( getThemeIcon( "/mActionSetProjectCRSFromLayer.png" ) );
13421344
mActionNewVectorLayer->setIcon( getThemeIcon( "/mActionNewVectorLayer.png" ) );
13431345
mActionAddAllToOverview->setIcon( getThemeIcon( "/mActionAddAllToOverview.png" ) );
13441346
mActionHideAllLayers->setIcon( getThemeIcon( "/mActionHideAllLayers.png" ) );
@@ -4492,7 +4494,7 @@ void QgisApp::setLayerCRS()
44924494
return;
44934495
}
44944496

4495-
if ( !mMapLegend )
4497+
if ( !( mMapLegend && mMapLegend->currentLayer() ) )
44964498
{
44974499
return;
44984500
}
@@ -4513,6 +4515,28 @@ void QgisApp::setLayerCRS()
45134515
delete mySelector;
45144516
}
45154517

4518+
void QgisApp::setProjectCRSFromLayer()
4519+
{
4520+
if ( mMapCanvas && mMapCanvas->isDrawing() )
4521+
{
4522+
return;
4523+
}
4524+
4525+
if ( !( mMapLegend && mMapLegend->currentLayer() ) )
4526+
{
4527+
return;
4528+
}
4529+
4530+
QgsCoordinateReferenceSystem crs = mMapLegend->currentLayer()->crs();
4531+
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
4532+
myRenderer->setDestinationSrs( crs );
4533+
if ( crs.mapUnits() != QGis::UnknownUnit )
4534+
{
4535+
myRenderer->setMapUnits( crs.mapUnits() );
4536+
}
4537+
mMapCanvas->refresh();
4538+
}
4539+
45164540
void QgisApp::showGpsTool()
45174541
{
45184542
if ( !mpGpsWidget )
@@ -5567,6 +5591,7 @@ void QgisApp::legendLayerSelectionChanged( void )
55675591
{
55685592
mActionRemoveLayer->setEnabled( mMapLegend && mMapLegend->selectedLayers().size() > 0 );
55695593
mActionSetLayerCRS->setEnabled( mMapLegend && mMapLegend->selectedLayers().size() > 0 );
5594+
mActionSetProjectCRSFromLayer->setEnabled( mMapLegend && mMapLegend->selectedLayers().size() == 1 );
55705595
}
55715596

55725597
void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )

‎src/app/qgisapp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
276276
QAction *actionLayerSelectionSaveAs() { return mActionLayerSelectionSaveAs; }
277277
QAction *actionRemoveLayer() { return mActionRemoveLayer; }
278278
QAction *actionSetLayerCRS() { return mActionSetLayerCRS; }
279+
QAction *actionSetProjectCRSFromLayer() { return mActionSetProjectCRSFromLayer; }
279280
QAction *actionTileScale() { return mActionTileScale; }
280281
QAction *actionGpsTool() { return mActionGpsTool; }
281282
QAction *actionLayerProperties() { return mActionLayerProperties; }
@@ -482,6 +483,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
482483
void removeLayer();
483484
//! Set CRS of a layer
484485
void setLayerCRS();
486+
//! Assign layer CRS to project
487+
void setProjectCRSFromLayer();
485488
//! Show GPS tool
486489
void showGpsTool();
487490
//! Show tile scale slider

‎src/ui/qgisapp.ui

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
<addaction name="mActionLayerSelectionSaveAs"/>
148148
<addaction name="mActionRemoveLayer"/>
149149
<addaction name="mActionSetLayerCRS"/>
150+
<addaction name="mActionSetProjectCRSFromLayer"/>
150151
<addaction name="mActionLayerProperties"/>
151152
<addaction name="mActionLayerSubsetString"/>
152153
<addaction name="mActionLabeling"/>
@@ -1198,6 +1199,11 @@
11981199
<string>Ctrl+Shift+C</string>
11991200
</property>
12001201
</action>
1202+
<action name="mActionSetProjectCRSFromLayer">
1203+
<property name="text">
1204+
<string>Assign layer CRS to project</string>
1205+
</property>
1206+
</action>
12011207
<action name="mActionTileScale">
12021208
<property name="text">
12031209
<string>Tile scale slider</string>

0 commit comments

Comments
 (0)
Please sign in to comment.