Skip to content

Commit f91642f

Browse files
author
jef
committed
[FEATURE] allow setting CRS for multiple layers at once
git-svn-id: http://svn.osgeo.org/qgis/trunk@15352 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e332633 commit f91642f

File tree

6 files changed

+185
-30
lines changed

6 files changed

+185
-30
lines changed
1.08 KB
Loading

src/app/legend/qgslegend.cpp

+99-23
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "qgsproject.h"
3434
#include "qgsrasterlayer.h"
3535
#include "qgsvectorlayer.h"
36-
#include "qgsprojectbadlayerguihandler.h"
36+
#include "qgsgenericprojectionselector.h"
3737

3838
#include <QFont>
3939
#include <QDomDocument>
@@ -525,16 +525,16 @@ void QgsLegend::mouseDoubleClickEvent( QMouseEvent* e )
525525
{
526526
QSettings settings;
527527

528-
switch( settings.value( "/qgis/legendDoubleClickAction", 0 ).toInt() )
528+
switch ( settings.value( "/qgis/legendDoubleClickAction", 0 ).toInt() )
529529
{
530-
case 0:
531-
QgisApp::instance()->layerProperties();
532-
break;
533-
case 1:
534-
QgisApp::instance()->attributeTable();
535-
break;
536-
default:
537-
break;
530+
case 0:
531+
QgisApp::instance()->layerProperties();
532+
break;
533+
case 1:
534+
QgisApp::instance()->attributeTable();
535+
break;
536+
default:
537+
break;
538538
}
539539
}
540540

@@ -558,7 +558,6 @@ void QgsLegend::handleRightClickEvent( QTreeWidgetItem* item, const QPoint& posi
558558
{
559559
theMenu.addAction( tr( "&Make to toplevel item" ), this, SLOT( makeToTopLevelItem() ) );
560560
}
561-
562561
}
563562
else if ( li->type() == QgsLegendItem::LEGEND_GROUP )
564563
{
@@ -567,6 +566,9 @@ void QgsLegend::handleRightClickEvent( QTreeWidgetItem* item, const QPoint& posi
567566

568567
theMenu.addAction( QgisApp::getThemeIcon( "/mActionRemoveLayer.png" ),
569568
tr( "&Remove" ), this, SLOT( legendGroupRemove() ) );
569+
570+
theMenu.addAction( QgisApp::getThemeIcon( "/mActionSetCRS.png" ),
571+
tr( "&Set group CRS" ), this, SLOT( legendGroupSetCRS() ) );
570572
}
571573

572574
if ( li->type() == QgsLegendItem::LEGEND_LAYER || li->type() == QgsLegendItem::LEGEND_GROUP )
@@ -739,6 +741,30 @@ void QgsLegend::legendGroupRemove()
739741
}
740742
}
741743

744+
void QgsLegend::legendGroupSetCRS()
745+
{
746+
if ( !mMapCanvas || mMapCanvas->isDrawing() )
747+
{
748+
return;
749+
}
750+
751+
QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector( this );
752+
mySelector->setMessage();
753+
if ( mySelector->exec() )
754+
{
755+
QgsCoordinateReferenceSystem crs( mySelector->selectedCrsId(), QgsCoordinateReferenceSystem::InternalCrsId );
756+
757+
QgsLegendGroup* lg = dynamic_cast<QgsLegendGroup *>( currentItem() );
758+
setGroupCRS( lg, crs );
759+
}
760+
else
761+
{
762+
QApplication::restoreOverrideCursor();
763+
}
764+
765+
delete mySelector;
766+
}
767+
742768
void QgsLegend::removeGroup( QgsLegendGroup *lg )
743769
{
744770
if ( !mMapCanvas || mMapCanvas->isDrawing() )
@@ -766,6 +792,36 @@ void QgsLegend::removeGroup( QgsLegendGroup *lg )
766792
adjustIconSize();
767793
}
768794

795+
void QgsLegend::setGroupCRS( QgsLegendGroup *lg, const QgsCoordinateReferenceSystem &crs )
796+
{
797+
if ( !mMapCanvas || mMapCanvas->isDrawing() )
798+
{
799+
return;
800+
}
801+
802+
//delete the legend layers first
803+
QTreeWidgetItem * child = lg->child( 0 );
804+
while ( child )
805+
{
806+
QgsLegendLayer *cl = dynamic_cast<QgsLegendLayer *>( child );
807+
QgsLegendGroup *cg = dynamic_cast<QgsLegendGroup *>( child );
808+
809+
if ( cl )
810+
{
811+
cl->layer()->setCrs( crs );
812+
}
813+
else if ( cg )
814+
{
815+
setGroupCRS( cg, crs );
816+
}
817+
818+
child = lg->child( 0 );
819+
}
820+
821+
delete lg;
822+
}
823+
824+
769825
void QgsLegend::moveLayer( QgsMapLayer *ml, int groupIndex )
770826
{
771827
if ( !ml )
@@ -999,20 +1055,11 @@ bool QgsLegend::readXML( QgsLegendGroup *parent, const QDomNode &node )
9991055
{
10001056
bool isOpen;
10011057
QgsLegendLayer* currentLayer = readLayerFromXML( childelem, isOpen );
1002-
1003-
bool ignorePressed = QgsProjectBadLayerGuiHandler::mIgnore;
1004-
10051058
if ( !currentLayer )
1006-
{
1007-
if( ignorePressed == true )
1008-
{
1009-
continue;
1010-
}
1011-
else
1012-
{
1013-
return false;
1014-
}
1059+
{
1060+
continue;
10151061
}
1062+
10161063
// add to tree - either as a top-level node or a child of a group
10171064
if ( parent )
10181065
{
@@ -1920,3 +1967,32 @@ void QgsLegend::removeSelectedLayers()
19201967
if ( renderFlagState )
19211968
mMapCanvas->setRenderFlag( true );
19221969
}
1970+
1971+
void QgsLegend::setCRSForSelectedLayers( const QgsCoordinateReferenceSystem &crs )
1972+
{
1973+
// Turn off rendering to improve speed.
1974+
bool renderFlagState = mMapCanvas->renderFlag();
1975+
if ( renderFlagState )
1976+
mMapCanvas->setRenderFlag( false );
1977+
1978+
foreach( QTreeWidgetItem * item, selectedItems() )
1979+
{
1980+
QgsLegendGroup* lg = dynamic_cast<QgsLegendGroup *>( item );
1981+
if ( lg )
1982+
{
1983+
setGroupCRS( lg, crs );
1984+
continue;
1985+
}
1986+
1987+
QgsLegendLayer *ll = dynamic_cast<QgsLegendLayer *>( item );
1988+
if ( ll && ll->layer() )
1989+
{
1990+
ll->layer()->setCrs( crs );
1991+
continue;
1992+
}
1993+
}
1994+
1995+
// Turn on rendering (if it was on previously)
1996+
if ( renderFlagState )
1997+
mMapCanvas->setRenderFlag( true );
1998+
}

src/app/legend/qgslegend.h

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class QDomElement;
3434
class QDomNode;
3535
class QMouseEvent;
3636
class QTreeWidgetItem;
37+
class QgsCoordinateReferenceSystem;
3738

3839
//Information about relationship between groups and layers
3940
//key: group name (or null strings for single layers without groups)
@@ -266,6 +267,9 @@ class QgsLegend : public QTreeWidget
266267
/** Remove selected layers */
267268
void removeSelectedLayers();
268269

270+
/** Set CRS for selected layers */
271+
void setCRSForSelectedLayers( const QgsCoordinateReferenceSystem &crs );
272+
269273
protected:
270274

271275
/*!Event handler for mouse movements.
@@ -362,8 +366,12 @@ class QgsLegend : public QTreeWidget
362366
void handleRightClickEvent( QTreeWidgetItem* item, const QPoint& position );
363367
/**Removes the current legend group*/
364368
void legendGroupRemove();
369+
/**Set the CRS of the current legend group*/
370+
void legendGroupSetCRS();
365371
/**Removes a legend group and its layers*/
366372
void removeGroup( QgsLegendGroup * lg );
373+
/**Removes a legend group and its layers*/
374+
void setGroupCRS( QgsLegendGroup * lg, const QgsCoordinateReferenceSystem &crs );
367375
/**Sets all listview items to open*/
368376
void expandAll();
369377
/**Sets all listview items to closed*/

src/app/legend/qgslegendlayer.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ void QgsLegendLayer::addToPopupMenu( QMenu& theMenu )
432432
// remove from canvas
433433
theMenu.addAction( QgisApp::getThemeIcon( "/mActionRemoveLayer.png" ), tr( "&Remove" ), QgisApp::instance(), SLOT( removeLayer() ) );
434434

435+
// remove from canvas
436+
theMenu.addAction( QgisApp::getThemeIcon( "/mActionSetCRS.png" ), tr( "&Set layer CRS" ), QgisApp::instance(), SLOT( setLayerCRS() ) );
437+
435438
theMenu.addSeparator();
436439

437440
if ( lyr->type() == QgsMapLayer::VectorLayer )

0 commit comments

Comments
 (0)