def scene_selection_changed(self):
     """scene.selectionChanged slot
     """
     # TODO LH Fix dreadful performance when selection changing as a result
     # of mouse drag
     if not self.handling_selection_update:
         debug_print('GraphicsItemView.scene_selection_changed')
         # TODO Context for this
         self.handling_selection_update = True
         try:
             new_selection = set(self.rows_of_items(self.scene.selectedItems()))
             update_selection_model(self.model(), self.selectionModel(),
                                    new_selection)
         finally:
             self.handling_selection_update = False
    def _slider_changed(self, value):
        """QSlider.valueChanged slot
        """
        debug_print('SelectorView._slider_changed', value)
        if False and 0 == value:
            # Do not alter selection if value is 0
            pass
        else:
            # Order items by increasing / decreasing area and select the first n
            model = self.model()
            rows = range(model.rowCount())

            def box_area(row):
                rect = model.index(row, 0).data(RectRole)
                return rect.width() * rect.height()

            rows = sorted(rows, key=box_area, reverse=value < 0)
            self._updating_selection = True
            try:
                update_selection_model(model, self.selectionModel(), rows[:abs(value)])
            finally:
                self._updating_selection = False
Example #3
0
    def _slider_changed(self, value):
        """QSlider.valueChanged slot
        """
        debug_print('SelectorView._slider_changed', value)
        if False and 0 == value:
            # Do not alter selection if value is 0
            pass
        else:
            # Order items by increasing / decreasing area and select the first n
            model = self.model()
            rows = range(model.rowCount())

            def box_area(row):
                rect = model.index(row, 0).data(RectRole)
                return rect.width() * rect.height()

            rows = sorted(rows, key=box_area, reverse=value < 0)
            self._updating_selection = True
            try:
                update_selection_model(model, self.selectionModel(),
                                       rows[:abs(value)])
            finally:
                self._updating_selection = False