Пример #1
0
    def _selectionmap(selection):
        sortedselection = sorted(selection,
                                 key=QtCore.QItemSelectionRange.parent)

        selectionmap = {}  # collections.OrderedDict()
        for key, group in itertools.groupby(sortedselection,
                                            QtCore.QItemSelectionRange.parent):
            ranges = []
            for item in sorted(group, key=QtCore.QItemSelectionRange.top):
                if len(ranges) == 0:
                    ranges.append(item)
                    continue
                lastitem = ranges[-1]
                assert lastitem.parent() == item.parent()
                if lastitem.bottom() + 1 >= item.top():
                    model = lastitem.model()
                    topleft = model.index(
                        min(lastitem.top(), item.top()),
                        # min(lastitem.left(), item.left()),
                        0,
                        lastitem.parent())
                    bottomright = model.index(
                        max(lastitem.bottom(), item.bottom()),
                        # max(lastitem.right(), item.right()),
                        model.columnCount() - 1,
                        lastitem.parent())
                    ranges[-1] = QtCore.QItemSelectionRange(
                        topleft, bottomright)
                else:
                    ranges.append(item)
            selectionmap[key] = ranges

        return selectionmap
Пример #2
0
    def _moveSelectionRange(self, selectionrange, dst):
        if selectionrange.top() == dst:
            return selectionrange

        model = selectionrange.model()
        parentindex = selectionrange.parent()
        parentitem = self._parentitem(selectionrange)
        nrows_selected = selectionrange.bottom() - selectionrange.top() + 1
        ncols = model.columnCount()

        if nrows_selected == parentitem.rowCount():
            return selectionrange

        if dst > parentitem.rowCount() - nrows_selected or dst < 0:
            return selectionrange

        selectedrows = self._takeRowsRange(selectionrange)
        for index, items in enumerate(selectedrows):
            parentitem.insertRow(dst + index, items)

        topleft = model.index(dst, 0, parentindex)
        bottomright = model.index(dst + nrows_selected - 1, ncols - 1,
                                  parentindex)

        return QtCore.QItemSelectionRange(topleft, bottomright)
Пример #3
0
 def copy_clicked(self):
     self.logger.debug('clipboard %s' % self.view._qtapp.clipboard().text())
     #self.view.app.clipboard().setText('something here')
     self.logger.debug('selectedIndexes %s' %
                       self.tableview.selectedIndexes())
     #self.view.gui_do(self.copy_clicked_gui_do)
     selection = self.tableview.selectionModel().selection()
     if selection.count() > 0:
         selRangeFirst = selection.first()
         self.logger.debug('first.height %d' % selRangeFirst.height())
         self.logger.debug('first.width  %d' % selRangeFirst.width())
         height = selRangeFirst.height()
         width = selRangeFirst.width()
         string = ''
         for i in range(height):
             for j in range(width):
                 k = i + j * height
                 index = selection.indexes()[k]
                 row = index.row()
                 col = index.column()
                 string += ' ' + str(self.dataForTableModel[row][col])
                 self.logger.debug(
                     'row %d col %d %s' %
                     (row, col, self.dataForTableModel[row][col]))
             string += '\n'
         self.logger.debug(string)
         self.view._qtapp.clipboard().setText(string)
         self.copySelectionRange = QtCore.QItemSelectionRange(selRangeFirst)