[Qgis-developer] Removing layers in QGIS

nhugent at hispeed.ch nhugent at hispeed.ch
Mon Mar 20 16:28:15 EST 2006


Hi Martin,

>Hi Marco,
>
>recently I've found out that removing layer has 2 different
>implementations - one in QgsLegend, another in QgisApp (this one even
>doesn't work correctly). 

In which cases does it not work correctly? Normally, i remove from the right click menu. Now i tried it from the main window menu and it seemed to work.

>I wanted to fix that with using
>QgsLegend::removeLayer(), but I've found inconsistency: in QgisApp,
>layer is erased from map layer registry, while in QgsLegend this is
>not happening.

There is QgsLegend::removeLayer(QString) and QgsLegend::legendLayerRemove(). The first one does not remove from the registry, the second one does. In nearly all cases, the second one is called. The first one is only called if QgsMapLayerRegistry::removeLayer is called with bool emitSignal = true and so the map layer is already removed from the registry (but i don't know if there is a need for the second call any more)

>My question is - what is the policy of using map layer registry (who
>is responsible for adding/removing from it etc.). This would be good
>to decide, also with regard to possibility to have multiple map
>canvases or embedding canvas and legend to other projects.

I agree current situation is (unnecessary) complicated. For the moment, it seems easier to me to remove from the registry only in legend. Because every layer remove goes to the legend, but some removes from the right click menu do not go to qgisapp.

Is it the idea, that the multiple map canvases will have the same legend? If yes, legend seems to be a good place for add/remove.


Marco



More information about the Qgis-developer mailing list