[QGIS-Developer] Event woes in QGIS

Bo Victor Thomsen bo.victor.thomsen at gmail.com
Thu Aug 22 03:46:37 PDT 2019


Hi Lars -

I hazard a guess, that you want to execute some action after a /project/ 
has finished loading.

You might have a look on how to execute macro's after open, save or 
close events for the project:

In the project properties, you can enable macro's and write some python 
code that will be stored in the project:

Example: (Open an attribute window with data from layer 'kommune" after 
the project has finished loading)

|#--- macro start --- from qgis.core import QgsProject from qgis.utils 
import iface def openProject(): layers = 
QgsProject.instance().mapLayersByName('kommune') layer = layers[0] 
iface.showAttributeTable(layer) def saveProject(): pass def 
closeProject(): pass||#--- macro end ---|

Den 21-08-2019 kl. 14:15 skrev Lars I. Nielsen, LIFA A/S:
>
> 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”).
>
> 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.
>
> 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.
>
> Med venlig hilsen
>
> Lars I. Nielsen, LIFA A/S
> GIS-konsulent, FME Certified Professional
> Geoinformatik
> Beskrivelse: 
> C:\Users\lin\AppData\Roaming\Microsoft\signatures\284x82-3741133837051347070
>
> *T*
>
> 	
>
> 6313 6800
>
> 	
>
> *@*
>
> 	
>
> lin at lifa.dk
>
> *D*
>
> 	
>
> 6313 6849
>
> 	
>
> *W*
>
> 	
>
> www.lifa.dk <http://www.lifa.dk>
>
> *M*
>
> 	
>
> 2492 4866
>
> 	
>
> *CVR*
>
> 	
>
> 20937289
>
>
> Beskrivelse: 
> C:\Users\lin\AppData\Roaming\Microsoft\signatures\21x21-3019966288736195652 
> <https://www.linkedin.com/company/lifa-a-s/>
> Følg os på LinkedIn og læs de seneste nyheder fra LIFA A/S
>
>
> _______________________________________________
> 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

-- 
Med venlig hilsen / Kind regards

Bo Victor Thomsen

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190822/eed25f25/attachment-0001.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/20190822/eed25f25/attachment-0001.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/20190822/eed25f25/attachment-0001.png>


More information about the QGIS-Developer mailing list