[QGIS Commit] r13960 - trunk/qgis/src/plugins/georeferencer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Jul 25 11:20:06 EDT 2010


Author: mmassing
Date: 2010-07-25 15:20:06 +0000 (Sun, 25 Jul 2010)
New Revision: 13960

Modified:
   trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp
   trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.h
Log:
Patch by Luiz Motta: re-add georeferenced raster to qgis layers after project reload (partial commit of #2890). Thanks.

Modified: trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp	2010-07-25 15:20:01 UTC (rev 13959)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.cpp	2010-07-25 15:20:06 UTC (rev 13960)
@@ -84,6 +84,7 @@
     , mTransformParam( QgsGeorefTransform::InvalidTransform )
     , mIface( theQgisInterface )
     , mLayer( 0 )
+    , mAgainAddRaster ( false )
     , mMovingPoint( 0 )
     , mMapCoordsDialog( 0 )
     , mUseZeroForTrans( false )
@@ -249,18 +250,9 @@
   if ( mLayer )
     QgsMapLayerRegistry::instance()->removeMapLayer( mLayer->getLayerID(), false );
 
-  //add new raster layer
-  mLayer = new QgsRasterLayer( mRasterFileName, "Raster" );;
+  // Add raster
+  addRaster(mRasterFileName);
 
-  // add to map layer registry, do not signal addition
-  // so layer is not added to legend
-  QgsMapLayerRegistry::instance()->addMapLayer( mLayer, false );
-
-  // add layer to map canvas
-  QList<QgsMapCanvasLayer> layers;
-  layers.append( QgsMapCanvasLayer( mLayer ) );
-  mCanvas->setLayerSet( layers );
-
   // load previously added points
   mGCPpointsFileName = mRasterFileName + ".points";
   loadGCPs();
@@ -748,6 +740,29 @@
   mMousePrecisionDecimalPlaces = dp;
 }
 
+void QgsGeorefPluginGui::extentsChanged()
+{
+  if ( mAgainAddRaster )
+  {
+    if ( QFile::exists( mRasterFileName ) )
+    {
+      addRaster(mRasterFileName);
+    }
+    else
+    {
+      mLayer = 0;
+      mAgainAddRaster = false;
+    }
+  }
+}
+
+// Registry layer QGis
+void QgsGeorefPluginGui::layerWillBeRemoved ( QString theLayerId )
+{
+  mAgainAddRaster = ( mLayer  && mLayer->getLayerID().compare(theLayerId) == 0 )
+                  ? true : false;
+}
+
 // ------------------------------ private ---------------------------------- //
 // Gui
 void QgsGeorefPluginGui::createActions()
@@ -982,8 +997,30 @@
   // Connect status from ZoomLast/ZoomNext to corresponding action
   connect( mCanvas, SIGNAL( zoomLastStatusChanged( bool ) ), mActionZoomLast, SLOT( setEnabled( bool ) ) );
   connect( mCanvas, SIGNAL( zoomNextStatusChanged( bool ) ), mActionZoomNext, SLOT( setEnabled( bool ) ) );
+  // Connect when one Layer is removed - Case where change the Projetct in QGIS
+  connect( QgsMapLayerRegistry::instance() , SIGNAL( layerWillBeRemoved (QString) ), this, SLOT( layerWillBeRemoved (QString) ) );
+
+  // Connect extents changed - Use for need add again Raster
+  connect( mCanvas, SIGNAL( extentsChanged () ), this, SLOT( extentsChanged() ) );
+
 }
 
+// Mapcanvas Plugin
+void QgsGeorefPluginGui::addRaster(QString file)
+{
+  mLayer = new QgsRasterLayer( file, "Raster" );
+
+  // so layer is not added to legend
+  QgsMapLayerRegistry::instance()->addMapLayer( mLayer, false );
+
+  // add layer to map canvas
+  QList<QgsMapCanvasLayer> layers;
+  layers.append( QgsMapCanvasLayer( mLayer ) );
+  mCanvas->setLayerSet( layers );
+
+  mAgainAddRaster = false;
+}
+
 // Settings
 void QgsGeorefPluginGui::readSettings()
 {

Modified: trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.h
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.h	2010-07-25 15:20:01 UTC (rev 13959)
+++ trunk/qgis/src/plugins/georeferencer/qgsgeorefplugingui.h	2010-07-25 15:20:06 UTC (rev 13960)
@@ -102,6 +102,10 @@
     void showMouseCoords( const QgsPoint pt );
     void updateMouseCoordinatePrecision();
 
+    // when one Layer is removed
+    void layerWillBeRemoved ( QString theLayerId );
+    void extentsChanged(); // Use for need add again Raster (case above)
+
     bool updateGeorefTransform();
 
   private:
@@ -122,6 +126,9 @@
     void createStatusBar();
     void setupConnections();
 
+    // Mapcanvas Plugin
+    void addRaster(QString file);
+
     // settings
     void readSettings();
     void writeSettings();
@@ -207,6 +214,7 @@
     QgsGCPList mInitialPoints;
     QgsMapCanvas *mCanvas;
     QgsRasterLayer *mLayer;
+    bool mAgainAddRaster;
 
     QgsMapTool *mToolZoomIn;
     QgsMapTool *mToolZoomOut;



More information about the QGIS-commit mailing list