TransWikia.com

Update for Deprecated setLayerInsertionPoint() in QGIS3

Geographic Information Systems Asked by CNIDog on March 6, 2021

The setLayerInsertionPoint() with the QgsProject.instance().layerTreeRoot() object is deprecated. The documentation says:

since QGIS 3.10 use setLayerInsertionPoint( const InsertionPoint &insertionPoint ) instead

but I can find no example of how to implement this update. My current code is as follows:

QgsProject.instance().layerTreeRegistryBridge().setLayerInsertionPoint(QgsProject.instance().layerTreeRoot(), 0)

It seems the only change is the first argument. How should I update the statement to comply with current requirements?

QgsProject.instance().layerTreeRegistryBridge().setLayerInsertionPoint([what_goes_here?], 0)

One Answer

I have not actually tested this but the following should work:

root_group = QgsProject.instance().layerTreeRoot()

insertion_point = QgsLayerTreeRegistryBridge.InsertionPoint(root_group, 0)

QgsProject.instance().layerTreeRegistryBridge().setInsertionPoint(insertion_point)

To check, the line:

print(insertion_point)

returns:

<qgis._core.QgsLayerTreeRegistryBridge.InsertionPoint object at 0x000001DAE4116678>

See:

https://qgis.org/api/structQgsLayerTreeRegistryBridge_1_1InsertionPoint.html

Correct answer by Ben W on March 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP