2

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)

where domNode has been passed in from handleBadLayers(self, domNodes)

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.