[BACKPORT] to 1.8. Remove deprecated use of map layer registry addLayer and removeLayer elsewhere in code base

This commit is contained in:
Tim Sutton 2012-04-05 00:42:08 +02:00
parent 8d4a656e4d
commit d830d537a6
15 changed files with 64 additions and 29 deletions

View File

@ -1172,7 +1172,8 @@ void QgsLegend::removeGroup( QgsLegendGroup *lg )
QgsLegendGroup *cg = dynamic_cast<QgsLegendGroup *>( child ); QgsLegendGroup *cg = dynamic_cast<QgsLegendGroup *>( child );
if ( cl ) if ( cl )
QgsMapLayerRegistry::instance()->removeMapLayer( cl->layer()->id() ); QgsMapLayerRegistry::instance()->removeMapLayers(
QStringList() << cl->layer()->id() );
else if ( cg ) else if ( cg )
removeGroup( cg ); removeGroup( cg );
@ -2420,7 +2421,8 @@ void QgsLegend::removeSelectedLayers()
QgsLegendLayer *ll = dynamic_cast<QgsLegendLayer *>( item ); QgsLegendLayer *ll = dynamic_cast<QgsLegendLayer *>( item );
if ( ll && ll->layer() ) if ( ll && ll->layer() )
{ {
QgsMapLayerRegistry::instance()->removeMapLayer( ll->layer()->id() ); QgsMapLayerRegistry::instance()->removeMapLayers(
QStringList() << ll->layer()->id() );
continue; continue;
} }
} }

View File

@ -429,7 +429,11 @@ bool QgsNewSpatialiteLayerDialog::apply()
if ( layer->isValid() ) if ( layer->isValid() )
{ {
// register this layer with the central layers registry // register this layer with the central layers registry
if ( QgsMapLayerRegistry::instance()->addMapLayer( layer ) ) QList<QgsMapLayer *> myList;
myList << layer;
//addMapLayers returns a list of all successfully added layers
//so we compare that to our original list.
if ( myList == QgsMapLayerRegistry::instance()->addMapLayers( myList ) )
return true; return true;
} }
else else

View File

@ -245,7 +245,8 @@ bool QgsBrowser::layerClicked( QgsLayerItem *item )
QgsDebugMsg( "Layer created" ); QgsDebugMsg( "Layer created" );
QgsMapLayerRegistry::instance()->addMapLayer( mLayer ); QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mLayer );
return true; return true;
} }

View File

@ -100,7 +100,8 @@ bool QgsPluginLayerRegistry::removePluginLayerType( QString typeName )
QgsPluginLayer* pl = qobject_cast<QgsPluginLayer*>( layer ); QgsPluginLayer* pl = qobject_cast<QgsPluginLayer*>( layer );
if ( pl->pluginLayerType() == typeName ) if ( pl->pluginLayerType() == typeName )
{ {
QgsMapLayerRegistry::instance()->removeMapLayer( layer->id() ); QgsMapLayerRegistry::instance()->removeMapLayers(
QStringList() << layer->id() );
} }
} }
} }

View File

@ -1427,7 +1427,8 @@ QStringList QgsWMSServer::layerSet( const QStringList &layersList,
if ( theMapLayer ) if ( theMapLayer )
{ {
layerKeys.push_front( theMapLayer->id() ); layerKeys.push_front( theMapLayer->id() );
QgsMapLayerRegistry::instance()->addMapLayer( theMapLayer, false ); QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << theMapLayer, false );
} }
else else
{ {

View File

@ -146,7 +146,8 @@ QgsGeorefPluginGui::~QgsGeorefPluginGui()
// delete layer (and don't signal it as it's our private layer) // delete layer (and don't signal it as it's our private layer)
if ( mLayer ) if ( mLayer )
{ {
QgsMapLayerRegistry::instance()->removeMapLayer( mLayer->id(), false ); QgsMapLayerRegistry::instance()->removeMapLayers(
(QStringList() << mLayer->id()), false );
} }
delete mToolZoomIn; delete mToolZoomIn;
@ -251,7 +252,8 @@ void QgsGeorefPluginGui::openRaster()
//delete any old rasterlayers //delete any old rasterlayers
if ( mLayer ) if ( mLayer )
QgsMapLayerRegistry::instance()->removeMapLayer( mLayer->id(), false ); QgsMapLayerRegistry::instance()->removeMapLayers(
QStringList() << mLayer->id(), false );
// Add raster // Add raster
addRaster( mRasterFileName ); addRaster( mRasterFileName );
@ -1039,7 +1041,8 @@ void QgsGeorefPluginGui::addRaster( QString file )
mLayer = new QgsRasterLayer( file, "Raster" ); mLayer = new QgsRasterLayer( file, "Raster" );
// so layer is not added to legend // so layer is not added to legend
QgsMapLayerRegistry::instance()->addMapLayer( mLayer, false ); QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mLayer, false );
// add layer to map canvas // add layer to map canvas
QList<QgsMapCanvasLayer> layers; QList<QgsMapCanvasLayer> layers;

View File

@ -182,7 +182,8 @@ void QgsOfflineEditing::synchronize( QgsLegendInterface* legendInterface )
copySymbology( offlineLayer, remoteLayer ); copySymbology( offlineLayer, remoteLayer );
// register this layer with the central layers registry // register this layer with the central layers registry
QgsMapLayerRegistry::instance()->addMapLayer( remoteLayer, true ); QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << remoteLayer, true );
// apply layer edit log // apply layer edit log
QString qgisLayerId = layer->id(); QString qgisLayerId = layer->id();
@ -233,7 +234,8 @@ void QgsOfflineEditing::synchronize( QgsLegendInterface* legendInterface )
} }
// remove offline layer // remove offline layer
QgsMapLayerRegistry::instance()->removeMapLayer( qgisLayerId, true ); QgsMapLayerRegistry::instance()->removeMapLayers(
(QStringList() << qgisLayerId), true );
// disable offline project // disable offline project
QString projectTitle = QgsProject::instance()->title(); QString projectTitle = QgsProject::instance()->title();
@ -495,7 +497,8 @@ void QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlite3* db, con
} }
// register this layer with the central layers registry // register this layer with the central layers registry
QgsMapLayerRegistry::instance()->addMapLayer( newLayer ); QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << newLayer );
if ( hasLabels ) if ( hasLabels )
{ {
@ -567,7 +570,8 @@ void QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlite3* db, con
} }
// remove remote layer // remove remote layer
QgsMapLayerRegistry::instance()->removeMapLayer( layer->id() ); QgsMapLayerRegistry::instance()->removeMapLayers(
QStringList() << layer->id() );
} }
} }
} }

View File

@ -85,7 +85,9 @@ QgsVectorLayer* RgExportDlg::mapLayer() const
QList<QgsField> attrList; QList<QgsField> attrList;
attrList.append( QgsField( "one", QVariant::Int ) ); attrList.append( QgsField( "one", QVariant::Int ) );
prov->addAttributes( attrList ); prov->addAttributes( attrList );
QgsMapLayerRegistry::instance()->addMapLayer( myLayer ); QList<QgsMapLayer *> myList;
myList << myLayer;
QgsMapLayerRegistry::instance()->addMapLayers( myList );
} }
else else

View File

@ -298,7 +298,8 @@ bool QgsSpatialQueryDialog::addLayerSubset( QString name, QString subset )
delete addLyr; delete addLyr;
return false; return false;
} }
QgsMapLayerRegistry::instance()->addMapLayer( addLyr ); QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << addLyr );
return true; return true;
} // bool QgsSpatialQueryDialog::addLayerSubset( QString name, QString subset ) } // bool QgsSpatialQueryDialog::addLayerSubset( QString name, QString subset )

View File

@ -152,7 +152,9 @@ void SqlAnywhere::addSqlAnywhereLayer()
SaDebugMsg( "Beautifying layer name. new: " + layer->name() ); SaDebugMsg( "Beautifying layer name. new: " + layer->name() );
// register this layer with the central layers registry // register this layer with the central layers registry
QgsMapLayerRegistry::instance()->addMapLayer(( QgsVectorLayer* )layer ); QList<QgsMapLayer *> myList;
myList << ( QgsVectorLayer* )layer;
QgsMapLayerRegistry::instance()->addMapLayers( myList );
} }
else else
{ {

View File

@ -75,7 +75,9 @@ void Regression992::initTestCase()
mpRasterLayer = new QgsRasterLayer( myRasterFileInfo.filePath(), mpRasterLayer = new QgsRasterLayer( myRasterFileInfo.filePath(),
myRasterFileInfo.completeBaseName() ); myRasterFileInfo.completeBaseName() );
// Register the layer with the registry // Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer( mpRasterLayer ); QList<QgsMapLayer *> myList;
myList << mpRasterLayer;
QgsMapLayerRegistry::instance()->addMapLayers( myList );
// add the test layer to the maprender // add the test layer to the maprender
mpMapRenderer = new QgsMapRenderer(); mpMapRenderer = new QgsMapRenderer();
QStringList myLayers; QStringList myLayers;

View File

@ -166,7 +166,8 @@ void TestQgsMapRenderer::initTestCase()
mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(), mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(),
myPolyFileInfo.completeBaseName(), "ogr" ); myPolyFileInfo.completeBaseName(), "ogr" );
// Register the layer with the registry // Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer( mpPolysLayer ); QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPolysLayer );
// add the test layer to the maprender // add the test layer to the maprender
mpMapRenderer = new QgsMapRenderer(); mpMapRenderer = new QgsMapRenderer();
QStringList myLayers; QStringList myLayers;

View File

@ -90,8 +90,10 @@ void TestQgsRasterLayer::initTestCase()
mpLandsatRasterLayer = new QgsRasterLayer( myLandsatRasterFileInfo.filePath(), mpLandsatRasterLayer = new QgsRasterLayer( myLandsatRasterFileInfo.filePath(),
myLandsatRasterFileInfo.completeBaseName() ); myLandsatRasterFileInfo.completeBaseName() );
// Register the layer with the registry // Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer( mpRasterLayer ); QgsMapLayerRegistry::instance()->addMapLayers(
QgsMapLayerRegistry::instance()->addMapLayer( mpLandsatRasterLayer ); QList<QgsMapLayer *>() << mpRasterLayer );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpLandsatRasterLayer );
// add the test layer to the maprender // add the test layer to the maprender
mpMapRenderer = new QgsMapRenderer(); mpMapRenderer = new QgsMapRenderer();
QStringList myLayers; QStringList myLayers;
@ -237,8 +239,10 @@ void TestQgsRasterLayer::registry()
QgsRasterLayer * mypLayer = new QgsRasterLayer( myRasterFileInfo.filePath(), QgsRasterLayer * mypLayer = new QgsRasterLayer( myRasterFileInfo.filePath(),
myRasterFileInfo.completeBaseName() ); myRasterFileInfo.completeBaseName() );
QgsMapLayerRegistry::instance()->addMapLayer( mypLayer, false ); QgsMapLayerRegistry::instance()->addMapLayers(
QgsMapLayerRegistry::instance()->removeMapLayer( mypLayer->id() ); QList<QgsMapLayer *>() << mypLayer, false );
QgsMapLayerRegistry::instance()->removeMapLayers(
QStringList() << mypLayer->id() );
//cleanup //cleanup
//delete mypLayer; //delete mypLayer;
} }

View File

@ -90,7 +90,8 @@ void TestQgsRenderers::initTestCase()
mpPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(), mpPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(),
myPointFileInfo.completeBaseName(), "ogr" ); myPointFileInfo.completeBaseName(), "ogr" );
// Register the layer with the registry // Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer( mpPointsLayer ); QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPointsLayer );
// //
//create a poly layer that will be used in all tests... //create a poly layer that will be used in all tests...
@ -100,7 +101,8 @@ void TestQgsRenderers::initTestCase()
mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(), mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(),
myPolyFileInfo.completeBaseName(), "ogr" ); myPolyFileInfo.completeBaseName(), "ogr" );
// Register the layer with the registry // Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer( mpPolysLayer ); QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPolysLayer );
// //
@ -111,7 +113,8 @@ void TestQgsRenderers::initTestCase()
mpLinesLayer = new QgsVectorLayer( myLineFileInfo.filePath(), mpLinesLayer = new QgsVectorLayer( myLineFileInfo.filePath(),
myLineFileInfo.completeBaseName(), "ogr" ); myLineFileInfo.completeBaseName(), "ogr" );
// Register the layer with the registry // Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer( mpLinesLayer ); QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpLinesLayer );
// //
// We only need maprender instead of mapcanvas // We only need maprender instead of mapcanvas
// since maprender does not require a qui // since maprender does not require a qui

View File

@ -81,7 +81,8 @@ class TestQgsVectorLayer: public QObject
mpNonSpatialLayer = new QgsVectorLayer( myDbfFileInfo.filePath(), mpNonSpatialLayer = new QgsVectorLayer( myDbfFileInfo.filePath(),
myDbfFileInfo.completeBaseName(), "ogr" ); myDbfFileInfo.completeBaseName(), "ogr" );
// Register the layer with the registry // Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer( mpNonSpatialLayer ); QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpNonSpatialLayer );
// //
//create a point layer that will be used in all tests... //create a point layer that will be used in all tests...
// //
@ -90,7 +91,8 @@ class TestQgsVectorLayer: public QObject
mpPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(), mpPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(),
myPointFileInfo.completeBaseName(), "ogr" ); myPointFileInfo.completeBaseName(), "ogr" );
// Register the layer with the registry // Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer( mpPointsLayer ); QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPointsLayer );
// //
//create a poly layer that will be used in all tests... //create a poly layer that will be used in all tests...
@ -100,7 +102,8 @@ class TestQgsVectorLayer: public QObject
mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(), mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(),
myPolyFileInfo.completeBaseName(), "ogr" ); myPolyFileInfo.completeBaseName(), "ogr" );
// Register the layer with the registry // Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer( mpPolysLayer ); QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPolysLayer );
// //
@ -111,7 +114,8 @@ class TestQgsVectorLayer: public QObject
mpLinesLayer = new QgsVectorLayer( myLineFileInfo.filePath(), mpLinesLayer = new QgsVectorLayer( myLineFileInfo.filePath(),
myLineFileInfo.completeBaseName(), "ogr" ); myLineFileInfo.completeBaseName(), "ogr" );
// Register the layer with the registry // Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer( mpLinesLayer ); QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpLinesLayer );
// //
// We only need maprender instead of mapcanvas // We only need maprender instead of mapcanvas
// since maprender does not require a qui // since maprender does not require a qui