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 QtCore.QItemSelection()
def __restoreSelection(self): # Restore previous selection for root (if available) assert self.__model is not None groupind = self.__currentIndex root = self.__model.index(groupind, 0) sel = self.__selections.get(groupind, []) indices = [ self.__model.index(pind.row(), pind.column(), root) for pind in sel if pind.isValid() and pind.parent() == root ] selection = QtCore.QItemSelection() for ind in indices: selection.select(ind, ind) self.values_view.selectionModel().select( selection, QtCore.QItemSelectionModel.ClearAndSelect)
def itemselection(modelindexlist): """ Return an QtCore.QItemSelection from QModelIndex list Parameters ---------- modelindexlist : list of QtCore.QModelIndex Selected model indices. Returns ------- selection : QtCore.QItemSelection """ selection = QtCore.QItemSelection() for index in modelindexlist: selection.select(index, index) return selection
def selection(self): """ Return the item selection. Returns ------- selection : QtCore.QItemSelection """ selection = QtCore.QItemSelection() if self.__model is None: return selection for pind in chain(*self.__selections.values()): ind = self.__model.index(pind.row(), pind.column(), pind.parent()) if ind.isValid(): selection.select(ind, ind) return selection