def __item_iterator(self):
        iterator = QTreeWidgetItemIterator(
            self.component.hierarchy_tree_widget, QTreeWidgetItemIterator.All)

        while iterator.value():
            item: QTreeWidgetItem = iterator.value()
            if not item.childCount():
                yield item
            iterator += 1
Beispiel #2
0
    def get_hierarchies(self, **kwargs):
        """ return selected hierarchy
        """
        only_selected = kwargs.get('only_selected', None)

        sets_to_display = list()

        if only_selected:
            iterator = QTreeWidgetItemIterator(self.hierarchy_tree_widget,
                                               QTreeWidgetItemIterator.Checked)
        else:
            iterator = QTreeWidgetItemIterator(self.hierarchy_tree_widget)

        while iterator.value():
            # note: if hierarchy value is not a tuple, then this is just top level qTreeWidgetItem that
            #       holds subcategories. We don't want to display all sets from category
            if type(iterator.value().hierarchy) is not str:

                if not only_selected:
                    sets_to_display.append(iterator.value().hierarchy)
                else:
                    if not iterator.value().isDisabled():
                        sets_to_display.append(iterator.value().hierarchy)

            iterator += 1

        return sets_to_display
Beispiel #3
0
    def set_custom_sets(self):
        iterator = QTreeWidgetItemIterator(self.hierarchy_tree_widget,
                                           QTreeWidgetItemIterator.All)

        while iterator.value():

            # note: if hierarchy value is not a tuple, then this is just top level qTreeWidgetItem that
            #       holds subcategories. We don't want to display all sets from category
            if type(iterator.value().hierarchy) is not str:
                if iterator.value().hierarchy == self.custom_set_hier:
                    iterator.value().setCheckState(0, Qt.Checked)
                else:
                    iterator.value().setCheckState(0, Qt.Unchecked)

            iterator += 1
Beispiel #4
0
    def set_selected_hierarchies(self):
        iterator = QTreeWidgetItemIterator(self.hierarchy_tree_widget,
                                           QTreeWidgetItemIterator.All)
        defaults = []

        while iterator.value():

            # note: if hierarchy value is not a tuple, then this is just top level qTreeWidgetItem that
            #       holds subcategories. We don't want to display all sets from category
            if type(iterator.value().hierarchy) is not str:
                if iterator.value().hierarchy in self.parent.__getattribute__(
                        self.stored_selection):
                    iterator.value().setCheckState(0, Qt.Checked)
                else:
                    iterator.value().setCheckState(0, Qt.Unchecked)

            # if no items are checked, set defaults
            if iterator.value().hierarchy in self.default_selection:
                defaults.append(iterator.value())

            iterator += 1

        if len(self.get_hierarchies(only_selected=True)) == 0:
            [item.setCheckState(0, Qt.Checked) for item in defaults]
    def set_selected_hierarchies(self):
        iterator = QTreeWidgetItemIterator(self.hierarchy_widget,
                                           QTreeWidgetItemIterator.All)

        while iterator.value():
            # note: if hierarchy value is not a tuple, then this is just top level qTreeWidgetItem that
            #       holds subcategories. We don't want to display all sets from category
            if type(iterator.value().hierarchy) is not str:
                if iterator.value().hierarchy in self.stored_selections:
                    iterator.value().setCheckState(0, Qt.Checked)
                else:
                    iterator.value().setCheckState(0, Qt.Unchecked)

            iterator += 1

        # if no items are checked, we check first one at random
        if len(self.get_hierarchies(only_selected=True)) == 0:
            iterator = QTreeWidgetItemIterator(
                self.hierarchy_widget, QTreeWidgetItemIterator.NotChecked)

            while iterator.value():
                if type(iterator.value().hierarchy) is not str:
                    iterator.value().setCheckState(0, Qt.Checked)
                    return

                iterator += 1