Skip to content

Commit 0a10443

Browse files
author
mmassing
committed
Patch by Luiz Motta: re-add georeferenced raster to qgis layers after project reload (partial commit of #2890). Thanks.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13960 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 3af41b1 commit 0a10443

File tree

2 files changed

+56
-11
lines changed

2 files changed

+56
-11
lines changed

src/plugins/georeferencer/qgsgeorefplugingui.cpp

+48-11
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ QgsGeorefPluginGui::QgsGeorefPluginGui( QgisInterface* theQgisInterface, QWidget
8484
, mTransformParam( QgsGeorefTransform::InvalidTransform )
8585
, mIface( theQgisInterface )
8686
, mLayer( 0 )
87+
, mAgainAddRaster ( false )
8788
, mMovingPoint( 0 )
8889
, mMapCoordsDialog( 0 )
8990
, mUseZeroForTrans( false )
@@ -249,17 +250,8 @@ void QgsGeorefPluginGui::openRaster()
249250
if ( mLayer )
250251
QgsMapLayerRegistry::instance()->removeMapLayer( mLayer->getLayerID(), false );
251252

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);
263255

264256
// load previously added points
265257
mGCPpointsFileName = mRasterFileName + ".points";
@@ -748,6 +740,29 @@ void QgsGeorefPluginGui::updateMouseCoordinatePrecision()
748740
mMousePrecisionDecimalPlaces = dp;
749741
}
750742

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+
751766
// ------------------------------ private ---------------------------------- //
752767
// Gui
753768
void QgsGeorefPluginGui::createActions()
@@ -982,6 +997,28 @@ void QgsGeorefPluginGui::setupConnections()
982997
// Connect status from ZoomLast/ZoomNext to corresponding action
983998
connect( mCanvas, SIGNAL( zoomLastStatusChanged( bool ) ), mActionZoomLast, SLOT( setEnabled( bool ) ) );
984999
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;
9851022
}
9861023

9871024
// Settings

src/plugins/georeferencer/qgsgeorefplugingui.h

+8
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
102102
void showMouseCoords( const QgsPoint pt );
103103
void updateMouseCoordinatePrecision();
104104

105+
// when one Layer is removed
106+
void layerWillBeRemoved ( QString theLayerId );
107+
void extentsChanged(); // Use for need add again Raster (case above)
108+
105109
bool updateGeorefTransform();
106110

107111
private:
@@ -122,6 +126,9 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
122126
void createStatusBar();
123127
void setupConnections();
124128

129+
// Mapcanvas Plugin
130+
void addRaster(QString file);
131+
125132
// settings
126133
void readSettings();
127134
void writeSettings();
@@ -207,6 +214,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
207214
QgsGCPList mInitialPoints;
208215
QgsMapCanvas *mCanvas;
209216
QgsRasterLayer *mLayer;
217+
bool mAgainAddRaster;
210218

211219
QgsMapTool *mToolZoomIn;
212220
QgsMapTool *mToolZoomOut;

0 commit comments

Comments
 (0)