Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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@13960 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mmassing committed Jul 25, 2010
1 parent 6cd0f0e commit 71deac5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 11 deletions.
59 changes: 48 additions & 11 deletions src/plugins/georeferencer/qgsgeorefplugingui.cpp
Expand Up @@ -84,6 +84,7 @@ QgsGeorefPluginGui::QgsGeorefPluginGui( QgisInterface* theQgisInterface, QWidget
, mTransformParam( QgsGeorefTransform::InvalidTransform )
, mIface( theQgisInterface )
, mLayer( 0 )
, mAgainAddRaster ( false )
, mMovingPoint( 0 )
, mMapCoordsDialog( 0 )
, mUseZeroForTrans( false )
Expand Down Expand Up @@ -249,17 +250,8 @@ void QgsGeorefPluginGui::openRaster()
if ( mLayer )
QgsMapLayerRegistry::instance()->removeMapLayer( mLayer->getLayerID(), false );

//add new raster layer
mLayer = new QgsRasterLayer( mRasterFileName, "Raster" );;

// 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 );
// Add raster
addRaster(mRasterFileName);

// load previously added points
mGCPpointsFileName = mRasterFileName + ".points";
Expand Down Expand Up @@ -748,6 +740,29 @@ void QgsGeorefPluginGui::updateMouseCoordinatePrecision()
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()
Expand Down Expand Up @@ -982,6 +997,28 @@ void QgsGeorefPluginGui::setupConnections()
// 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
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/georeferencer/qgsgeorefplugingui.h
Expand Up @@ -102,6 +102,10 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
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:
Expand All @@ -122,6 +126,9 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
void createStatusBar();
void setupConnections();

// Mapcanvas Plugin
void addRaster(QString file);

// settings
void readSettings();
void writeSettings();
Expand Down Expand Up @@ -207,6 +214,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
QgsGCPList mInitialPoints;
QgsMapCanvas *mCanvas;
QgsRasterLayer *mLayer;
bool mAgainAddRaster;

QgsMapTool *mToolZoomIn;
QgsMapTool *mToolZoomOut;
Expand Down

0 comments on commit 71deac5

Please sign in to comment.