Skip to content

views

View

Bases: QTreeView

Source code in client/ayon_maya/tools/mayalookassigner/views.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class View(QtWidgets.QTreeView):
    data_changed = QtCore.Signal()

    def __init__(self, parent=None):
        super(View, self).__init__(parent=parent)

        # view settings
        self.setAlternatingRowColors(False)
        self.setSortingEnabled(True)
        self.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
        self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)

    def get_indices(self):
        """Get the selected rows"""
        selection_model = self.selectionModel()
        return selection_model.selectedRows()

    def extend_to_children(self, indices):
        """Extend the indices to the children indices.

        Top-level indices are extended to its children indices. Sub-items
        are kept as is.

        :param indices: The indices to extend.
        :type indices: list

        :return: The children indices
        :rtype: list
        """

        subitems = set()
        for i in indices:
            valid_parent = i.parent().isValid()
            if valid_parent and i not in subitems:
                subitems.add(i)
            else:
                # is top level node
                model = i.model()
                rows = model.rowCount(parent=i)
                for row in range(rows):
                    child = model.index(row, 0, parent=i)
                    subitems.add(child)

        return list(subitems)

extend_to_children(indices)

Extend the indices to the children indices.

Top-level indices are extended to its children indices. Sub-items are kept as is.

:param indices: The indices to extend. :type indices: list

:return: The children indices :rtype: list

Source code in client/ayon_maya/tools/mayalookassigner/views.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def extend_to_children(self, indices):
    """Extend the indices to the children indices.

    Top-level indices are extended to its children indices. Sub-items
    are kept as is.

    :param indices: The indices to extend.
    :type indices: list

    :return: The children indices
    :rtype: list
    """

    subitems = set()
    for i in indices:
        valid_parent = i.parent().isValid()
        if valid_parent and i not in subitems:
            subitems.add(i)
        else:
            # is top level node
            model = i.model()
            rows = model.rowCount(parent=i)
            for row in range(rows):
                child = model.index(row, 0, parent=i)
                subitems.add(child)

    return list(subitems)

get_indices()

Get the selected rows

Source code in client/ayon_maya/tools/mayalookassigner/views.py
16
17
18
19
def get_indices(self):
    """Get the selected rows"""
    selection_model = self.selectionModel()
    return selection_model.selectedRows()