Skip to content
Permalink
Browse files
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
  • Loading branch information
mmassing committed Jul 25, 2010
1 parent 3af41b1 commit 0a104436074a56890f55830ae43bbf2a9eee53c6
Showing with 56 additions and 11 deletions.
  1. +48 −11 src/plugins/georeferencer/qgsgeorefplugingui.cpp
  2. +8 −0 src/plugins/georeferencer/qgsgeorefplugingui.h
@@ -84,6 +84,7 @@ QgsGeorefPluginGui::QgsGeorefPluginGui( QgisInterface* theQgisInterface, QWidget
, mTransformParam( QgsGeorefTransform::InvalidTransform )
, mIface( theQgisInterface )
, mLayer( 0 )
, mAgainAddRaster ( false )
, mMovingPoint( 0 )
, mMapCoordsDialog( 0 )
, mUseZeroForTrans( false )
@@ -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";
@@ -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()
@@ -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
@@ -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:
@@ -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();
@@ -207,6 +214,7 @@ class QgsGeorefPluginGui : public QMainWindow, private Ui::QgsGeorefPluginGuiBas
QgsGCPList mInitialPoints;
QgsMapCanvas *mCanvas;
QgsRasterLayer *mLayer;
bool mAgainAddRaster;

QgsMapTool *mToolZoomIn;
QgsMapTool *mToolZoomOut;

0 comments on commit 0a10443

Please sign in to comment.