On Tue, 23 Jul 2019 at 02:01, Tejas L <[email protected]> wrote: > > Hello devs, > > I am using the QGIS postprocessing interface to add layers to a layer group. > The layer group is created in processAlgorithm, while the indivdual layers > are added from postprocessing classses. > > The layer group gets created as expected along with the child layers. However > toggling the individual layers does not repaint the canvas and has no effect. > Toggling the entire group does work though. > > The pseudocode is as follows: > > def processAlgorithm(...): > root = context.project().layerTreeRoot() > group = root.insertGroup(0, "myGroup")
Here's where your problem lies. You're creating the group in the processAlgorithm step, which is run in a background thread. Apart from being at severe risk of crashes, this also has the side-effect of making the new group "live" in the background thread. As soon as your algorithm finishes and that thread exits, it will stop processing events and things will go... murky... with your group. Solution: don't do ANYTHING like this in a background thread, and do all this logic in the post-processor (which runs in the main thread). Nyall > > self.postp = MyPostProcessor(group) > > layer = QgsVectorLayer(...) > if layer and self.context.willLoadLayerOnCompletion(layer.id()): > > self.context.layerToLoadOnCompletionDetails(layer.id()).setPostProcessor(self.postp). > > MyPostProcessor is used to basically move the layer to the group. > > When the layer group is also created from within the postprocessing class, > everthing works perfectly. > > What am I doing wrong? > > Regards, > Tej > > > _______________________________________________ > QGIS-Developer mailing list > [email protected] > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer _______________________________________________ QGIS-Developer mailing list [email protected] List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
