[QGIS-Developer] Inserting provider filter just before PostGIS layer is loaded?

Johannes Kröger (WhereGroup) johannes.kroeger at wheregroup.com
Tue Aug 30 09:10:14 PDT 2022


Thomas B sent me a suggestion off list and allowed me to share it:

QgsProject.layersAdded.connect(func) actually seems to emit in just the 
right moment. This feels super finicky but so far it has worked 
flawlessly to set the layer.setSubsetString() *before* the actual query 
goes out to the DB. Hope I don't jinx it by posting ;)

Handle with care, and thanks Thomas!

Cheers, Hannes


Am 09.08.22 um 11:15 schrieb Johannes Kröger (WhereGroup) via 
QGIS-Developer:
> Howdy!
>
> I'd like to force a provider filter when a user adds a PostGIS layer 
> and have it applied *before* any data is loaded. Setting it after the 
> layer (and some of its big data) is loaded initially is not an option.
>
> Is there a way to sneak in between "user clicked something in the GUI 
> to load a table/query and QGIS will construct a QgsVectorLayer now" 
> and "QGIS now talks to the PostGIS database to get the data for the 
> new layer", maybe with a signal?
>
> Something like a "layerAboutToBeLoaded" (like the opposite 
> layerWillBeRemoved on 
> https://qgis.org/pyqgis/master/core/QgsProject.html) basically. :o)
>
> Cheers, Hannes

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0x840A4B843789797F.asc
Type: application/pgp-keys
Size: 2472 bytes
Desc: OpenPGP public key
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220830/393f99ea/attachment-0001.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 665 bytes
Desc: OpenPGP digital signature
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220830/393f99ea/attachment-0001.sig>


More information about the QGIS-Developer mailing list