Skip to content

Commit

Permalink
[FEATURE] Assign layer CRS to project (legend context menu)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@15424 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
borysiasty committed Mar 10, 2011
1 parent f5b5efc commit c219001
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/app/legend/qgslegendlayer.cpp
Expand Up @@ -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();

Expand Down
27 changes: 26 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -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() ) );
Expand Down Expand Up @@ -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" ) );
Expand Down Expand Up @@ -4492,7 +4494,7 @@ void QgisApp::setLayerCRS()
return;
}

if ( !mMapLegend )
if ( !( mMapLegend && mMapLegend->currentLayer() ) )
{
return;
}
Expand All @@ -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 )
Expand Down Expand Up @@ -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 )
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -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; }
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/ui/qgisapp.ui
Expand Up @@ -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"/>
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit c219001

Please sign in to comment.