예제 #1
0
파일: model.py 프로젝트: mlilien/sloth
 def setSelectedItems(self, items):
     #block = self.blockSignals(True)
     sel = QItemSelection()
     for item in items:
         sel.merge(QItemSelection(item.index(), item.index(1)), QItemSelectionModel.SelectCurrent)
     if set(sel) != set(self.selectionModel().selection()):
         self.selectionModel().clear()
         self.selectionModel().select(sel, QItemSelectionModel.Select)
예제 #2
0
파일: model.py 프로젝트: iluxave/sloth
 def setSelectedItems(self, items):
     #block = self.blockSignals(True)
     sel = QItemSelection()
     for item in items:
         sel.merge(QItemSelection(item.index(), item.index(1)),
                   QItemSelectionModel.SelectCurrent)
     if set(sel) != set(self.selectionModel().selection()):
         self.selectionModel().clear()
         self.selectionModel().select(sel, QItemSelectionModel.Select)
    def setSelectionForFindingTypeDetail(self, findingTypeDetail):
        self.setMode = True

        # QMessageBox.warning(None, "not found", u"{0}, '{1}'".format(len(findingTypeDetailList),u",".join(findingTypeDetailList)))
        e = self.uiFindingTypeDetailTableV
        sm = e.selectionModel()
        sm.clearSelection()

        if len(findingTypeDetail) > 0:
            m = self.uiFindingTypeDetailTableV.model()
            rC = m.rowCount()
            selection = QItemSelection()

            notFound = []
            findingTypeDetailList = findingTypeDetail.split(',')
            for detail in findingTypeDetailList:
                found = False
                for r in range(rC):
                    mIdx = m.createIndex(r, m.fieldIndex("befundart_detail"))
                    # QMessageBox.warning(None, "WeatherCode", "{0}={1}".format(m.data(mIdx), weatherCode[i]))
                    if m.data(mIdx).lower() == detail.lower():
                        lIdx = m.createIndex(r, 0)
                        rIdx = m.createIndex(r, m.columnCount() - 1)
                        rowSelection = QItemSelection(lIdx, rIdx)
                        selection.merge(rowSelection,
                                        QItemSelectionModel.Select)
                        found = True
                        break
                if not found:
                    notFound.append(detail)
                sm.select(selection, QItemSelectionModel.Select)
            #QMessageBox.warning(None, "not found", u"{0}".format(len(notFound)))
            if len(notFound) > 0:
                QMessageBox.warning(
                    self, u"Befundart Details",
                    u"Die folgenden Einträge wurden nicht gefunden. Bitte wählen Sie von den verfügbaren Einträgen aus oder fügen Sie diese manuell zur Tabelle 'befundart' hinzu. [{0}]"
                    .format(u", ".join(notFound)))

        self.setMode = False
예제 #4
0
    def mapSelectionToSource(self, selection):  #pylint: disable=invalid-name
        """Reimplemented."""
        source_selection = QItemSelection()

        if not self.sourceModel():
            return source_selection

        source_column_count = self.sourceModel().columnCount()
        for item in selection:
            top_left = item.topLeft()
            top_left = top_left.sibling(top_left.row(), 0)

            bottom_right = item.bottomRight()
            if bottom_right.column() >= source_column_count:
                bottom_right = bottom_right.sibling(bottom_right.row(),
                                                    source_column_count - 1)

            selection_range = QItemSelectionRange(
                self.mapToSource(top_left), self.mapToSource(bottom_right))
            new_selection = []
            new_selection.append(selection_range)
            source_selection.merge(new_selection, QItemSelectionModel.Select)

        return source_selection
예제 #5
0
 def currentChanged(self, current: QModelIndex,
                    previous: QModelIndex) -> None:
     if self.state() == QAbstractItemView.DragSelectingState:
         self.clearSelection()
         if current.row() == self._start.row(
         ):  # we only have one row, select from start to current
             selection = QItemSelection(
                 self._start,
                 self.model().index(self._start.row(), current.column()))
         else:  # more than one row selected make the other 2 selections
             selection = QItemSelection(self._start, current)
             if current.row() < self._start.row():  # stencil out diagonal
                 right = QItemSelection(
                     current, self.index(self._start.row() - 1, 6))
                 left = QItemSelection(self.index(current.row() + 1, 0),
                                       self._start)
                 selection.merge(right, QItemSelectionModel.Select)
                 selection.merge(left, QItemSelectionModel.Select)
                 if current.column() > self._start.column():
                     stencil = QItemSelection(
                         self.index(current.row(),
                                    current.column() - 1),
                         self.index(current.row(), 0))
                     stencil2 = QItemSelection(
                         self.index(self._start.row(),
                                    self._start.column() + 1),
                         self.index(self._start.row(), 6))
                     selection.merge(stencil, QItemSelectionModel.Deselect)
                     selection.merge(stencil2, QItemSelectionModel.Deselect)
             else:
                 right = QItemSelection(self._start,
                                        self.index(current.row() - 1, 6))
                 left = QItemSelection(self.index(self._start.row() + 1, 0),
                                       current)
                 selection.merge(right, QItemSelectionModel.Select)
                 selection.merge(left, QItemSelectionModel.Select)
                 if current.column() < self._start.column(
                 ):  # stencil out diagonal
                     stencil = QItemSelection(
                         self.index(self._start.row(),
                                    self._start.column() - 1),
                         self.index(self._start.row(), 0))
                     stencil2 = QItemSelection(
                         self.index(current.row(),
                                    current.column() + 1),
                         self.index(current.row(), 6))
                     selection.merge(stencil, QItemSelectionModel.Deselect)
                     selection.merge(stencil2, QItemSelectionModel.Deselect)
         self.selectionModel().select(selection, QItemSelectionModel.Select)
예제 #6
0
    def keyPressEvent(self, event):

        key_press = event.key()
        mode = self.selectionModel()
        modifier = event.modifiers()
        ctrl = modifier == Qt.ControlModifier
        shift = modifier == Qt.ShiftModifier
        alt = modifier == Qt.AltModifier

        if alt:

            if self.selectedIndexes() and key_press in (Qt.Key_Return,
                                                        Qt.Key_Enter):

                self.openPersistentEditor()

            else:
                self.parent().keyPressEvent(event)

        elif ctrl:

            if shift:
                if key_press == Qt.Key_A: self.clearSelection()

            elif key_press == Qt.Key_A: self.selectAll()

            elif key_press == Qt.Key_C: self.copy_path()

            else: self.parent().keyPressEvent(event)

        elif key_press in (Qt.Key_Up, Qt.Key_Down, Qt.Key_Right, Qt.Key_Left):

            index = self.currentIndex()
            row1, col1 = index.row(), index.column()
            sign = 1 if key_press in (Qt.Key_Down, Qt.Key_Right) else -1

            if key_press in (Qt.Key_Right, Qt.Key_Left):

                row2 = row1

                if (col1 == 0 and sign < 0) or (col1 == 4 and sign > 0):
                    if not 0 <= (row1 + sign) < self.table.rowCount():
                        return
                    row2 = row1 + sign

                col2 = (col1 + sign) % self.table.columnCount()

            elif key_press in (Qt.Key_Up, Qt.Key_Down):

                col2 = col1

                if not 0 <= (row1 + sign) < self.table.rowCount(): return

                row2 = row1 + sign

            new = self.table.index(row2, col2)

            if shift:

                if row1 == row2: selection = QItemSelection(index, new)

                elif key_press in (Qt.Key_Right, Qt.Key_Left):

                    selection = QItemSelection(index, new)

                elif key_press in (Qt.Key_Up, Qt.Key_Down):

                    start, end = (0, 4) if (sign < 0) else (4, 0)
                    selection = QItemSelection(index,
                                               self.table.index(row1, start))
                    selection.merge(
                        QItemSelection(new, self.table.index(row2, end)),
                        self.selectionModel().Select)

                self.selectionModel().select(selection, mode.Select)
                self.selectionModel().setCurrentIndex(new, mode.NoUpdate)

            else:
                self.setCurrentIndex(new)

        elif key_press in (Qt.Key_PageUp, Qt.Key_PageDown):

            index = self.currentIndex()
            row1, col1 = index.row(), index.column()
            sign = 1 if key_press == Qt.Key_PageDown else -1

            row2 = row1 + (sign * 5)
            if 0 > row2: row2, col2 = 0, 0
            elif row2 > self.table.rowCount():
                row2, col2 = self.table.rowCount() - 1, 4
            else:
                col2 = col1

            new = self.table.index(row2, col2)

            if shift:

                selection = QItemSelection(self.table.index(row1, 4),
                                           self.table.index(row1, col1))
                selection.merge(
                    QItemSelection(self.table.index(row1 + sign, 0),
                                   self.table.index(row2 - sign, 4)),
                    self.selectionModel().Select)
                selection.merge(
                    QItemSelection(self.table.index(row2, col1),
                                   self.table.index(row2, 0)),
                    self.selectionModel().Select)

                self.selectionModel().select(selection, mode.Select)
                self.selectionModel().setCurrentIndex(new, mode.NoUpdate)

            else:
                self.setCurrentIndex(new)

        elif key_press in (Qt.Key_Home, Qt.Key_End):

            sign = 1 if key_press == Qt.Key_End else -1

            row1, col1 = ((0, 0) if sign < 0 else
                          (self.table.rowCount() - 1,
                           (self.total() - 1) % self.table.columnCount()))
            new = self.table.index(row1, col1)

            if shift:

                index = self.currentIndex()
                row2, col2 = index.row(), index.column()

                selection = QItemSelection(self.table.index(index.row(), col1),
                                           index)
                selection.merge(
                    QItemSelection(self.table.index(row2 + sign, 0),
                                   self.table.index(row1 - sign, 4)),
                    self.selectionModel().Select)
                selection.merge(
                    QItemSelection(self.table.index(row1, 0),
                                   self.table.index(row1, 4)),
                    self.selectionModel().Select)

                self.selectionModel().select(selection, mode.Select)
                self.selectionModel().setCurrentIndex(new, mode.NoUpdate)

            else:
                self.setCurrentIndex(new)

        elif key_press in (Qt.Key_Return, Qt.Key_Enter):

            self.load_comic.emit(self.currentIndex())

        else:
            self.parent().parent().keyPressEvent(event)