def moveSelectionUp(self, selectionmodel): #assert selectionmodel.model() is self.model selection = selectionmodel.selection() selectionmap = self._selectionmap(selection) newselection = QtCore.QItemSelection() for parent, ranges in selectionmap.items(): for selectionrange in ranges: dst = selectionrange.top() - 1 newrange = self._moveSelectionRange(selectionrange, dst) newselection.append(newrange) selectionmodel.select(newselection, SelectCurrentRows)
def moveSelectionToTop(self, selectionmodel): #assert selectionmodel.model() is self.model selection = selectionmodel.selection() selectionmap = self._selectionmap(selection) newselection = QtCore.QItemSelection() for parent, ranges in selectionmap.items(): dst = 0 for selectionrange in ranges: newrange = self._moveSelectionRange(selectionrange, dst) newselection.append(newrange) dst = newrange.bottom() + 1 selectionmodel.select(newselection, SelectCurrentRows)
def moveSelectionToBottom(self, selectionmodel): #assert selectionmodel.model() is self.model selection = selectionmodel.selection() selectionmap = self._selectionmap(selection) newselection = QtCore.QItemSelection() nrows = selectionmodel.model().rowCount() for parent, ranges in selectionmap.items(): ranges.reverse() dst = nrows for selectionrange in ranges: dst -= selectionrange.height() newrange = self._moveSelectionRange(selectionrange, dst) newselection.append(newrange) selectionmodel.select(newselection, SelectCurrentRows)
def selectAllItems(itemview): '''Select all items in an QAbstractItemView.''' model = itemview.model() topleft = model.index(0, 0) try: bottomright = model.index(model.rowCount() - 1, model.columnCount() - 1) except (TypeError, AttributeError): # columnCount is a private method in QAbstractListModel # assume it is a list bottomright = model.index(model.rowCount() - 1) selection = QtCore.QItemSelection(topleft, bottomright) itemview.selectionModel().select(selection, QtCore.QItemSelectionModel.Select)