Skip to content

Commit

Permalink
automatic otfr:
Browse files Browse the repository at this point in the history
* notify on message bar when CRS and OTFR kicks in (refs #9644)
* don't automatically change settings of loaded projects
  • Loading branch information
jef-n committed Mar 2, 2014
1 parent 5d6fc3d commit 3b4edb8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/app/legend/qgslegend.cpp
Expand Up @@ -34,6 +34,7 @@
#include "qgsgenericprojectionselector.h" #include "qgsgenericprojectionselector.h"
#include "qgsclipboard.h" #include "qgsclipboard.h"
#include "qgsmessagelog.h" #include "qgsmessagelog.h"
#include "qgsmessagebar.h"


#include <QFont> #include <QFont>
#include <QDomDocument> #include <QDomDocument>
Expand Down Expand Up @@ -83,6 +84,7 @@ QgsLegend::QgsLegend( QgsMapCanvas *canvas, QWidget * parent, const char *name )
, mChanging( false ) , mChanging( false )
, mUpdateDrawingOrder( true ) , mUpdateDrawingOrder( true )
, mGetLegendGraphicPopup( 0 ) , mGetLegendGraphicPopup( 0 )
, mLoadingLayers( false )
{ {
setObjectName( name ); setObjectName( name );


Expand All @@ -100,6 +102,8 @@ QgsLegend::QgsLegend( QgsMapCanvas *canvas, QWidget * parent, const char *name )
this, SLOT( readProject( const QDomDocument & ) ) ); this, SLOT( readProject( const QDomDocument & ) ) );
connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ), connect( QgsProject::instance(), SIGNAL( writeProject( QDomDocument & ) ),
this, SLOT( writeProject( QDomDocument & ) ) ); this, SLOT( writeProject( QDomDocument & ) ) );
connect( QgsProject::instance(), SIGNAL( layerLoaded( int, int ) ),
this, SLOT( layerLoaded( int, int ) ) );


// connect map layer registry signal to legend // connect map layer registry signal to legend
connect( QgsMapLayerRegistry::instance(), connect( QgsMapLayerRegistry::instance(),
Expand Down Expand Up @@ -1162,22 +1166,26 @@ void QgsLegend::addLayers( QList<QgsMapLayer *> theLayerList )
updateMapCanvasLayerSet(); updateMapCanvasLayerSet();
emit itemAdded( indexFromItem( llayer ) ); emit itemAdded( indexFromItem( llayer ) );
} }

// first layer? // first layer?
if ( myFirstLayerFlag ) if ( myFirstLayerFlag )
{ {
QgsMapLayer * myFirstLayer = theLayerList.at( 0 ); QgsMapLayer * myFirstLayer = theLayerList.at( 0 );
if ( !mMapCanvas->mapSettings().hasCrsTransformEnabled() ) if ( !mMapCanvas->mapSettings().hasCrsTransformEnabled() && !mLoadingLayers )
{ {
mMapCanvas->setDestinationCrs( myFirstLayer->crs() ); mMapCanvas->setDestinationCrs( myFirstLayer->crs() );
mMapCanvas->setMapUnits( myFirstLayer->crs().mapUnits() ); mMapCanvas->setMapUnits( myFirstLayer->crs().mapUnits() );

QgisApp::instance()->messageBar()->pushMessage( tr( "Destination CRS set to %1" ).arg( myFirstLayer->crs().authid() ), QgsMessageBar::INFO, QgisApp::instance()->messageTimeout() );
} }
mMapCanvas->zoomToFullExtent(); mMapCanvas->zoomToFullExtent();
mMapCanvas->clearExtentHistory(); mMapCanvas->clearExtentHistory();
} }
else else
{ {
if ( settings.value( "/Projections/otfTransformAutoEnable", true ).toBool() && if ( settings.value( "/Projections/otfTransformAutoEnable", true ).toBool() &&
!mMapCanvas->mapSettings().hasCrsTransformEnabled() ) !mMapCanvas->mapSettings().hasCrsTransformEnabled() &&
!mLoadingLayers )
{ {
// Verify if all layers have the same CRS // Verify if all layers have the same CRS
foreach ( QgsMapLayer *l, layers() ) foreach ( QgsMapLayer *l, layers() )
Expand All @@ -1187,6 +1195,8 @@ void QgsLegend::addLayers( QList<QgsMapLayer *> theLayerList )
// Set to the previous de facto used so that extent does not change // Set to the previous de facto used so that extent does not change
mMapCanvas->setDestinationCrs( myPreviousCrs ); mMapCanvas->setDestinationCrs( myPreviousCrs );
mMapCanvas->setCrsTransformEnabled( true ); mMapCanvas->setCrsTransformEnabled( true );

QgisApp::instance()->messageBar()->pushMessage( tr( "On the fly reprojection enabled." ), QgsMessageBar::INFO, QgisApp::instance()->messageTimeout() );
break; break;
} }
} }
Expand Down Expand Up @@ -3270,3 +3280,8 @@ QImage QgsLegend::getWmsLegendPixmap( QTreeWidgetItem *item )
return rasterLayer->dataProvider()->getLegendGraphic( canvas()->scale() ); return rasterLayer->dataProvider()->getLegendGraphic( canvas()->scale() );
} }



void QgsLegend::layerLoaded( int i, int n )
{
mLoadingLayers = i < n;
}
5 changes: 5 additions & 0 deletions src/app/legend/qgslegend.h
Expand Up @@ -386,6 +386,9 @@ class QgsLegend : public QTreeWidget
*/ */
void updateLegendItemSymbologies(); void updateLegendItemSymbologies();


/** Slot to catch if layers are being loaded */
void layerLoaded( int i, int n );

protected: protected:


/*!Event handler for mouse movements. /*!Event handler for mouse movements.
Expand Down Expand Up @@ -593,6 +596,8 @@ class QgsLegend : public QTreeWidget
//! popup QFrame containing WMS getLegendGraphic pixmap //! popup QFrame containing WMS getLegendGraphic pixmap
QFrame *mGetLegendGraphicPopup; QFrame *mGetLegendGraphicPopup;


bool mLoadingLayers;

signals: signals:
void itemAdded( QModelIndex index ); void itemAdded( QModelIndex index );
void itemMoved( QModelIndex oldIndex, QModelIndex newIndex ); void itemMoved( QModelIndex oldIndex, QModelIndex newIndex );
Expand Down

0 comments on commit 3b4edb8

Please sign in to comment.