[FEATURE] Assign layer CRS to project (legend context menu)

git-svn-id: http://svn.osgeo.org/qgis/trunk@15424 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
borysiasty 2011-03-10 22:54:18 +00:00
parent f5b5efc71b
commit c2190016b3
4 changed files with 39 additions and 2 deletions

View File

@ -431,8 +431,11 @@ void QgsLegendLayer::addToPopupMenu( QMenu& theMenu )
// remove from canvas
theMenu.addAction( QgisApp::getThemeIcon( "/mActionRemoveLayer.png" ), tr( "&Remove" ), QgisApp::instance(), SLOT( removeLayer() ) );
// remove from canvas
// set layer crs
theMenu.addAction( QgisApp::getThemeIcon( "/mActionSetCRS.png" ), tr( "&Set layer CRS" ), QgisApp::instance(), SLOT( setLayerCRS() ) );
// assign layer crs to project
theMenu.addAction( QgisApp::getThemeIcon( "/mActionSetProjectCRS.png" ), tr( "Assign layer CRS to &project" ), QgisApp::instance(), SLOT( setProjectCRSFromLayer() ) );
theMenu.addSeparator();

View File

@ -792,6 +792,7 @@ void QgisApp::createActions()
connect( mActionLayerSelectionSaveAs, SIGNAL( triggered() ), this, SLOT( saveSelectionAsVectorFile() ) );
connect( mActionRemoveLayer, SIGNAL( triggered() ), this, SLOT( removeLayer() ) );
connect( mActionSetLayerCRS, SIGNAL( triggered() ), this, SLOT( setLayerCRS() ) );
connect( mActionSetProjectCRSFromLayer, SIGNAL( triggered() ), this, SLOT( setProjectCRSFromLayer() ) );
connect( mActionTileScale, SIGNAL( triggered() ), this, SLOT( showTileScale() ) );
connect( mActionGpsTool, SIGNAL( triggered() ), this, SLOT( showGpsTool() ) );
connect( mActionLayerProperties, SIGNAL( triggered() ), this, SLOT( layerProperties() ) );
@ -1339,6 +1340,7 @@ void QgisApp::setTheme( QString theThemeName )
#endif
mActionRemoveLayer->setIcon( getThemeIcon( "/mActionRemoveLayer.png" ) );
mActionSetLayerCRS->setIcon( getThemeIcon( "/mActionSetLayerCRS.png" ) );
mActionSetProjectCRSFromLayer->setIcon( getThemeIcon( "/mActionSetProjectCRSFromLayer.png" ) );
mActionNewVectorLayer->setIcon( getThemeIcon( "/mActionNewVectorLayer.png" ) );
mActionAddAllToOverview->setIcon( getThemeIcon( "/mActionAddAllToOverview.png" ) );
mActionHideAllLayers->setIcon( getThemeIcon( "/mActionHideAllLayers.png" ) );
@ -4492,7 +4494,7 @@ void QgisApp::setLayerCRS()
return;
}
if ( !mMapLegend )
if ( !( mMapLegend && mMapLegend->currentLayer() ) )
{
return;
}
@ -4513,6 +4515,28 @@ void QgisApp::setLayerCRS()
delete mySelector;
}
void QgisApp::setProjectCRSFromLayer()
{
if ( mMapCanvas && mMapCanvas->isDrawing() )
{
return;
}
if ( !( mMapLegend && mMapLegend->currentLayer() ) )
{
return;
}
QgsCoordinateReferenceSystem crs = mMapLegend->currentLayer()->crs();
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
myRenderer->setDestinationSrs( crs );
if ( crs.mapUnits() != QGis::UnknownUnit )
{
myRenderer->setMapUnits( crs.mapUnits() );
}
mMapCanvas->refresh();
}
void QgisApp::showGpsTool()
{
if ( !mpGpsWidget )
@ -5567,6 +5591,7 @@ void QgisApp::legendLayerSelectionChanged( void )
{
mActionRemoveLayer->setEnabled( mMapLegend && mMapLegend->selectedLayers().size() > 0 );
mActionSetLayerCRS->setEnabled( mMapLegend && mMapLegend->selectedLayers().size() > 0 );
mActionSetProjectCRSFromLayer->setEnabled( mMapLegend && mMapLegend->selectedLayers().size() == 1 );
}
void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )

View File

@ -276,6 +276,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QAction *actionLayerSelectionSaveAs() { return mActionLayerSelectionSaveAs; }
QAction *actionRemoveLayer() { return mActionRemoveLayer; }
QAction *actionSetLayerCRS() { return mActionSetLayerCRS; }
QAction *actionSetProjectCRSFromLayer() { return mActionSetProjectCRSFromLayer; }
QAction *actionTileScale() { return mActionTileScale; }
QAction *actionGpsTool() { return mActionGpsTool; }
QAction *actionLayerProperties() { return mActionLayerProperties; }
@ -482,6 +483,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
void removeLayer();
//! Set CRS of a layer
void setLayerCRS();
//! Assign layer CRS to project
void setProjectCRSFromLayer();
//! Show GPS tool
void showGpsTool();
//! Show tile scale slider

View File

@ -147,6 +147,7 @@
<addaction name="mActionLayerSelectionSaveAs"/>
<addaction name="mActionRemoveLayer"/>
<addaction name="mActionSetLayerCRS"/>
<addaction name="mActionSetProjectCRSFromLayer"/>
<addaction name="mActionLayerProperties"/>
<addaction name="mActionLayerSubsetString"/>
<addaction name="mActionLabeling"/>
@ -1198,6 +1199,11 @@
<string>Ctrl+Shift+C</string>
</property>
</action>
<action name="mActionSetProjectCRSFromLayer">
<property name="text">
<string>Assign layer CRS to project</string>
</property>
</action>
<action name="mActionTileScale">
<property name="text">
<string>Tile scale slider</string>