I've made a bit of a plugin to handle badlayers (I'm aware that Change datasource plugin had something for this but the code appears to have been removed now?). I've followed the advice provided in How to set default bad layers handler in the python plugin? and I can get the handler to start when layers are missing.
I'm currently having trouble setting the new data provider. Currently I'm doing
handler = QgsProjectbadLayerHandler() newPath = "C:\pathtomissinglayer" handler.setDataSource(domNode,newPath)
domNode has been passed in from
This doesn't work as expected. The layers still disappear and setting the data source doesn't seem to change anything even though it executes properly.
Should I be passing in the
newPath as a string or something else? And how do I stop the layers from disappearing?
Edit: There appears to be a new class as a part of 3.6?? called QgsStoreBadLayerInfo. Description says it stores layer IDs of bad layers. The ID could be useful to get the position of the map layer in the layer explorer and then just create a new layer with the correct file path. As is extends from QgsProjectBadLayerHandler could this class just be used in place of QgsProjectBadLayerHandler? Will it be called when layers are missing? I tried but couldn't get it too work