[Qgis-developer] Removing layers in QGIS

Martin Dobias wonder.sk at gmail.com
Mon Mar 20 17:31:14 EST 2006


On 3/20/06, nhugent at hispeed.ch <nhugent at hispeed.ch> wrote:
> 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)

Ah well, I haven't noticed the latter one (legendLayerRemove) which
also removes layer from  registry. The incorrect function I have meant
was QgisApp::removeLayer (it lefts  - I guess that the right approach
is just to call QgsLegend::legendLayerRemove - is it right?

>
> >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.

I thought a bit on this topic and this looks like good solution: every
map canvas has it's own legend - for the matter of not getting legend
implementation too complex. Map layer registry holds also count of
canvases referencing a layer, therefore when it's going to be removed
from one legend, it decreases number of references and deletes it when
counter reaches zero.

Martin

>
>
> Marco
>



More information about the Qgis-developer mailing list