[Qgis-developer] PyQGIS: Problems with the layerWasAdded SIGNAL

Germán Carrillo carrillo.german at gmail.com
Tue Jun 16 13:14:09 EDT 2009


Martin, thanks by your advices, I finally get it.

I reorder things this way (just like QGIS do the same things):

Add Layer:

    * Viewer Class: Calls the loadShapefile method from Load Class.
    * Load Class: Add layer to QgsMapLayerRegistry.
    * Legend Class: ( SLOT to layerWasAdded SIGNAL )
                   +  Add new QTreeWidgetItem.
                   +  Update the canvas layer set. (Before, the canvas layer
set was updated on Load Class)

Remove Layer: ( Before, a for did the RemoveItem, the remove from
QgsMapLayerRegistry and the update canvas layer set )

    * Legend Class: Remove layer from QgsMapLayerRegistry.
    * Legend Class: Remove the QTreeWidgetItem.
    * Legend Class: Update the canvas layer set.

Now the app works with SIGNAL-SLOT mechanism, like it should be.

Germán


El 16 de junio de 2009 10:44, Germán Carrillo
<carrillo.german at gmail.com>escribió:

> Well, I thought this order would do those things:
>
>         self.layers.remove( i )
>         QgsMapLayerRegistry.instance().removeMapLayer(
> i.layer().getLayerID() )
>         self.canvas.setLayerSet( self.layers )
>
> Anyway, I did the two lines swap and get the segmentation fault again.
>
> Germán
>
> El 16 de junio de 2009 10:04, Martin Dobias <wonder.sk at gmail.com>escribió:
>
> 2009/6/16 Germán Carrillo <carrillo.german at gmail.com>:
>> > Thanks Martin, but I remove the layer from the layerSet before removing
>> from
>> > QgsMapLayerRegistry. So, when I update the layer set in canvas, the
>> layer
>> > doesn't exists.
>>
>> From your code I see you only remove the layer from the self.layers
>> dictionary. But canvas (resp. map renderer class) still thinks that
>> the layer exists.
>>
>> Martin
>>
>
>
>
> --
> -----------
>   |\__
> (:>__)(
>   |/
>
> Soluciones Geoinformáticas Libres
> http://geotux.tuxfamily.org/
>
> --
-----------
  |\__
(:>__)(
  |/

Soluciones Geoinformáticas Libres
http://geotux.tuxfamily.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20090616/5c2f9312/attachment.html


More information about the Qgis-developer mailing list