TreeView automatic column span error

Issue #737 resolved
Benjamin Jakimow created an issue

Collapsing expanded TreeNodes fails if one of the subnodes contains a PyObjectNode.

This affects the DataSourceTreeView with expanded PKL nodes.

Seems to be related to TreeView.setColumnSpan

How to reproduce (for documentation)

    def test_issue_672(self):
        """
        Collapsing parent nodes crashes TreeView
        How to reproduce
        1. Show Widget
        2. Expand nodes 'Models', 'classification_dataset.pkl', 'dict', 'X', 'array'
           (below 'classification_dataset.pkl' will be fetched on demand)
        3. unexpand 'X'

        - happens with TreeView but not QTreeView
        - seems to be related to TreeView.setColumnSpan
        - automatic column span is necessary to save space
        """
        mgr = DataSourceManager()
        model = DataSourceManagerTreeModel(None, mgr)

        tv = TreeView()
        # tv = QTreeView()
        tv.setUniformRowHeights(True)
        tv.setIndentation(12)
        tv.setAutoExpansionDepth(10)
        tv.setModel(model)

        # set False to avoid error
        tv.setAutoFirstColumnSpan(True)

        from testdata import classification_dataset_pkl
        self.assertIsInstance(tv, QTreeView)
        mgr.addSource(classification_dataset_pkl)

        node = model.rootNode().findChildNodes(HubFlowPyObjectTreeNode, recursive=True)
        self.assertTrue(len(node) == 1)
        node = node[0]
        # tv.expandRecursively(QModelIndex(), 4)
        # dict X array
        self.assertIsInstance(node, HubFlowPyObjectTreeNode)
        NODES = dict(ROOT=node)

        for name in ['dict', 'X', 'array']:

            node.fetch()
            # tv.expand(model.node2idx(node))
            node = node.findChildNodes(PyObjectTreeNode, name)[0]
            NODES[name] = node

        # tv.expand(model.node2idx(node))
        tv.resize(QSize(600, 600))
        tv.show()
        s  =""

        self.showGui(tv)

Comments (10)

  1. Andreas Janz
    • changed status to open

    Benjamin, the bug is back. Or maybe I'm missing a detail: what is the "workaround" you mentioned in the comment from 2021-09-30?

  2. Benjamin Jakimow reporter

    @Andreas Janz cannot reproduce with QGIS 3.24. Please close this issue if appropriate

  3. Log in to comment