[FEATURE] allow setting CRS for multiple layers at once

git-svn-id: http://svn.osgeo.org/qgis/trunk@15352 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
jef 2011-03-06 02:18:18 +00:00
parent e332633cd4
commit f91642fc47
6 changed files with 185 additions and 30 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -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 @@ void QgsLegend::mouseDoubleClickEvent( QMouseEvent* e )
{
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 @@ void QgsLegend::handleRightClickEvent( QTreeWidgetItem* item, const QPoint& posi
{
theMenu.addAction( tr( "&Make to toplevel item" ), this, SLOT( makeToTopLevelItem() ) );
}
}
else if ( li->type() == QgsLegendItem::LEGEND_GROUP )
{
@ -567,6 +566,9 @@ void QgsLegend::handleRightClickEvent( QTreeWidgetItem* item, const QPoint& posi
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::legendGroupRemove()
}
}
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 @@ void QgsLegend::removeGroup( QgsLegendGroup *lg )
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 QgsLegend::readXML( QgsLegendGroup *parent, const QDomNode &node )
{
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 @@ void QgsLegend::removeSelectedLayers()
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 );
}

View File

@ -34,6 +34,7 @@ class QDomElement;
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 @@ class QgsLegend : public QTreeWidget
/** 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 @@ class QgsLegend : public QTreeWidget
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*/

View File

@ -432,6 +432,9 @@ void QgsLegendLayer::addToPopupMenu( QMenu& theMenu )
// 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 )

View File

@ -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 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
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 @@ void QgisApp::createActions()
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,6 +1255,14 @@ void QgisApp::createActions()
#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
@ -1609,6 +1623,7 @@ void QgisApp::createMenus()
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 @@ void QgisApp::createMenus()
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 @@ void QgisApp::createToolBars()
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 @@ void QgisApp::createToolBars()
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 @@ void QgisApp::setTheme( QString theThemeName )
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 @@ void QgisApp::setTheme( QString theThemeName )
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 @@ void QgisApp::saveAsVectorFileGeneral( bool saveOnlySelection )
}
else
{
destCRS = vlayer->srs();
destCRS = vlayer->crs();
}
}
else
@ -4812,7 +4838,7 @@ void QgisApp::editCut( QgsMapLayer * layerContainingSelection )
{
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 @@ void QgisApp::editCopy( QgsMapLayer * layerContainingSelection )
{
QgsFeatureList features = selectionVectorLayer->selectedFeatures();
clipboard()->replaceWithCopyOf( selectionVectorLayer->pendingFields(), features );
clipboard()->setCRS( selectionVectorLayer->srs() );
clipboard()->setCRS( selectionVectorLayer->crs() );
}
}
}
@ -4865,7 +4891,7 @@ void QgisApp::editPaste( QgsMapLayer *destinationLayer )
QgsFeatureList features;
if ( mMapCanvas->mapRenderer()->hasCrsTransformEnabled() )
{
features = clipboard()->transformedCopyOf( pasteVectorLayer->srs() );
features = clipboard()->transformedCopyOf( pasteVectorLayer->crs() );
}
else
{
@ -5233,6 +5259,34 @@ void QgisApp::removeLayer()
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 @@ void QgisApp::options()
myRenderer->setProjectionsEnabled( false );
}
mMapCanvas->refresh();
}
}
delete optionsDialog;
}
@ -5602,6 +5656,11 @@ void QgisApp::helpContents()
openURL( "index.html" );
}
void QgisApp::apiDocumentation()
{
openURL( "api/index.html" );
}
void QgisApp::helpQgisHomePage()
{
openURL( "http://qgis.org", false );
@ -6283,6 +6342,7 @@ void QgisApp::selectionChanged( QgsMapLayer *layer )
void QgisApp::legendLayerSelectionChanged( void )
{
mActionRemoveLayer->setEnabled( mMapLegend && mMapLegend->selectedLayers().size() > 0 );
mActionSetLayerCRS->setEnabled( mMapLegend && mMapLegend->selectedLayers().size() > 0 );
}
void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )

View File

@ -287,6 +287,7 @@ class QgisApp : public QMainWindow
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 @@ class QgisApp : public QMainWindow
#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 @@ class QgisApp : public QMainWindow
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 @@ class QgisApp : public QMainWindow
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 @@ class QgisApp : public QMainWindow
QAction *mActionLayerSaveAs;
QAction *mActionLayerSelectionSaveAs;
QAction *mActionRemoveLayer;
QAction *mActionSetLayerCRS;
QAction *mActionTileScale;
QAction *mActionGpsTool;
QAction *mActionLayerProperties;
@ -1013,6 +1020,7 @@ class QgisApp : public QMainWindow
#endif
QAction *mActionHelpContents;
QAction *mActionHelpAPI;
QAction *mActionHelpSeparator1;
QAction *mActionQgisHomePage;
QAction *mActionCheckQgisVersion;