Hi, somehow I need to create a plugin which can toggle visibility of a layer in the .qml, I am wondering if this is currently possible?
1 Like
Heya!
I found that it’s possible like this:
import org.qfield
let count = flatLayerTree.rowCount();
for (let i = 0; i < count; ++i) {
let idx = flatLayerTree.index(i, 0);
let name = flatLayerTree.data(idx, FlatLayerTreeModel.Name);
let visible = flatLayerTree.data(idx, FlatLayerTreeModel.Visible);
iface.logMessage("Layer: " + name + " was visible: " + visible);
flatLayerTree.setData(idx, !visible, FlatLayerTreeModel.Visible);
}
To change/read different layer values, you can reference the enums in FlatLayerTreeModel.
Hope this helps!
1 Like
Nice tip! I’m going to keep that in my pocket.
That helps a lot! Thank you, appreciate it