<div dir="ltr"><div><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 21, 2019 at 2:20 PM Lars I. Nielsen, LIFA A/S <<a href="mailto:lin@lifa.dk">lin@lifa.dk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="DA">
<div class="gmail-m_-1046061070484270957WordSection1">
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US">Hi bold developers of QGIS.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US">I’ve recently begun digging into utilizing the event (signal) model of QGIS (3.4).<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US">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 (<a href="https://qgis.org/pyqgis/master/core/index.html" target="_blank">https://qgis.org/pyqgis/master/core/index.html</a>).<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US">E.g., the event “layerLoaded” on the project instance with the description “<i>Emitted when a layer from a projects (sic) was read</i>”, which to me indicates,
 that the loading is done (due to the use of “loaded” and “was”).</span></p></div></div></blockquote><div><br></div><div>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:</div><div>     * \param i current layer<br>     * \param n number of layers</div><div>so, the first time it is emitted "before" any layers is read: <span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US">layerLoaded</span>(0, <number_of_layers>)</div><div>and then it is emitted exactly once "after" each layer has been read and (this time for real) loaded in the layer registry.</div><div>Be aware that the loaded layers may still be invalid because they might be broken layers.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="DA"><div class="gmail-m_-1046061070484270957WordSection1"><p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US">But the event is emitted before the loading of the layer is done, and you are therefore unable to find the layer it concerns.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US">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.</span></p></div></div></blockquote><div><br></div><div>actually metadataChanged looks like it is called "after" the change takes place.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div lang="DA"><div class="gmail-m_-1046061070484270957WordSection1"><p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US">If the two events are indeed preload events, their names should instead be something like “layerLoading” and “metadataChanging”, or even “layerPreLoad” and “metadataPreChange”.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US">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 ?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US">Or must I (hopefully not) take a deep look into the QGIS source code itself for this kind of information ?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US">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.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:10pt;font-family:"Arial","sans-serif"" lang="EN-US"><u></u> <u></u></span></p>
</div></div><a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank"></a></blockquote><div><br></div><div> 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. <br></div><div><br></div><div>Something to keep in mind for QGIS4.</div><div><br></div><div>You could also file a ticket for that, just to keep it under the radar: <br></div><div><br></div><div><a href="https://github.com/qgis/qgis4.0_api/issues">https://github.com/qgis/qgis4.0_api/issues</a></div></div><br clear="all"></div><div>Hope this helps.</div><div><br></div><div>-- <br><div dir="ltr" class="gmail_signature">Alessandro Pasotti<br>w3:   <a href="http://www.itopen.it" target="_blank">www.itopen.it</a></div></div></div>