[QGIS Commit] r15352 - in trunk/qgis: images/themes/default src/app src/app/legend

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Mar 5 21:18:18 EST 2011


Author: jef
Date: 2011-03-05 18:18:18 -0800 (Sat, 05 Mar 2011)
New Revision: 15352

Added:
   trunk/qgis/images/themes/default/mActionHelpAPI.png
Modified:
   trunk/qgis/src/app/legend/qgslegend.cpp
   trunk/qgis/src/app/legend/qgslegend.h
   trunk/qgis/src/app/legend/qgslegendlayer.cpp
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/app/qgisapp.h
Log:
[FEATURE] allow setting CRS for multiple layers at once

Added: trunk/qgis/images/themes/default/mActionHelpAPI.png
===================================================================
(Binary files differ)


Property changes on: trunk/qgis/images/themes/default/mActionHelpAPI.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: trunk/qgis/src/app/legend/qgslegend.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.cpp	2011-03-06 02:16:44 UTC (rev 15351)
+++ trunk/qgis/src/app/legend/qgslegend.cpp	2011-03-06 02:18:18 UTC (rev 15352)
@@ -33,7 +33,7 @@
 #include "qgsproject.h"
 #include "qgsrasterlayer.h"
 #include "qgsvectorlayer.h"
-#include "qgsprojectbadlayerguihandler.h"
+#include "qgsgenericprojectionselector.h"
 
 #include <QFont>
 #include <QDomDocument>
@@ -525,16 +525,16 @@
 {
   QSettings settings;
 
-  switch( settings.value( "/qgis/legendDoubleClickAction", 0 ).toInt() )
+  switch ( settings.value( "/qgis/legendDoubleClickAction", 0 ).toInt() )
   {
-  case 0:
-    QgisApp::instance()->layerProperties();
-    break;
-  case 1:
-    QgisApp::instance()->attributeTable();
-    break;
-  default:
-    break;
+    case 0:
+      QgisApp::instance()->layerProperties();
+      break;
+    case 1:
+      QgisApp::instance()->attributeTable();
+      break;
+    default:
+      break;
   }
 }
 
@@ -558,7 +558,6 @@
       {
         theMenu.addAction( tr( "&Make to toplevel item" ), this, SLOT( makeToTopLevelItem() ) );
       }
-
     }
     else if ( li->type() == QgsLegendItem::LEGEND_GROUP )
     {
@@ -567,6 +566,9 @@
 
       theMenu.addAction( QgisApp::getThemeIcon( "/mActionRemoveLayer.png" ),
                          tr( "&Remove" ), this, SLOT( legendGroupRemove() ) );
+
+      theMenu.addAction( QgisApp::getThemeIcon( "/mActionSetCRS.png" ),
+                         tr( "&Set group CRS" ), this, SLOT( legendGroupSetCRS() ) );
     }
 
     if ( li->type() == QgsLegendItem::LEGEND_LAYER || li->type() == QgsLegendItem::LEGEND_GROUP )
@@ -739,6 +741,30 @@
   }
 }
 
+void QgsLegend::legendGroupSetCRS()
+{
+  if ( !mMapCanvas || mMapCanvas->isDrawing() )
+  {
+    return;
+  }
+
+  QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector( this );
+  mySelector->setMessage();
+  if ( mySelector->exec() )
+  {
+    QgsCoordinateReferenceSystem crs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId );
+
+    QgsLegendGroup* lg = dynamic_cast<QgsLegendGroup *>( currentItem() );
+    setGroupCRS( lg, crs );
+  }
+  else
+  {
+    QApplication::restoreOverrideCursor();
+  }
+
+  delete mySelector;
+}
+
 void QgsLegend::removeGroup( QgsLegendGroup *lg )
 {
   if ( !mMapCanvas || mMapCanvas->isDrawing() )
@@ -766,6 +792,36 @@
   adjustIconSize();
 }
 
+void QgsLegend::setGroupCRS( QgsLegendGroup *lg, const QgsCoordinateReferenceSystem &crs )
+{
+  if ( !mMapCanvas || mMapCanvas->isDrawing() )
+  {
+    return;
+  }
+
+  //delete the legend layers first
+  QTreeWidgetItem * child = lg->child( 0 );
+  while ( child )
+  {
+    QgsLegendLayer *cl = dynamic_cast<QgsLegendLayer *>( child );
+    QgsLegendGroup *cg = dynamic_cast<QgsLegendGroup *>( child );
+
+    if ( cl )
+    {
+      cl->layer()->setCrs( crs );
+    }
+    else if ( cg )
+    {
+      setGroupCRS( cg, crs );
+    }
+
+    child = lg->child( 0 );
+  }
+
+  delete lg;
+}
+
+
 void QgsLegend::moveLayer( QgsMapLayer *ml, int groupIndex )
 {
   if ( !ml )
@@ -999,20 +1055,11 @@
     {
       bool isOpen;
       QgsLegendLayer* currentLayer = readLayerFromXML( childelem, isOpen );
-
-      bool ignorePressed = QgsProjectBadLayerGuiHandler::mIgnore;
-      
       if ( !currentLayer )
-      {  
-        if( ignorePressed == true )
-        {
-          continue;
-        }
-        else
-        {
-          return false;
-        }
+      {
+        continue;
       }
+
       // add to tree - either as a top-level node or a child of a group
       if ( parent )
       {
@@ -1920,3 +1967,32 @@
   if ( renderFlagState )
     mMapCanvas->setRenderFlag( true );
 }
+
+void QgsLegend::setCRSForSelectedLayers( const QgsCoordinateReferenceSystem &crs )
+{
+  // Turn off rendering to improve speed.
+  bool renderFlagState = mMapCanvas->renderFlag();
+  if ( renderFlagState )
+    mMapCanvas->setRenderFlag( false );
+
+  foreach( QTreeWidgetItem * item, selectedItems() )
+  {
+    QgsLegendGroup* lg = dynamic_cast<QgsLegendGroup *>( item );
+    if ( lg )
+    {
+      setGroupCRS( lg, crs );
+      continue;
+    }
+
+    QgsLegendLayer *ll = dynamic_cast<QgsLegendLayer *>( item );
+    if ( ll && ll->layer() )
+    {
+      ll->layer()->setCrs( crs );
+      continue;
+    }
+  }
+
+  // Turn on rendering (if it was on previously)
+  if ( renderFlagState )
+    mMapCanvas->setRenderFlag( true );
+}

Modified: trunk/qgis/src/app/legend/qgslegend.h
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.h	2011-03-06 02:16:44 UTC (rev 15351)
+++ trunk/qgis/src/app/legend/qgslegend.h	2011-03-06 02:18:18 UTC (rev 15352)
@@ -34,6 +34,7 @@
 class QDomNode;
 class QMouseEvent;
 class QTreeWidgetItem;
+class QgsCoordinateReferenceSystem;
 
 //Information about relationship between groups and layers
 //key: group name (or null strings for single layers without groups)
@@ -266,6 +267,9 @@
     /** Remove selected layers */
     void removeSelectedLayers();
 
+    /** Set CRS for selected layers */
+    void setCRSForSelectedLayers( const QgsCoordinateReferenceSystem &crs );
+
   protected:
 
     /*!Event handler for mouse movements.
@@ -362,8 +366,12 @@
     void handleRightClickEvent( QTreeWidgetItem* item, const QPoint& position );
     /**Removes the current legend group*/
     void legendGroupRemove();
+    /**Set the CRS of the current legend group*/
+    void legendGroupSetCRS();
     /**Removes a legend group and its layers*/
     void removeGroup( QgsLegendGroup * lg );
+    /**Removes a legend group and its layers*/
+    void setGroupCRS( QgsLegendGroup * lg, const QgsCoordinateReferenceSystem &crs );
     /**Sets all listview items to open*/
     void expandAll();
     /**Sets all listview items to closed*/

Modified: trunk/qgis/src/app/legend/qgslegendlayer.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegendlayer.cpp	2011-03-06 02:16:44 UTC (rev 15351)
+++ trunk/qgis/src/app/legend/qgslegendlayer.cpp	2011-03-06 02:18:18 UTC (rev 15352)
@@ -432,6 +432,9 @@
   // remove from canvas
   theMenu.addAction( QgisApp::getThemeIcon( "/mActionRemoveLayer.png" ), tr( "&Remove" ), QgisApp::instance(), SLOT( removeLayer() ) );
 
+  // remove from canvas
+  theMenu.addAction( QgisApp::getThemeIcon( "/mActionSetCRS.png" ), tr( "&Set layer CRS" ), QgisApp::instance(), SLOT( setLayerCRS() ) );
+
   theMenu.addSeparator();
 
   if ( lyr->type() == QgsMapLayer::VectorLayer )

Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2011-03-06 02:16:44 UTC (rev 15351)
+++ trunk/qgis/src/app/qgisapp.cpp	2011-03-06 02:18:18 UTC (rev 15352)
@@ -141,7 +141,7 @@
 #include "qgspluginmetadata.h"
 #include "qgspluginregistry.h"
 #include "qgspoint.h"
-#include "qgsprojectbadlayerguihandler.h"
+#include "qgshandlebadlayers.h"
 #include "qgsproject.h"
 #include "qgsprojectproperties.h"
 #include "qgsproviderregistry.h"
@@ -506,7 +506,7 @@
   QgsRasterLayer::buildSupportedRasterFileFilter( mRasterFileFilter );
 
   // set handler for missing layers (will be owned by QgsProject)
-  QgsProject::instance()->setBadLayerHandler( new QgsProjectBadLayerGuiHandler() );
+  QgsProject::instance()->setBadLayerHandler( new QgsHandleBadLayersHandler() );
 
 #if 0
   // Set the background color for toolbox and overview as they default to
@@ -1125,6 +1125,12 @@
   connect( mActionRemoveLayer, SIGNAL( triggered() ), this, SLOT( removeLayer() ) );
   mActionRemoveLayer->setEnabled( false );
 
+  mActionSetLayerCRS = new QAction( getThemeIcon( "mActionSetLayerCRS.png" ), tr( "Set CRS of Layer(s)" ), this );
+  shortcuts->registerAction( mActionSetLayerCRS, tr( "Ctrl+Shift+C", "Set CRS of Layer(s)" ) );
+  mActionSetLayerCRS->setStatusTip( tr( "Set CRS of Layer(s)" ) );
+  connect( mActionSetLayerCRS, SIGNAL( triggered() ), this, SLOT( setLayerCRS() ) );
+  mActionSetLayerCRS->setEnabled( false );
+
   mActionTileScale = new QAction( getThemeIcon( "mActionTileScale.png" ), tr( "Tile scale slider" ), this );
   shortcuts->registerAction( mActionTileScale, tr( "", "Tile scale slider" ) );
   mActionTileScale->setStatusTip( tr( "Show tile scale slider" ) );
@@ -1249,7 +1255,15 @@
 #endif
   mActionHelpContents->setStatusTip( tr( "Help Documentation" ) );
   connect( mActionHelpContents, SIGNAL( triggered() ), this, SLOT( helpContents() ) );
+  mActionHelpContents->setEnabled( QFileInfo( QgsApplication::pkgDataPath() + "/doc/index.html" ).exists() );
 
+#ifdef WITH_APIDOC
+  mActionHelpAPI = new QAction( getThemeIcon( "mActionHelpAPI.png" ), tr( "API documentation" ), this );
+  connect( mActionHelpAPI, SIGNAL( triggered() ), this, SLOT( apiDocumentation() ) );
+  mActionHelpAPI->setEnabled( QFileInfo( QgsApplication::pkgDataPath() + "/doc/api/index.html" ).exists() );
+#endif
+
+
   mActionQgisHomePage = new QAction( getThemeIcon( "mActionQgisHomePage.png" ), tr( "QGIS Home Page" ), this );
 #ifndef Q_WS_MAC
   shortcuts->registerAction( mActionQgisHomePage, tr( "Ctrl+H", "QGIS Home Page" ) );
@@ -1609,6 +1623,7 @@
   mLayerMenu->addAction( mActionLayerSaveAs );
   mLayerMenu->addAction( mActionLayerSelectionSaveAs );
   mLayerMenu->addAction( mActionRemoveLayer );
+  mLayerMenu->addAction( mActionSetLayerCRS );
   mLayerMenu->addAction( mActionLayerProperties );
   mLayerMenu->addAction( mActionLayerSubsetString );
   mActionLayerSeparator2 = mLayerMenu->addSeparator();
@@ -1684,6 +1699,9 @@
   mHelpMenu = menuBar()->addMenu( tr( "&Help" ) );
 
   mHelpMenu->addAction( mActionHelpContents );
+#ifdef WITH_APIDOC
+  mHelpMenu->addAction( mActionHelpAPI );
+#endif
   mActionHelpSeparator1 = mHelpMenu->addSeparator();
 
   mHelpMenu->addAction( mActionQgisHomePage );
@@ -1730,6 +1748,7 @@
   mLayerToolBar->addAction( mActionAddWmsLayer );
   mLayerToolBar->addAction( mActionNewVectorLayer );
   mLayerToolBar->addAction( mActionRemoveLayer );
+  mLayerToolBar->addAction( mActionSetLayerCRS );
   //commented out for QGIS 1.4 by Tim
   //mLayerToolBar->addAction( mActionAddToOverview );
   //mLayerToolBar->addAction( mActionShowAllLayers );
@@ -1898,6 +1917,9 @@
   mHelpToolBar = addToolBar( tr( "Help" ) );
   mHelpToolBar->setObjectName( "Help" );
   mHelpToolBar->addAction( mActionHelpContents );
+#ifdef WITH_APIDOC
+  mHelpToolBar->addAction( mActionHelpAPI );
+#endif
   mHelpToolBar->addAction( QWhatsThis::createAction() );
   mToolbarMenu->addAction( mHelpToolBar->toggleViewAction() );
 
@@ -2108,6 +2130,7 @@
   mActionAddPgLayer->setIcon( getThemeIcon( "/mActionAddLayer.png" ) );
   mActionAddSpatiaLiteLayer->setIcon( getThemeIcon( "/mActionAddSpatiaLiteLayer.png" ) );
   mActionRemoveLayer->setIcon( getThemeIcon( "/mActionRemoveLayer.png" ) );
+  mActionSetLayerCRS->setIcon( getThemeIcon( "/mActionSetLayerCRS.png" ) );
   mActionNewVectorLayer->setIcon( getThemeIcon( "/mActionNewVectorLayer.png" ) );
   mActionAddAllToOverview->setIcon( getThemeIcon( "/mActionAddAllToOverview.png" ) );
   mActionHideAllLayers->setIcon( getThemeIcon( "/mActionHideAllLayers.png" ) );
@@ -2120,6 +2143,9 @@
   mActionOptions->setIcon( getThemeIcon( "/mActionOptions.png" ) );
   mActionConfigureShortcuts->setIcon( getThemeIcon( "/mActionOptions.png" ) );
   mActionHelpContents->setIcon( getThemeIcon( "/mActionHelpContents.png" ) );
+#ifdef WITH_APIDOC
+  mActionHelpAPI->setIcon( getThemeIcon( "/mActionHelpApi.png" ) );
+#endif
   mActionLocalHistogramStretch->setIcon( getThemeIcon( "/mActionLocalHistogramStretch.png" ) );
   mActionQgisHomePage->setIcon( getThemeIcon( "/mActionQgisHomePage.png" ) );
   mActionAbout->setIcon( getThemeIcon( "/mActionHelpAbout.png" ) );
@@ -4107,7 +4133,7 @@
       }
       else
       {
-        destCRS = vlayer->srs();
+        destCRS = vlayer->crs();
       }
     }
     else
@@ -4812,7 +4838,7 @@
     {
       QgsFeatureList features = selectionVectorLayer->selectedFeatures();
       clipboard()->replaceWithCopyOf( selectionVectorLayer->pendingFields(), features );
-      clipboard()->setCRS( selectionVectorLayer->srs() );
+      clipboard()->setCRS( selectionVectorLayer->crs() );
       selectionVectorLayer->beginEditCommand( tr( "Features cut" ) );
       selectionVectorLayer->deleteSelectedFeatures();
       selectionVectorLayer->endEditCommand();
@@ -4839,7 +4865,7 @@
     {
       QgsFeatureList features = selectionVectorLayer->selectedFeatures();
       clipboard()->replaceWithCopyOf( selectionVectorLayer->pendingFields(), features );
-      clipboard()->setCRS( selectionVectorLayer->srs() );
+      clipboard()->setCRS( selectionVectorLayer->crs() );
     }
   }
 }
@@ -4865,7 +4891,7 @@
       QgsFeatureList features;
       if ( mMapCanvas->mapRenderer()->hasCrsTransformEnabled() )
       {
-        features = clipboard()->transformedCopyOf( pasteVectorLayer->srs() );
+        features = clipboard()->transformedCopyOf( pasteVectorLayer->crs() );
       }
       else
       {
@@ -5233,6 +5259,34 @@
   mMapCanvas->refresh();
 }
 
+void QgisApp::setLayerCRS()
+{
+  if ( mMapCanvas && mMapCanvas->isDrawing() )
+  {
+    return;
+  }
+
+  if ( !mMapLegend )
+  {
+    return;
+  }
+
+  QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector( this );
+  mySelector->setMessage();
+  if ( mySelector->exec() )
+  {
+    QgsCoordinateReferenceSystem crs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId );
+    mMapLegend->setCRSForSelectedLayers( crs );
+    mMapCanvas->refresh();
+  }
+  else
+  {
+    QApplication::restoreOverrideCursor();
+  }
+
+  delete mySelector;
+}
+
 void QgisApp::showGpsTool()
 {
   if ( !mpGpsWidget )
@@ -5550,7 +5604,7 @@
       myRenderer->setProjectionsEnabled( false );
     }
     mMapCanvas->refresh();
- }
+  }
 
   delete optionsDialog;
 }
@@ -5602,6 +5656,11 @@
   openURL( "index.html" );
 }
 
+void QgisApp::apiDocumentation()
+{
+  openURL( "api/index.html" );
+}
+
 void QgisApp::helpQgisHomePage()
 {
   openURL( "http://qgis.org", false );
@@ -6283,6 +6342,7 @@
 void QgisApp::legendLayerSelectionChanged( void )
 {
   mActionRemoveLayer->setEnabled( mMapLegend && mMapLegend->selectedLayers().size() > 0 );
+  mActionSetLayerCRS->setEnabled( mMapLegend && mMapLegend->selectedLayers().size() > 0 );
 }
 
 void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )

Modified: trunk/qgis/src/app/qgisapp.h
===================================================================
--- trunk/qgis/src/app/qgisapp.h	2011-03-06 02:16:44 UTC (rev 15351)
+++ trunk/qgis/src/app/qgisapp.h	2011-03-06 02:18:18 UTC (rev 15352)
@@ -287,6 +287,7 @@
     QAction *actionLayerSaveAs() { return mActionLayerSaveAs; }
     QAction *actionLayerSelectionSaveAs() { return mActionLayerSelectionSaveAs; }
     QAction *actionRemoveLayer() { return mActionRemoveLayer; }
+    QAction *actionSetLayerCRS() { return mActionSetLayerCRS; }
     QAction *actionTileScale() { return mActionTileScale; }
     QAction *actionGpsTool() { return mActionGpsTool; }
     QAction *actionLayerProperties() { return mActionLayerProperties; }
@@ -321,6 +322,7 @@
 #endif
 
     QAction *actionHelpContents() { return mActionHelpContents; }
+    QAction *actionHelpAPI() { return mActionHelpAPI; }
     QAction *actionHelpSeparator1() { return mActionHelpSeparator1; }
     QAction *actionQgisHomePage() { return mActionQgisHomePage; }
     QAction *actionCheckQgisVersion() { return mActionCheckQgisVersion; }
@@ -496,6 +498,8 @@
     void userCenter();
     //! Remove a layer from the map and legend
     void removeLayer();
+    //! Set CRS of a layer
+    void setLayerCRS();
     //! Show GPS tool
     void showGpsTool();
     //! Show tile scale slider
@@ -577,6 +581,8 @@
     bool setActiveLayer( QgsMapLayer * );
     //! Open the help contents in a browser
     void helpContents();
+    //! Open the API documentation in a browser
+    void apiDocumentation();
     //! Open the QGIS homepage in users browser
     void helpQgisHomePage();
     //! Open a url in the users configured browser
@@ -980,6 +986,7 @@
     QAction *mActionLayerSaveAs;
     QAction *mActionLayerSelectionSaveAs;
     QAction *mActionRemoveLayer;
+    QAction *mActionSetLayerCRS;
     QAction *mActionTileScale;
     QAction *mActionGpsTool;
     QAction *mActionLayerProperties;
@@ -1013,6 +1020,7 @@
 #endif
 
     QAction *mActionHelpContents;
+    QAction *mActionHelpAPI;
     QAction *mActionHelpSeparator1;
     QAction *mActionQgisHomePage;
     QAction *mActionCheckQgisVersion;



More information about the QGIS-commit mailing list