[QGIS-Developer] Event woes in QGIS

Alessandro Pasotti apasotti at gmail.com
Wed Aug 21 05:56:46 PDT 2019


On Wed, Aug 21, 2019 at 2:20 PM Lars I. Nielsen, LIFA A/S <lin at lifa.dk>
wrote:

> Hi bold developers of QGIS.
>
>
>
> I’ve recently begun digging into utilizing the event (signal) model of
> QGIS (3.4).
>
>
>
> And I’ve encountered a number of frustrations, as the events don’t work
> the way they’re supposed to, at least according to the available
> documentation (https://qgis.org/pyqgis/master/core/index.html).
>
>
>
> E.g., the event “layerLoaded” on the project instance with the description
> “*Emitted when a layer from a projects (sic) was read*”, which to me
> indicates, that the loading is done (due to the use of “loaded” and “was”).
>

I agree the name can be misleading misleading, "Emitted when a layer from a
projects was read." the key is in "read", it means "read from the project
XML file", also, it takes two arguments:
     * \param i current layer
     * \param n number of layers
so, the first time it is emitted "before" any layers is read: layerLoaded(0,
<number_of_layers>)
and then it is emitted exactly once "after" each layer has been read and
(this time for real) loaded in the layer registry.
Be aware that the loaded layers may still be invalid because they might be
broken layers.


>
>
> But the event is emitted before the loading of the layer is done, and you
> are therefore unable to find the layer it concerns.
>
>
>
> Another example is the event “metadataChanged” on a loaded layer, which
> again to me indicates a past/done action (due to the use of “changed”). But
> again, it’s emitted before the change actually takes place, and the changed
> metadata isn’t available.
>

actually metadataChanged looks like it is called "after" the change takes
place.


>
>
> If the two events are indeed preload events, their names should instead be
> something like “layerLoading” and “metadataChanging”, or even
> “layerPreLoad” and “metadataPreChange”.
>
>
>
> Is there a guide somewhere to tell how the event system is envisioned, and
> which events are emitted pre-action and which are emitted post-action ?
>
>
>
> Or must I (hopefully not) take a deep look into the QGIS source code
> itself for this kind of information ?
>
>
>
> In general, pre-action events are of limited use, except when it comes to
> deletions and destructions. For loading and changing stuff, post-action
> events are almost always what you need.
>
>
> <https://lists.osgeo.org/mailman/listinfo/qgis-developer>


 I'm afraid that, set aside a few cases, most of the signals have been
created to meet particular needs for internal synchronization of QGIS
application, they are now part of the stable API and I agree the we should
improve the naming and the documentation and make them more
developer-friendly for Python plugin developers.

Something to keep in mind for QGIS4.

You could also file a ticket for that, just to keep it under the radar:

https://github.com/qgis/qgis4.0_api/issues

Hope this helps.

-- 
Alessandro Pasotti
w3:   www.itopen.it
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190821/25923ecf/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.gif
Type: image/gif
Size: 6269 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190821/25923ecf/attachment.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 1204 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190821/25923ecf/attachment.png>


More information about the QGIS-Developer mailing list