[QGIS-Developer] Event woes in QGIS

Nyall Dawson nyall.dawson at gmail.com
Wed Aug 21 15:38:24 PDT 2019


On Wed, 21 Aug 2019 at 22:57, Alessandro Pasotti <apasotti at gmail.com> wrote:
>
>
>
> On Wed, Aug 21, 2019 at 2:20 PM Lars I. Nielsen, LIFA A/S <lin at lifa.dk> wrote:

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

You probably want to use the layersAdded or layerWasAdded signals
instead. They sound like what you're after.

(We should really hide layerLoaded from the python bindings. It's for
internal purposes only and is evidently misleading)

Nyall

>
>>
>>
>>
>> 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.
>>
>>
>
>
>  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
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


More information about the QGIS-Developer mailing list