[prev in list] [next in list] [prev in thread] [next in thread] 

List:       qgis-developer
Subject:    Re: [Qgis-developer] PyQGIS: Problems with the layerWasAdded SIGNAL
From:       Germán_Carrillo <carrillo.german () gmail ! com>
Date:       2009-06-16 17:14:09
Message-ID: e32d76a10906161014paef6b62uab42f9d1ff6ac3ed () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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 laye=
r
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=E1n


El 16 de junio de 2009 10:44, Germ=E1n Carrillo
<carrillo.german@gmail.com>escribi=F3:

> 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=E1n
>
> El 16 de junio de 2009 10:04, Martin Dobias <wonder.sk@gmail.com>escribi=
=F3:
>
> 2009/6/16 Germ=E1n Carrillo <carrillo.german@gmail.com>:
>> > Thanks Martin, but I remove the layer from the layerSet before removin=
g
>> 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=E1ticas Libres
> http://geotux.tuxfamily.org/
>
> --
-----------
  |\__
(:>__)(
  |/

Soluciones Geoinform=E1ticas Libres
http://geotux.tuxfamily.org/

[Attachment #5 (text/html)]

Martin, thanks by your advices, I finally get it.<br><br>I reorder things this way \
(just like QGIS do the same things):<br><br>Add Layer: <br><br>    * Viewer Class: \
Calls the loadShapefile method from Load Class.<br>    * Load Class: Add layer to \
                QgsMapLayerRegistry.<br>
    * Legend Class: ( SLOT to layerWasAdded SIGNAL ) <br>                   +  Add \
new QTreeWidgetItem.<br>                   +  Update the canvas layer set. (Before, \
the canvas layer set was updated on Load Class)<br><br> Remove Layer: ( Before, a for \
did the RemoveItem, the remove from QgsMapLayerRegistry and the update canvas layer \
set )<br>    <br>    * Legend Class: Remove layer from QgsMapLayerRegistry.<br>    * \
                Legend Class: Remove the QTreeWidgetItem.<br>
    * Legend Class: Update the canvas layer set. <br><br>Now the app works with \
SIGNAL-SLOT mechanism, like it should be.<br><br>Germán<br><br><br><div \
class="gmail_quote">El 16 de junio de 2009 10:44, Germán Carrillo <span \
dir="ltr">&lt;<a href="mailto:carrillo.german@gmail.com">carrillo.german@gmail.com</a>&gt;</span> \
escribió:<br> <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, \
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Well, I thought this order \
would do those things:<div class="im"><br><br>        self.layers.remove( i ) <br>    \
QgsMapLayerRegistry.instance().removeMapLayer( i.layer().getLayerID() ) <br><div>     \
self.canvas.setLayerSet( self.layers ) </div><br></div>Anyway, I did the two lines \
swap and get the segmentation fault again.<br><br>Germán <br><br><div \
class="gmail_quote">El 16 de junio de 2009 10:04, Martin Dobias <span \
dir="ltr">&lt;<a href="http://wonder.sk" target="_blank">wonder.sk</a>@<a \
href="http://gmail.com" target="_blank">gmail.com</a>&gt;</span> escribió:<div> \
<div></div><div class="h5"><br> <blockquote class="gmail_quote" style="border-left: \
1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: \
1ex;"><div>2009/6/16 Germán Carrillo &lt;<a href="mailto:carrillo.german@gmail.com" \
target="_blank">carrillo.german@gmail.com</a>&gt;:<br>


</div><div>&gt; Thanks Martin, but I remove the layer from the layerSet before \
removing from<br> &gt; QgsMapLayerRegistry. So, when I update the layer set in \
canvas, the layer<br> &gt; doesn&#39;t exists.<br>
<br>
</div>From your code I see you only remove the layer from the self.layers<br>
dictionary. But canvas (resp. map renderer class) still thinks that<br>
the layer exists.<br>
<font color="#888888"><br>
Martin<br>
</font></blockquote></div></div></div><br><br clear="all"><div><div></div><div \
class="h5"><br>-- <br>-----------<br>   |\__  <br>(:&gt;__)(<br>  |/    \
<br><br>Soluciones Geoinformáticas Libres                            <br> <a \
href="http://geotux.tuxfamily.org/" \
target="_blank">http://geotux.tuxfamily.org/</a><br> <br>
</div></div></blockquote></div>-- <br>-----------<br>   |\__  <br>(:&gt;__)(<br>   |/ \
<br><br>Soluciones Geoinformáticas Libres                            <br><a \
href="http://geotux.tuxfamily.org/">http://geotux.tuxfamily.org/</a><br> <br>



_______________________________________________
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic