@@ -84,6 +84,7 @@ QgsGeorefPluginGui::QgsGeorefPluginGui( QgisInterface* theQgisInterface, QWidget
84
84
, mTransformParam( QgsGeorefTransform::InvalidTransform )
85
85
, mIface( theQgisInterface )
86
86
, mLayer( 0 )
87
+ , mAgainAddRaster ( false )
87
88
, mMovingPoint( 0 )
88
89
, mMapCoordsDialog( 0 )
89
90
, mUseZeroForTrans( false )
@@ -249,17 +250,8 @@ void QgsGeorefPluginGui::openRaster()
249
250
if ( mLayer )
250
251
QgsMapLayerRegistry::instance ()->removeMapLayer ( mLayer ->getLayerID (), false );
251
252
252
- // add new raster layer
253
- mLayer = new QgsRasterLayer ( mRasterFileName , " Raster" );;
254
-
255
- // add to map layer registry, do not signal addition
256
- // so layer is not added to legend
257
- QgsMapLayerRegistry::instance ()->addMapLayer ( mLayer , false );
258
-
259
- // add layer to map canvas
260
- QList<QgsMapCanvasLayer> layers;
261
- layers.append ( QgsMapCanvasLayer ( mLayer ) );
262
- mCanvas ->setLayerSet ( layers );
253
+ // Add raster
254
+ addRaster (mRasterFileName );
263
255
264
256
// load previously added points
265
257
mGCPpointsFileName = mRasterFileName + " .points" ;
@@ -748,6 +740,29 @@ void QgsGeorefPluginGui::updateMouseCoordinatePrecision()
748
740
mMousePrecisionDecimalPlaces = dp;
749
741
}
750
742
743
+ void QgsGeorefPluginGui::extentsChanged ()
744
+ {
745
+ if ( mAgainAddRaster )
746
+ {
747
+ if ( QFile::exists ( mRasterFileName ) )
748
+ {
749
+ addRaster (mRasterFileName );
750
+ }
751
+ else
752
+ {
753
+ mLayer = 0 ;
754
+ mAgainAddRaster = false ;
755
+ }
756
+ }
757
+ }
758
+
759
+ // Registry layer QGis
760
+ void QgsGeorefPluginGui::layerWillBeRemoved ( QString theLayerId )
761
+ {
762
+ mAgainAddRaster = ( mLayer && mLayer ->getLayerID ().compare (theLayerId) == 0 )
763
+ ? true : false ;
764
+ }
765
+
751
766
// ------------------------------ private ---------------------------------- //
752
767
// Gui
753
768
void QgsGeorefPluginGui::createActions ()
@@ -982,6 +997,28 @@ void QgsGeorefPluginGui::setupConnections()
982
997
// Connect status from ZoomLast/ZoomNext to corresponding action
983
998
connect ( mCanvas , SIGNAL ( zoomLastStatusChanged ( bool ) ), mActionZoomLast , SLOT ( setEnabled ( bool ) ) );
984
999
connect ( mCanvas , SIGNAL ( zoomNextStatusChanged ( bool ) ), mActionZoomNext , SLOT ( setEnabled ( bool ) ) );
1000
+ // Connect when one Layer is removed - Case where change the Projetct in QGIS
1001
+ connect ( QgsMapLayerRegistry::instance () , SIGNAL ( layerWillBeRemoved (QString) ), this , SLOT ( layerWillBeRemoved (QString) ) );
1002
+
1003
+ // Connect extents changed - Use for need add again Raster
1004
+ connect ( mCanvas , SIGNAL ( extentsChanged () ), this , SLOT ( extentsChanged () ) );
1005
+
1006
+ }
1007
+
1008
+ // Mapcanvas Plugin
1009
+ void QgsGeorefPluginGui::addRaster (QString file)
1010
+ {
1011
+ mLayer = new QgsRasterLayer ( file, " Raster" );
1012
+
1013
+ // so layer is not added to legend
1014
+ QgsMapLayerRegistry::instance ()->addMapLayer ( mLayer , false );
1015
+
1016
+ // add layer to map canvas
1017
+ QList<QgsMapCanvasLayer> layers;
1018
+ layers.append ( QgsMapCanvasLayer ( mLayer ) );
1019
+ mCanvas ->setLayerSet ( layers );
1020
+
1021
+ mAgainAddRaster = false ;
985
1022
}
986
1023
987
1024
// Settings
0 commit comments