Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[BACKPORT] to 1.8. Remove deprecated use of map layer registry addLay…
…er and removeLayer elsewhere in code base
  • Loading branch information
timlinux committed Apr 4, 2012
1 parent 8d4a656 commit d830d53
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 29 deletions.
6 changes: 4 additions & 2 deletions src/app/legend/qgslegend.cpp
Expand Up @@ -1172,7 +1172,8 @@ void QgsLegend::removeGroup( QgsLegendGroup *lg )
QgsLegendGroup *cg = dynamic_cast<QgsLegendGroup *>( child );

if ( cl )
QgsMapLayerRegistry::instance()->removeMapLayer( cl->layer()->id() );
QgsMapLayerRegistry::instance()->removeMapLayers(
QStringList() << cl->layer()->id() );
else if ( cg )
removeGroup( cg );

Expand Down Expand Up @@ -2420,7 +2421,8 @@ void QgsLegend::removeSelectedLayers()
QgsLegendLayer *ll = dynamic_cast<QgsLegendLayer *>( item );
if ( ll && ll->layer() )
{
QgsMapLayerRegistry::instance()->removeMapLayer( ll->layer()->id() );
QgsMapLayerRegistry::instance()->removeMapLayers(
QStringList() << ll->layer()->id() );
continue;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/app/qgsnewspatialitelayerdialog.cpp
Expand Up @@ -429,7 +429,11 @@ bool QgsNewSpatialiteLayerDialog::apply()
if ( layer->isValid() )
{
// 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;
}
else
Expand Down
3 changes: 2 additions & 1 deletion src/browser/qgsbrowser.cpp
Expand Up @@ -245,7 +245,8 @@ bool QgsBrowser::layerClicked( QgsLayerItem *item )

QgsDebugMsg( "Layer created" );

QgsMapLayerRegistry::instance()->addMapLayer( mLayer );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mLayer );

return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgspluginlayerregistry.cpp
Expand Up @@ -100,7 +100,8 @@ bool QgsPluginLayerRegistry::removePluginLayerType( QString typeName )
QgsPluginLayer* pl = qobject_cast<QgsPluginLayer*>( layer );
if ( pl->pluginLayerType() == typeName )
{
QgsMapLayerRegistry::instance()->removeMapLayer( layer->id() );
QgsMapLayerRegistry::instance()->removeMapLayers(
QStringList() << layer->id() );
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/mapserver/qgswmsserver.cpp
Expand Up @@ -1427,7 +1427,8 @@ QStringList QgsWMSServer::layerSet( const QStringList &layersList,
if ( theMapLayer )
{
layerKeys.push_front( theMapLayer->id() );
QgsMapLayerRegistry::instance()->addMapLayer( theMapLayer, false );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << theMapLayer, false );
}
else
{
Expand Down
9 changes: 6 additions & 3 deletions src/plugins/georeferencer/qgsgeorefplugingui.cpp
Expand Up @@ -146,7 +146,8 @@ QgsGeorefPluginGui::~QgsGeorefPluginGui()
// delete layer (and don't signal it as it's our private layer)
if ( mLayer )
{
QgsMapLayerRegistry::instance()->removeMapLayer( mLayer->id(), false );
QgsMapLayerRegistry::instance()->removeMapLayers(
(QStringList() << mLayer->id()), false );
}

delete mToolZoomIn;
Expand Down Expand Up @@ -251,7 +252,8 @@ void QgsGeorefPluginGui::openRaster()

//delete any old rasterlayers
if ( mLayer )
QgsMapLayerRegistry::instance()->removeMapLayer( mLayer->id(), false );
QgsMapLayerRegistry::instance()->removeMapLayers(
QStringList() << mLayer->id(), false );

// Add raster
addRaster( mRasterFileName );
Expand Down Expand Up @@ -1039,7 +1041,8 @@ void QgsGeorefPluginGui::addRaster( QString file )
mLayer = new QgsRasterLayer( file, "Raster" );

// so layer is not added to legend
QgsMapLayerRegistry::instance()->addMapLayer( mLayer, false );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mLayer, false );

// add layer to map canvas
QList<QgsMapCanvasLayer> layers;
Expand Down
12 changes: 8 additions & 4 deletions src/plugins/offline_editing/offline_editing.cpp
Expand Up @@ -182,7 +182,8 @@ void QgsOfflineEditing::synchronize( QgsLegendInterface* legendInterface )
copySymbology( offlineLayer, remoteLayer );

// register this layer with the central layers registry
QgsMapLayerRegistry::instance()->addMapLayer( remoteLayer, true );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << remoteLayer, true );

// apply layer edit log
QString qgisLayerId = layer->id();
Expand Down Expand Up @@ -233,7 +234,8 @@ void QgsOfflineEditing::synchronize( QgsLegendInterface* legendInterface )
}

// remove offline layer
QgsMapLayerRegistry::instance()->removeMapLayer( qgisLayerId, true );
QgsMapLayerRegistry::instance()->removeMapLayers(
(QStringList() << qgisLayerId), true );

// disable offline project
QString projectTitle = QgsProject::instance()->title();
Expand Down Expand Up @@ -495,7 +497,8 @@ void QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlite3* db, con
}

// register this layer with the central layers registry
QgsMapLayerRegistry::instance()->addMapLayer( newLayer );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << newLayer );

if ( hasLabels )
{
Expand Down Expand Up @@ -567,7 +570,8 @@ void QgsOfflineEditing::copyVectorLayer( QgsVectorLayer* layer, sqlite3* db, con
}

// remove remote layer
QgsMapLayerRegistry::instance()->removeMapLayer( layer->id() );
QgsMapLayerRegistry::instance()->removeMapLayers(
QStringList() << layer->id() );
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/roadgraph/exportdlg.cpp
Expand Up @@ -85,7 +85,9 @@ QgsVectorLayer* RgExportDlg::mapLayer() const
QList<QgsField> attrList;
attrList.append( QgsField( "one", QVariant::Int ) );
prov->addAttributes( attrList );
QgsMapLayerRegistry::instance()->addMapLayer( myLayer );
QList<QgsMapLayer *> myList;
myList << myLayer;
QgsMapLayerRegistry::instance()->addMapLayers( myList );

}
else
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/spatialquery/qgsspatialquerydialog.cpp
Expand Up @@ -298,7 +298,8 @@ bool QgsSpatialQueryDialog::addLayerSubset( QString name, QString subset )
delete addLyr;
return false;
}
QgsMapLayerRegistry::instance()->addMapLayer( addLyr );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << addLyr );
return true;
} // bool QgsSpatialQueryDialog::addLayerSubset( QString name, QString subset )

Expand Down
4 changes: 3 additions & 1 deletion src/plugins/sqlanywhere/sqlanywhere.cpp
Expand Up @@ -152,7 +152,9 @@ void SqlAnywhere::addSqlAnywhereLayer()
SaDebugMsg( "Beautifying layer name. new: " + layer->name() );

// register this layer with the central layers registry
QgsMapLayerRegistry::instance()->addMapLayer(( QgsVectorLayer* )layer );
QList<QgsMapLayer *> myList;
myList << ( QgsVectorLayer* )layer;
QgsMapLayerRegistry::instance()->addMapLayers( myList );
}
else
{
Expand Down
4 changes: 3 additions & 1 deletion tests/src/core/regression992.cpp
Expand Up @@ -75,7 +75,9 @@ void Regression992::initTestCase()
mpRasterLayer = new QgsRasterLayer( myRasterFileInfo.filePath(),
myRasterFileInfo.completeBaseName() );
// 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
mpMapRenderer = new QgsMapRenderer();
QStringList myLayers;
Expand Down
3 changes: 2 additions & 1 deletion tests/src/core/testqgsmaprenderer.cpp
Expand Up @@ -166,7 +166,8 @@ void TestQgsMapRenderer::initTestCase()
mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(),
myPolyFileInfo.completeBaseName(), "ogr" );
// Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer( mpPolysLayer );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPolysLayer );
// add the test layer to the maprender
mpMapRenderer = new QgsMapRenderer();
QStringList myLayers;
Expand Down
12 changes: 8 additions & 4 deletions tests/src/core/testqgsrasterlayer.cpp
Expand Up @@ -90,8 +90,10 @@ void TestQgsRasterLayer::initTestCase()
mpLandsatRasterLayer = new QgsRasterLayer( myLandsatRasterFileInfo.filePath(),
myLandsatRasterFileInfo.completeBaseName() );
// Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer( mpRasterLayer );
QgsMapLayerRegistry::instance()->addMapLayer( mpLandsatRasterLayer );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpRasterLayer );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpLandsatRasterLayer );
// add the test layer to the maprender
mpMapRenderer = new QgsMapRenderer();
QStringList myLayers;
Expand Down Expand Up @@ -237,8 +239,10 @@ void TestQgsRasterLayer::registry()
QgsRasterLayer * mypLayer = new QgsRasterLayer( myRasterFileInfo.filePath(),
myRasterFileInfo.completeBaseName() );

QgsMapLayerRegistry::instance()->addMapLayer( mypLayer, false );
QgsMapLayerRegistry::instance()->removeMapLayer( mypLayer->id() );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mypLayer, false );
QgsMapLayerRegistry::instance()->removeMapLayers(
QStringList() << mypLayer->id() );
//cleanup
//delete mypLayer;
}
Expand Down
9 changes: 6 additions & 3 deletions tests/src/core/testqgsrenderers.cpp
Expand Up @@ -90,7 +90,8 @@ void TestQgsRenderers::initTestCase()
mpPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(),
myPointFileInfo.completeBaseName(), "ogr" );
// 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...
Expand All @@ -100,7 +101,8 @@ void TestQgsRenderers::initTestCase()
mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(),
myPolyFileInfo.completeBaseName(), "ogr" );
// Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer( mpPolysLayer );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPolysLayer );


//
Expand All @@ -111,7 +113,8 @@ void TestQgsRenderers::initTestCase()
mpLinesLayer = new QgsVectorLayer( myLineFileInfo.filePath(),
myLineFileInfo.completeBaseName(), "ogr" );
// Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer( mpLinesLayer );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpLinesLayer );
//
// We only need maprender instead of mapcanvas
// since maprender does not require a qui
Expand Down
12 changes: 8 additions & 4 deletions tests/src/core/testqgsvectorlayer.cpp
Expand Up @@ -81,7 +81,8 @@ class TestQgsVectorLayer: public QObject
mpNonSpatialLayer = new QgsVectorLayer( myDbfFileInfo.filePath(),
myDbfFileInfo.completeBaseName(), "ogr" );
// 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...
//
Expand All @@ -90,7 +91,8 @@ class TestQgsVectorLayer: public QObject
mpPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(),
myPointFileInfo.completeBaseName(), "ogr" );
// 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...
Expand All @@ -100,7 +102,8 @@ class TestQgsVectorLayer: public QObject
mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(),
myPolyFileInfo.completeBaseName(), "ogr" );
// Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer( mpPolysLayer );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPolysLayer );


//
Expand All @@ -111,7 +114,8 @@ class TestQgsVectorLayer: public QObject
mpLinesLayer = new QgsVectorLayer( myLineFileInfo.filePath(),
myLineFileInfo.completeBaseName(), "ogr" );
// Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer( mpLinesLayer );
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpLinesLayer );
//
// We only need maprender instead of mapcanvas
// since maprender does not require a qui
Expand Down

0 comments on commit d830d53

Please sign in to comment.