def autoSelection(self): selModel = self.ranksView.selectionModel() rowCount = self.ranksModel.rowCount() columnCount = self.ranksModel.columnCount() model = self.ranksProxyModel if self.selectMethod == OWRank.SelectNone: selection = QItemSelection() elif self.selectMethod == OWRank.SelectAll: selection = QItemSelection( model.index(0, 0), model.index(rowCount - 1, columnCount - 1) ) elif self.selectMethod == OWRank.SelectNBest: nSelected = min(self.nSelected, rowCount) selection = QItemSelection( model.index(0, 0), model.index(nSelected - 1, columnCount - 1) ) else: selection = QItemSelection() if len(self.selected_rows): selection = QItemSelection() for row in self.selected_rows: selection.append(QItemSelectionRange( model.index(row, 0), model.index(row, columnCount - 1))) selModel.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() 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)
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)
def select_rows(rows: List[int], widget: OWFeatureStatistics): """Since the widget sorts the rows, selecting rows isn't trivial.""" indices = widget.model.mapToSourceRows(rows) selection = QItemSelection() for idx in indices: selection.append(QItemSelectionRange( widget.model.index(idx, 0), widget.model.index(idx, widget.model.columnCount() - 1) )) widget.table_view.selectionModel().select( selection, QItemSelectionModel.ClearAndSelect)
def set_selection(self): view = self.doc_list if len(self.selection): selection = QItemSelection() for row in self.selection: selection.append( QItemSelectionRange( view.model().index(row, 0), view.model().index(row, 0) ) ) view.selectionModel().select( selection, QItemSelectionModel.ClearAndSelect)
def select_rows(rows: List[int], widget: OWFeatureStatistics): """Since the widget sorts the rows, selecting rows isn't trivial.""" indices = widget.model.mapToSourceRows(rows) selection = QItemSelection() for idx in indices: selection.append( QItemSelectionRange( widget.model.index(idx, 0), widget.model.index(idx, widget.model.columnCount() - 1))) widget.table_view.selectionModel().select( selection, QItemSelectionModel.ClearAndSelect)
def set_selection(self): view = self.doc_list if len(self.selection): selection = QItemSelection() for row in self.selection: selection.append( QItemSelectionRange( view.model().index(row, 0), view.model().index(row, 0) ) ) view.selectionModel().select( selection, QItemSelectionModel.ClearAndSelect)
def update_selection(self): """ Update selected rows (potentially from loaded scheme) at once.""" sel_model = self.ranksView.selectionModel() ncol = self.ranksModel.columnCount() model = self.ranksModel selection = QItemSelection() selected_rows = [self.batch_vars_names.index(b) for b in self.batch_vars_selected.copy() if b in self.batch_vars_names] if len(selected_rows): for row in model.mapFromSourceRows(selected_rows): selection.append(QItemSelectionRange( model.index(row, 0), model.index(row, ncol - 1))) sel_model.select(selection, QItemSelectionModel.ClearAndSelect) else: self.commit()
def __restore_selection(self): """Restore the selection on the table view from saved settings.""" selection_model = self.table_view.selectionModel() selection = QItemSelection() if self.selected_vars: var_indices = { var: i for i, var in enumerate(self.model.variables) } selected_indices = [var_indices[var] for var in self.selected_vars] for row in self.model.mapFromSourceRows(selected_indices): selection.append( QItemSelectionRange( self.model.index(row, 0), self.model.index(row, self.model.columnCount() - 1))) selection_model.select(selection, QItemSelectionModel.ClearAndSelect)
def set_selection(self): if len(self.selected_rows): header_count = self.view.header().count() - 1 if self.view.model().rowCount() <= self.selected_rows[-1]: return selection = QItemSelection() for row_index in self.selected_rows: selection.append( QItemSelectionRange( self.view.model().index(row_index, 0), self.view.model().index(row_index, header_count))) self.view.selectionModel().select( selection, QItemSelectionModel.ClearAndSelect)
def set_selection(self): if self.selected_rows and self.selected_cols: view = self.tabs.currentWidget() model = view.model() if model.rowCount() <= self.selected_rows[-1] or \ model.columnCount() <= self.selected_cols[-1]: return selection = QItemSelection() rowranges = list(ranges(self.selected_rows)) colranges = list(ranges(self.selected_cols)) for rowstart, rowend in rowranges: for colstart, colend in colranges: selection.append( QItemSelectionRange( view.model().index(rowstart, colstart), view.model().index(rowend - 1, colend - 1))) view.selectionModel().select(selection, QItemSelectionModel.ClearAndSelect)
def set_selection(self): if len(self.selected_rows) and len(self.selected_cols): view = self.tabs.currentWidget() model = view.model() if model.rowCount() <= self.selected_rows[-1] or \ model.columnCount() <= self.selected_cols[-1]: return selection = QItemSelection() rowranges = list(ranges(self.selected_rows)) colranges = list(ranges(self.selected_cols)) for rowstart, rowend in rowranges: for colstart, colend in colranges: selection.append( QItemSelectionRange( view.model().index(rowstart, colstart), view.model().index(rowend - 1, colend - 1) ) ) view.selectionModel().select( selection, QItemSelectionModel.ClearAndSelect)
def set_selection(self): if len(self.selected_rows): view = self.data_view model = self.data_model row_model_indexes = [model.indexFromItem(model.item(i)) for i in self.selected_rows] proxy_rows = [self.filter_proxy_model.mapFromSource(i).row() for i in row_model_indexes] if model.rowCount() <= self.selected_rows[-1]: return header_count = view.header().count() - 1 selection = QItemSelection() for row_index in proxy_rows: selection.append( QItemSelectionRange( self.filter_proxy_model.index(row_index, 0), self.filter_proxy_model.index(row_index, header_count), ) ) view.selectionModel().select(selection, QItemSelectionModel.ClearAndSelect)
def autoSelection(self): selModel = self.ranksView.selectionModel() model = self.ranksModel rowCount = model.rowCount() columnCount = model.columnCount() if self.selectionMethod == OWRank.SelectNone: selection = QItemSelection() elif self.selectionMethod == OWRank.SelectAll: selection = QItemSelection( model.index(0, 0), model.index(rowCount - 1, columnCount - 1)) elif self.selectionMethod == OWRank.SelectNBest: nSelected = min(self.nSelected, rowCount) selection = QItemSelection( model.index(0, 0), model.index(nSelected - 1, columnCount - 1)) else: selection = QItemSelection() if len(self.selected_rows): for row in model.mapFromSourceRows(self.selected_rows): selection.append( QItemSelectionRange(model.index(row, 0), model.index(row, columnCount - 1))) selModel.select(selection, QItemSelectionModel.ClearAndSelect)
def _set_selected_words(self, indices: List[int]): selection = QItemSelection() sel_model: QItemSelectionModel = self.words_view.selectionModel() for i in indices: selection.append(QItemSelectionRange(self.words_model.index(i, 0))) sel_model.select(selection, QItemSelectionModel.ClearAndSelect)