[QGIS Commit] r15424 - in trunk/qgis/src: app app/legend ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Mar 10 17:54:18 EST 2011


Author: borysiasty
Date: 2011-03-10 14:54:18 -0800 (Thu, 10 Mar 2011)
New Revision: 15424

Modified:
   trunk/qgis/src/app/legend/qgslegendlayer.cpp
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/app/qgisapp.h
   trunk/qgis/src/ui/qgisapp.ui
Log:
[FEATURE] Assign layer CRS to project (legend context menu)

Modified: trunk/qgis/src/app/legend/qgslegendlayer.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegendlayer.cpp	2011-03-10 21:39:54 UTC (rev 15423)
+++ trunk/qgis/src/app/legend/qgslegendlayer.cpp	2011-03-10 22:54:18 UTC (rev 15424)
@@ -431,8 +431,11 @@
   // 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();
 

Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2011-03-10 21:39:54 UTC (rev 15423)
+++ trunk/qgis/src/app/qgisapp.cpp	2011-03-10 22:54:18 UTC (rev 15424)
@@ -792,6 +792,7 @@
   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 @@
 #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 @@
     return;
   }
 
-  if ( !mMapLegend )
+  if ( !( mMapLegend && mMapLegend->currentLayer() ) )
   {
     return;
   }
@@ -4513,6 +4515,28 @@
   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 @@
 {
   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 )

Modified: trunk/qgis/src/app/qgisapp.h
===================================================================
--- trunk/qgis/src/app/qgisapp.h	2011-03-10 21:39:54 UTC (rev 15423)
+++ trunk/qgis/src/app/qgisapp.h	2011-03-10 22:54:18 UTC (rev 15424)
@@ -276,6 +276,7 @@
     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 @@
     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

Modified: trunk/qgis/src/ui/qgisapp.ui
===================================================================
--- trunk/qgis/src/ui/qgisapp.ui	2011-03-10 21:39:54 UTC (rev 15423)
+++ trunk/qgis/src/ui/qgisapp.ui	2011-03-10 22:54:18 UTC (rev 15424)
@@ -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>



More information about the QGIS-commit mailing list