예제 #1
0
 def _setItemRangeSelected(self, startIndex, endIndex, selected):
     """
     Protected method to set the selection status of a range of items.
     
     @param startIndex start index of range of items to set (QModelIndex)
     @param endIndex end index of range of items to set (QModelIndex)
     @param selected flag giving the new selection status (boolean)
     """
     selection = QItemSelection(startIndex, endIndex)
     self.selectionModel().select(
         selection, selected and self.SelectFlags or self.DeselectFlags)
예제 #2
0
 def synchronize_selection(self, from_list: QListView, to_list: QListView):
     source_selection_model: QItemSelectionModel = from_list.selectionModel()
     destination_selection_model: QItemSelectionModel = to_list.selectionModel()
     rows = source_selection_model.selectedRows()
     if len(rows) > 0:
         idx = [r.row() for r in rows]
         min_idx, max_idx = min(idx), max(idx)
         top_index = QModelIndex(to_list.model().index(min_idx, 0))
         bottom_index = QModelIndex(to_list.model().index(max_idx, 0))
         destination_selection_model.select(QItemSelection(top_index, bottom_index),
                                            QItemSelectionModel.ClearAndSelect)
    def display_firmware_list(self):
        """Display list of firmwares available for the currently selected hw type."""

        def item(value):
            i = QTableWidgetItem(value)
            i.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsEditable)
            return i

        self.selected_firmware_source_web = None
        self.hw_firmware_web_sources_cur_hw.clear()

        if self.cur_hw_device:
            for f in self.hw_firmware_web_sources_all:
                if f.device == self.cur_hw_device.hw_type and \
                        (self.cur_hw_device.hw_type != HWType.trezor or
                         self.cur_hw_device.model_symbol == f.model):
                    self.hw_firmware_web_sources_cur_hw.append(f)

        self.tabFirmwareWebSources.setRowCount(len(self.hw_firmware_web_sources_cur_hw))
        for row, f in enumerate(self.hw_firmware_web_sources_cur_hw):
            if f.testnet_support:
                testnet = 'Yes'
            else:
                testnet = 'No'
            if f.official:
                official = 'Yes'
            else:
                official = 'Custom/Unofficial'

            if f.device == HWType.trezor:
                if f.model == '1':
                    model = 'Trezor One'
                else:
                    model = 'Trezor T'
            else:
                model = str(f.model)

            self.tabFirmwareWebSources.setItem(row, 0, item(f.version))
            self.tabFirmwareWebSources.setItem(row, 1, item(model))
            self.tabFirmwareWebSources.setItem(row, 2, item(official))
            self.tabFirmwareWebSources.setItem(row, 3, item(testnet))

        self.tabFirmwareWebSources.resizeColumnsToContents()
        if len(self.hw_firmware_web_sources_cur_hw) > 0:
            self.tabFirmwareWebSources.selectRow(0)
            # self.on_tabFirmwareWebSources_itemSelectionChanged isn't always fired up if there was previously
            # selected row, so we need to force selecting new row:
            self.select_firmware(0)
        else:
            sm = self.tabFirmwareWebSources.selectionModel()
            s = QItemSelection()
            sm.select(s, QItemSelectionModel.Clear | QItemSelectionModel.Rows)
            # force deselect firmware:
            self.select_firmware(-1)
예제 #4
0
    def _apply_selection_to_full_row(self):
        rows = list()
        selection = QItemSelection()
        for idx in self.selectedIndexes():
            if idx.row() not in rows:
                rows.append(idx.row())
                selection.append(QItemSelectionRange(idx))

        self.selectionModel().select(
            selection,
            QItemSelectionModel.Rows | QItemSelectionModel.ClearAndSelect)
예제 #5
0
 def _set_selection(self, row_list):
     selection = QItemSelection()
     model = self.table.model()
     for row in row_list:
         if self._reverse_order:
             row = len(self._config_dictionaries) - row - 1
         index = model.index(row, 0)
         selection.select(index, index)
     self.table.selectionModel().select(
         selection, QItemSelectionModel.Rows
         | QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Current)
예제 #6
0
    def setSelection(self, rect, command):
        # Use content widget coordinates because we will use the itemRegion()
        # function to check for intersections.

        contentsRect = rect.translated(
            self.horizontalScrollBar().value(),
            self.verticalScrollBar().value()).normalized()

        rows = self.model().rowCount(self.rootIndex())
        columns = self.model().columnCount(self.rootIndex())
        indexes = []

        for row in range(rows):
            for column in range(columns):
                index = self.model().index(row, column, self.rootIndex())
                region = self.itemRegion(index)
                if not region.intersect(QRegion(contentsRect)).isEmpty():
                    indexes.append(index)

        if len(indexes) > 0:
            firstRow = indexes[0].row()
            lastRow = indexes[0].row()
            firstColumn = indexes[0].column()
            lastColumn = indexes[0].column()

            for i in range(1, len(indexes)):
                firstRow = min(firstRow, indexes[i].row())
                lastRow = max(lastRow, indexes[i].row())
                firstColumn = min(firstColumn, indexes[i].column())
                lastColumn = max(lastColumn, indexes[i].column())

            selection = QItemSelection(
                self.model().index(firstRow, firstColumn, self.rootIndex()),
                self.model().index(lastRow, lastColumn, self.rootIndex()))
            self.selectionModel().select(selection, command)
        else:
            noIndex = QModelIndex()
            selection = QItemSelection(noIndex, noIndex)
            self.selectionModel().select(selection, command)

        self.update()
예제 #7
0
 def _restoreSelection(self):
     newSelection = QItemSelection()
     for index in self.model.selected_indexes:
         newSelection.select(self.createIndex(index, 0),
                             self.createIndex(index, 0))
     self.view.selectionModel().select(newSelection,
                                       QItemSelectionModel.ClearAndSelect)
     if len(newSelection.indexes()):
         currentIndex = newSelection.indexes()[0]
         self.view.selectionModel().setCurrentIndex(
             currentIndex, QItemSelectionModel.Current)
         self.view.scrollTo(currentIndex)
    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
 def on_btnCheckAll_clicked(self):
     sel = self.tableView.selectionModel()
     # block_old = sel.blockSignals(True)
     sel_modified = False
     s = QItemSelection()
     for row_idx, utxo in enumerate(self.utxos):
         index = self.table_model.index(row_idx, 0)
         if not utxo['coinbase_locked'] and not utxo.get('spent_date'):
             if not sel.isSelected(index):
                 sel_modified = True
                 s.select(index, index)
     if sel_modified:
         sel.select(s, QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows)
    def selectionFilter(self, selected_items: QItemSelection,
                        deselected_items: QItemSelection):
        """Disables selections of items not in the active filter set.
        I had issues with segfaults subclassing QItemSelectionModel so
        this is the next best thing I think
        """

        # NOTE: prevent selection when select is not pressed
        is_not_select_tool = not self._window.action_global_select.isChecked()

        document = self._document
        # print("!!!!!!!!filter", len(selected_items), len(deselected_items))
        if self.selection_filter_disabled:
            return
        filter_set = document.filter_set
        filter_set.add('part')
        out_deselection = []
        out_selection = []
        flags = QItemSelectionModel.Current | QItemSelectionModel.Deselect
        for index in selected_items.indexes():
            item = self.itemFromIndex(index)
            if is_not_select_tool or item.FILTER_NAME not in filter_set:
                if index.column() == 0:
                    # print("deselect", item.FILTER_NAME, filter_set,
                    #                     index.row(), index.column())
                    out_deselection.append(index)
            else:
                out_selection.append(index)
        sm = self.selectionModel()
        if len(out_deselection) > 0:
            self.indexFromItem(item)
            deselection = QItemSelection(out_deselection[0],
                                         out_deselection[-1])
            sm.blockSignals(True)
            sm.select(deselection, flags)
            sm.blockSignals(False)

        # now group the indices into items in sets
        tbs, tbd = self.model_selection_changes
        # print("sets:", tbs, tbd)
        for idx in out_selection:
            item = self.itemFromIndex(idx)
            # print("did select", item)
            tbs.add(item)
        for idx in deselected_items.indexes():
            # print("could deselect?", self.itemFromIndex(idx))
            item = self.itemFromIndex(idx)
            if item not in tbd and item.isModelSelected(document):
                tbd.add(item)
        self.processSelections(deselect_only=True)
예제 #11
0
 def _updateViewSelection(self):
     # Takes the selection on the model's side and update the view with it.
     newSelection = QItemSelection()
     columnCount = self.columnCount(QModelIndex())
     for index in self.model.selected_indexes:
         newSelection.select(self.createIndex(index, 0),
                             self.createIndex(index, columnCount - 1))
     self.view.selectionModel().select(newSelection,
                                       QItemSelectionModel.ClearAndSelect)
     if len(newSelection.indexes()):
         currentIndex = newSelection.indexes()[0]
         self.view.selectionModel().setCurrentIndex(
             currentIndex, QItemSelectionModel.Current)
         self.view.scrollTo(currentIndex)
예제 #12
0
    def selectTilesInStamp(self, stamp):
        if self.mEmittingStampCaptured:
            return
        processed = QSet()
        selections = QMap()
        for variation in stamp.variations():
            tileLayer = variation.tileLayer()
            for cell in tileLayer:
                tile = cell.tile
                if tile:
                    if (processed.contains(tile)):
                        continue
                    processed.insert(tile)  # avoid spending time on duplicates
                    tileset = tile.tileset()
                    tilesetIndex = self.mTilesets.indexOf(
                        tileset.sharedPointer())
                    if (tilesetIndex != -1):
                        view = self.tilesetViewAt(tilesetIndex)
                        if (not view.model()):  # Lazily set up the model
                            self.setupTilesetModel(view, tileset)
                        model = view.tilesetModel()
                        modelIndex = model.tileIndex(tile)
                        selectionModel = view.selectionModel()

                        _x = QItemSelection()
                        _x.select(modelIndex, modelIndex)
                        selections[selectionModel] = _x

        if (not selections.isEmpty()):
            self.mSynchronizingSelection = True
            # Mark captured tiles as selected
            for i in selections:
                selectionModel = i[0]
                selection = i[1]
                selectionModel.select(selection,
                                      QItemSelectionModel.SelectCurrent)

            # Show/edit properties of all captured tiles
            self.mMapDocument.setSelectedTiles(processed.toList())
            # Update the current tile (useful for animation and collision editors)
            first = selections.first()
            selectionModel = first[0]
            selection = first[1]
            currentIndex = QModelIndex(selection.first().topLeft())
            if (selectionModel.currentIndex() != currentIndex):
                selectionModel.setCurrentIndex(currentIndex,
                                               QItemSelectionModel.NoUpdate)
            else:
                self.currentChanged(currentIndex)
            self.mSynchronizingSelection = False
def main():
    import sys
    app = QApplication(sys.argv)

    v = QTreeView()
    model = TreeModel(utils.find_data_file('disease_num2name.p'), 'Disease')
    v.setModel(model)
    v.selectionModel().select(
        QItemSelection(model.index(0, 0), model.index(5, 0)),
        QItemSelectionModel.Select)
    v.setSelectionMode(QAbstractItemView.NoSelection)
    v.setEditTriggers(QAbstractItemView.NoEditTriggers)
    v.show()
    app.exec()
예제 #14
0
def update_selection_model(model, sm, new_selection):
    """Updates the selection model with new_selection
    """
    current = set(i.row() for i in sm.selectedIndexes())
    new_selection = set(new_selection)

    # Select contiguous blocks
    for row, count in contiguous(sorted(new_selection.difference(current))):
        top_left = model.index(row, 0)
        bottom_right = model.index(row + count - 1, 0)
        sm.select(QItemSelection(top_left, bottom_right),
                  QItemSelectionModel.Select)

    # Deselect contiguous blocks
    for row, count in contiguous(sorted(current.difference(new_selection))):
        top_left = model.index(row, 0)
        bottom_right = model.index(row + count - 1, 0)
        sm.select(QItemSelection(top_left, bottom_right),
                  QItemSelectionModel.Deselect)

    if new_selection:
        # Set an arbitrary row as the current index
        sm.setCurrentIndex(model.index(new_selection.pop(), 0),
                           QItemSelectionModel.Current)
예제 #15
0
 def setChanged(self,
                topLeft: QModelIndex,
                bottomRight: QModelIndex = None):
     """Set the item and all parents as changed"""
     bottomRight = topLeft if bottomRight is None else bottomRight
     if topLeft.isValid() and bottomRight.isValid():
         selection = QItemSelection(topLeft, bottomRight)
         for index in selection.indexes():
             self.objByIndex(index).changed = True
             if index.parent().isValid():
                 self.setChanged(index.parent())
             else:
                 packItem: QModelIndex = index.data(PACK_ITEM_ROLE)
                 if packItem and packItem.isValid():
                     packItem.model().dataChanged.emit(packItem, packItem)
    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 = QItemSelection()
        for ind in indices:
            selection.select(ind, ind)
        self.values_view.selectionModel().select(
            selection, QItemSelectionModel.ClearAndSelect)
 def dataChangedSlot(self, top_left: QModelIndex , bottom_right: QModelIndex):
     if self.is_child_adding == 0:
         if top_left == bottom_right:    # single item
             item = self.itemFromIndex(top_left)
             if isinstance(item, (OutlineVirtualHelixItem, OutlineNucleicAcidPartItem, OutlineOligoItem)):
                 # print("dataChanged", item.__class__.__name__)
                 item.updateCNModel()
         else:
             selection = QItemSelection(top_left, bottom_right)
             for index in selection.indexes():
                 if index.column() == 0:
                     item = self.itemFromIndex(index)
                     # if isinstance(item, OutlineVirtualHelixItem):
                     #     print("slap", item.idNum())
                     if isinstance(item, (OutlineVirtualHelixItem, OutlineNucleicAcidPartItem, OutlineOligoItem)):
                         item.updateCNModel()
def itemselection(modelindexlist):
    """
    Return an QtCore.QItemSelection from QModelIndex list

    Parameters
    ----------
    modelindexlist : list of QtCore.QModelIndex
        Selected model indices.

    Returns
    -------
    selection : QtCore.QItemSelection
    """
    selection = QItemSelection()
    for index in modelindexlist:
        selection.select(index, index)
    return selection
    def selection(self):
        """
        Return the item selection.

        Returns
        -------
        selection : QtCore.QItemSelection
        """
        selection = 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
예제 #20
0
    def presetsIndexChanged(self, idx):
        self.savePreset.setEnabled(idx > 0)
        self.clearPreset.setEnabled(idx > 0)
        categories = self.presetModel.categoriesAtIndex(idx)
        selm = self.categoryList.selectionModel()
        cmodel = self.categoryList.model()
        catidxs = [
            cmodel.createIndex(row, 0, None)
            for row in range(cmodel.rowCount(None))
        ]

        qis = QItemSelection()
        for cidx in catidxs:
            if cmodel.idAtRow(cidx.row()) in categories:
                qir = QItemSelectionRange(cidx)
                qis.append(qir)
        selm.select(qis, QItemSelectionModel.ClearAndSelect)
예제 #21
0
    def onSetPosition(self):
        """Activate screen rectangle selector"""
        ci = self.tableView.selectionModel().currentIndex()
        if not ci.isValid():
            s = self.model.index(0, 0)
            e = self.model.index(0, len(VideoModel.headers) - 1)
            selection = QItemSelection(s, e)
            self.tableView.selectionModel().select(
                selection, QItemSelectionModel.SelectCurrent)
            ci = self.tableView.selectionModel().currentIndex()
        if not ci.isValid():
            QMessageBox.warning(self, 'Not selected', 'None row is selected')
            self.actionSet_Position.setChecked(False)
            return

        self.rubberBandActive = True
        self.grabMouse()
        return True
예제 #22
0
 def select_row(self,
                row,
                scroll_hint: QAbstractItemView.
                ScrollHint = QAbstractItemView.EnsureVisible):
     if 0 <= row < self.widgetSpectrumDetails.model().rowCount():
         index = self.widgetSpectrumDetails.model().index(row, 0)
         if index.data(role=SpectraModel.TypeRole) == 'standards':
             parent = self.tvSpectra.model().index(0, 0)
         else:
             parent = self.tvSpectra.model().index(1, 0)
         index_first = self.tvSpectra.model().index(row, 0, parent=parent)
         index_last = self.tvSpectra.model().index(
             row, self.tvSpectra.model().columnCount() - 1, parent=parent)
         self.tvSpectra.selectionModel().select(
             QItemSelection(index_first, index_last),
             QItemSelectionModel.Select)
         self.on_selection_changed(index_first)
         self.tvSpectra.scrollTo(index_first, scroll_hint)
예제 #23
0
    def handle_delete(self):
        """Handle delete key press.

        On delete key press, delete the selection.
        """
        race_table_model = self.modeldb.race_table_model

        item_selection = self.selectionModel().selection()
        selection_list = self.selectionModel().selectedRows()

        # Remove rows from large to small, because the rows are removed
        # immediately, and cause the rest of the rows to shift, invalidating
        # any row number that's higher than the currently removed one.
        selection_list.sort(key=lambda selection: selection.row(),
                            reverse=True)
        for selection in selection_list:
            record = self.source_model.record(selection.row())

            reference_datetime = race_table_model.get_reference_clock_datetime(
            )
            bib = record.value(ResultTableModel.SCRATCHPAD)
            msecs = record.value(ResultTableModel.FINISH)
            finish = reference_datetime.addMSecs(msecs).toString(
                defaults.DATETIME_FORMAT)

            self.journal.log('Result with bib "%s" and time "%s" deleted.' %
                             (bib, finish))

            self.source_model.removeRow(selection.row())

        # Model retains blank rows until we select() again.
        self.modeldb.result_table_model.select()

        # Selection changed because of this deletion, but for some reason,
        # this widget class doesn't emit the selectionChanged signal in this
        # case. Let's emit it ourselves.
        #
        # Not gonna bother calculating selected and deselected. Hopefully,
        # slots that receive this signal won't care...
        self.selectionModel().selectionChanged.emit(QItemSelection(),
                                                    item_selection)

        # Emit resultDeleted signal.
        self.resultDeleted.emit()
예제 #24
0
 def select(self, uuids, lbox: QTreeView = None, scroll_to_show_single=True):
     lbox = self.current_set_listbox if lbox is None else lbox
     lbox.clearSelection()
     if not uuids:
         return
     # FUTURE: this is quick and dirty
     rowdict = dict((u, i) for i, u in enumerate(self.doc.current_layer_uuid_order))
     items = QItemSelection()
     q = None
     for uuid in uuids:
         row = rowdict.get(uuid, None)
         if row is None:
             LOG.error('UUID {} cannot be selected in list view'.format(uuid))
             continue
         q = self.createIndex(row, 0)
         items.select(q, q)
         lbox.selectionModel().select(items, QItemSelectionModel.Select)
         # lbox.setCurrentIndex(q)
     if scroll_to_show_single and len(uuids) == 1 and q is not None:
         lbox.scrollTo(q)
예제 #25
0
    def start_row_index(self, row_index: int):
        """Receive signal that a new row in table has started, so we can highlight it"""

        # Create a selection corresponding to this row in the table
        self._signal_mutex.lock()
        selection: QItemSelection = QItemSelection()
        model_index_top_left: QModelIndex = self._table_model.createIndex(
            row_index, 0)
        model_index_bottom_right: QModelIndex = \
            self._table_model.createIndex(row_index,
                                          WorkItemTableModel.NUMBER_OF_COLUMNS - 1)
        selection.select(model_index_top_left, model_index_bottom_right)
        # Set the selection to that row so it highlights
        selection_model: QItemSelectionModel = self.ui.sessionTable.selectionModel(
        )
        selection_model.clearSelection()
        selection_model.select(selection, QItemSelectionModel.Select)
        # Scroll to ensure the selected row is in view
        self.ui.sessionTable.scrollTo(model_index_top_left)
        self._signal_mutex.unlock()
예제 #26
0
    def onUploadButtonUpRow(self):
        if self.rowsSelected != None:
            self.layoutAboutToBeChanged.emit()
            rowSelected = self.rowsSelected[0]
            if rowSelected != 0:
                temp = self._videos[rowSelected]
                self._videos[rowSelected] = self._videos[rowSelected - 1]
                self._videos[rowSelected - 1] = temp

                temp = self._subs[rowSelected]
                self._subs[rowSelected] = self._subs[rowSelected - 1]
                self._subs[rowSelected - 1] = temp
            self.layoutChanged.emit()
            previousRowSelection = QItemSelection(
                self.createIndex(rowSelected - 1, UploadListView.COL_VIDEO),
                self.createIndex(rowSelected - 1, UploadListView.COL_SUB))
            self._main.uploadSelectionModel.select(
                previousRowSelection,
                self._main.uploadSelectionModel.ClearAndSelect)

        self._main.updateButtonsUpload()
예제 #27
0
    def onUploadButtonDownRow(self):
        if self.rowsSelected != None:
            self.layoutAboutToBeChanged.emit()
            rowSelected = self.rowsSelected[0]
            if rowSelected != self.getTotalRows() - 1:
                temp = self._videos[rowSelected]
                self._videos[rowSelected] = self._videos[rowSelected + 1]
                self._videos[rowSelected + 1] = temp

                temp = self._subs[rowSelected]
                self._subs[rowSelected] = self._subs[rowSelected + 1]
                self._subs[rowSelected + 1] = temp

            self.layoutChanged.emit()
            nextRowSelection = QItemSelection(
                self.index(rowSelected + 1, UploadListView.COL_VIDEO),
                self.index(rowSelected + 1, UploadListView.COL_SUB))
            self._main.uploadSelectionModel.select(
                nextRowSelection,
                self._main.uploadSelectionModel.ClearAndSelect)
        self._main.updateButtonsUpload()
예제 #28
0
    def _sync_api_selection_to_grid(self, rows: list[int],
                                    changed: bool) -> None:
        if not self.model():
            return
        if self._collect_rows() == self._api.subs.selected_indexes:
            return
        self.setUpdatesEnabled(False)

        self.selectionModel().selectionChanged.disconnect(
            self._sync_grid_selection_to_api)

        selection = QItemSelection()
        for row in self._api.subs.selected_indexes:
            idx = self.model().index(row, 0)
            selection.select(idx, idx)

        self.selectionModel().clear()

        if self._api.subs.selected_indexes:
            first_row = self._api.subs.selected_indexes[0]
            cell_index = self.model().index(first_row, 0)
            self.setCurrentIndex(cell_index)
            self.scrollTo(cell_index)

        self.selectionModel().select(
            selection,
            QItemSelectionModel.SelectionFlag(
                QItemSelectionModel.SelectionFlag.Rows
                | QItemSelectionModel.SelectionFlag.Current
                | QItemSelectionModel.SelectionFlag.Select),
        )

        self.selectionModel().selectionChanged.connect(
            self._sync_grid_selection_to_api)

        self.setUpdatesEnabled(True)
예제 #29
0
 def select_row(self, style):
     selectionModel = self.list.selectionModel()
     parent = QModelIndex()
     self.rows = self.model.rowCount(parent) - 1
     if style == 'last':
         self.row = self.rows
     elif style == 'up':
         if self.row > 0:
             self.row -= 1
         else:
             self.row = self.rows
     elif style == 'down':
         if self.row < self.rows:
             self.row += 1
         else:
             self.row = 0
     else:
         return
     top = self.model.index(self.row, 0, parent)
     bottom = self.model.index(self.row, 0, parent)
     selectionModel.setCurrentIndex(top, QItemSelectionModel.Select | QItemSelectionModel.Rows)
     selection = QItemSelection(top, top)
     selectionModel.clearSelection()
     selectionModel.select(selection, QItemSelectionModel.Select)
예제 #30
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