Esempio n. 1
0
 def currentGroupSelection(self):
     """
     Return the item selection for the current group only.
     """
     if self.values_view.selectionModel() is not None:
         return self.values_view.selectionModel().selection()
     else:
         return QItemSelection()
Esempio n. 2
0
 def setSelectedItems(self, inds: Iterable[int]):
     """Set and select the `inds` indices"""
     model = self.model()
     selection = QItemSelection()
     sym_ranges = to_ranges(ranges(inds))
     for rows, cols in product(sym_ranges, sym_ranges):
         qitemselection_select_range(selection, model, rows, cols)
     self.select(selection, QItemSelectionModel.ClearAndSelect)
Esempio n. 3
0
 def __filter_rowsAboutToBeRemoved(self, parent: QModelIndex, start: int,
                                   end: int) -> None:
     fmodel = self.__pmodel
     mrange = QItemSelection(fmodel.index(start, 0, parent),
                             fmodel.index(end, 0, parent))
     mranges = fmodel.mapSelectionToSource(mrange)
     for mrange in mranges:
         self.__filter_set(range(mrange.top(), mrange.bottom() + 1), True)
Esempio n. 4
0
    def select(self, selection: Union[QItemSelection, QModelIndex],
               flags: QItemSelectionModel.SelectionFlags) -> None:
        """Reimplemented."""
        if isinstance(selection, QModelIndex):
            selection = QItemSelection(selection, selection)

        if not self.__selectBlocks:
            super().select(selection, flags)
            return

        model = self.model()

        if flags & QItemSelectionModel.Current:  # no current selection support
            flags &= ~QItemSelectionModel.Current
        if flags & QItemSelectionModel.Toggle:  # no toggle support either
            flags &= ~QItemSelectionModel.Toggle
            flags |= QItemSelectionModel.Select

        if flags == QItemSelectionModel.ClearAndSelect:
            # extend selection ranges in `selection` to span all row/columns
            sel_rows = selection_rows(selection)
            sel_cols = selection_columns(selection)
            selection = QItemSelection()
            for row_range, col_range in \
                    product(to_ranges(sel_rows), to_ranges(sel_cols)):
                qitemselection_select_range(selection, model, row_range,
                                            col_range)
        elif flags & (QItemSelectionModel.Select
                      | QItemSelectionModel.Deselect):
            # extend all selection ranges in `selection` with the full current
            # row/col spans
            rows, cols = selection_blocks(self.selection())
            sel_rows = selection_rows(selection)
            sel_cols = selection_columns(selection)
            ext_selection = QItemSelection()
            for row_range, col_range in \
                    product(to_ranges(rows), to_ranges(sel_cols)):
                qitemselection_select_range(ext_selection, model, row_range,
                                            col_range)
            for row_range, col_range in \
                    product(to_ranges(sel_rows), to_ranges(cols)):
                qitemselection_select_range(ext_selection, model, row_range,
                                            col_range)
            selection.merge(ext_selection, QItemSelectionModel.Select)
        super().select(selection, flags)
Esempio n. 5
0
    def move_rows(self, view, rows, offset):
        model = view.model()
        newrows = [min(max(0, row + offset), len(model) - 1) for row in rows]

        for row, newrow in sorted(zip(rows, newrows), reverse=offset > 0):
            model[row], model[newrow] = model[newrow], model[row]

        selection = QItemSelection()
        for nrow in newrows:
            index = model.index(nrow, 0)
            selection.select(index, index)
        view.selectionModel().select(selection,
                                     QItemSelectionModel.ClearAndSelect)
 def __restore_selection(self):
     """Restore the selection on the table view from saved settings."""
     selection_model = self.table_view.selectionModel()
     selection = QItemSelection()
     # self.selected_rows can be list or numpy.array, thus
     # pylint: disable=len-as-condition
     if len(self.selected_rows):
         for row in self.model.mapFromSourceRows(self.selected_rows):
             selection.append(QItemSelectionRange(
                 self.model.index(row, 0),
                 self.model.index(row, self.model.columnCount() - 1)
             ))
     selection_model.select(selection, QItemSelectionModel.ClearAndSelect)