Closed raymondnijssen closed 5 years ago
Asked for suggestions on the dev list: https://lists.osgeo.org/pipermail/qgis-developer/2019-May/057470.html
Possible (smelly!) solution is using the QgsProject 'loadingLayer' signal and connect it to a function that checks the layerName and overwrites the data source if it contains 'SIMS_world_overview'
@pyqtSlot('QString')
def layerLoaded(value):
print('layerLoded: {}'.format(value))
if 'SIMS_world_overview' in value:
# set data source here
QgsProject.instance().loadingLayer.connect(layerLoaded)
As of this point @raymondnijssen, @r2rc and @arongergely came up with the idea of shipping the overview layer with the plugin as the most reasonable solution
That data we currently use for this layer is from a built-in "ester egg" in QGIS (accessible by typing world
in the coordinate box and pressing Enter )
Checklist of tasks, with assigned person:
Locally implemented and tested a solution that is based on the QgsProject.readPoject
signal. (API doc link).
While it works, it may confuse the user:
Apparently, readProject
is emitted only after all layers are initialized at project load, and an eventual "Handle Unavailable Layers" popup window is closed.
When choosing to "keep unavaulable layers", the window closes and readProject
is emitted and a slot is run that replaces the overview map data path with the right one.
I think this will trick users into believing the overview map is broken while it would be fixed in the next step after the popup window.
Thus I am now looking at using a different signal, after some trial & error I found QgsProject.layerLoaded
(API doc link) which seems suitable:
It is emitted for each layer on load, and before the mentioned popup window would appear for missing layers.
The above behaviour is still present with the layerLoaded
signal.
The problem likely because "bad layers" are collected behorehand and passed to a bad layer handler that subsequently runs and opens the popup window.
It may be better to implement a custom bad layer handler that handles the world map layer appropriately and set it for QgsProject
via QgsProject.setBadLayerHandler()
(API doc link)
https://gis.stackexchange.com/questions/67291/how-to-set-default-bad-layers-handler-in-the-python-plugin https://gis.stackexchange.com/questions/310953/qgis-badlayerhandler-setdataprovider
When reopening a saved project with sims map layouts, the overview layer is likely to point to a non existent location for the world_map.shp