def setData(self, index: QModelIndex, value, role: int = Qt.EditRole): if role != Qt.EditRole or not index.isValid(): return False row = index.row() col = index.column() colname = self._input_table.columns[col] if colname == STFM.ID.name: value = str(value) else: value = float(value) self._input_table.at[row, colname] = value if self._stream_type == 'hot': self._setup.hot_changed.emit() else: self._setup.cold_changed.emit() self.dataChanged.emit( index.sibling(0, 0), index.sibling(self.rowCount() - 1, self.columnCount() - 1) ) return True
def update_question_type_tools(self, current: QModelIndex = None): if current is not None: self.ui.remove_question_type_button.setDisabled(False) top_index = current.sibling(current.row() - 1, current.column()) bottom_index = current.sibling(current.row() + 1, current.column()) self.ui.move_up_question_type_button.setDisabled(not top_index.isValid()) self.ui.move_down_question_type_button.setDisabled(not bottom_index.isValid()) else: self.ui.remove_question_type_button.setDisabled(True) self.ui.move_up_question_type_button.setDisabled(True) self.ui.move_down_question_type_button.setDisabled(True)
def selectRun(self,index: QModelIndex): print("select row",index.row(),"column",index.column(),"id",index.internalId()) pkIndex=index.sibling(index.row(),0) self.currentRun=self.runsTable.model().data(pkIndex).value() pgmIndex=index.sibling(index.row(),3) self.currentProgram=self.runsTable.model().data(pgmIndex).value() self.currentPlate=None self.currentSample=None self.currentWell=None #self.runsTable.selectRow(index.row()) self.refreshAll()
def setData(self, index: QModelIndex, value, role: int = Qt.EditRole): if role != Qt.EditRole or not index.isValid(): return False row = index.row() col = index.column() if col != 0: self.theta_data.iat[row, col] = float(value) else: return False self.dataChanged.emit(index.sibling(row, 1), index.sibling(row, 2)) return True
def update_question_type_tools(self, current: QModelIndex = None): if current is not None: self.ui.remove_question_type_button.setDisabled(False) top_index = current.sibling(current.row() - 1, current.column()) bottom_index = current.sibling(current.row() + 1, current.column()) self.ui.move_up_question_type_button.setDisabled( not top_index.isValid()) self.ui.move_down_question_type_button.setDisabled( not bottom_index.isValid()) else: self.ui.remove_question_type_button.setDisabled(True) self.ui.move_up_question_type_button.setDisabled(True) self.ui.move_down_question_type_button.setDisabled(True)
def setData(self, index: QModelIndex, value, role: int = Qt.EditRole): if role != Qt.EditRole or not index.isValid(): return False row = index.row() col = index.column() if col == 0: self.variables.at[row, 'Checked'] = True if value == 1 else False self.dataChanged.emit(index.sibling(row, col + 1), index.sibling(row, self.columnCount())) return True return False
def setData(self, Index: QModelIndex, Any, role: int = Qt.EditRole) -> bool: t_inof = self.TabelFieldInfo t_inof.setData(Index, Any) self._setdirty() if self.__isCalculating is False: self.__formulaCacu(Index.row()) # 执行重载函数,判断行数据是否合法 # 给函数参数的值 是最后一行的数据list row_data = t_inof.getRowData(len(t_inof.DataRows) - 1) tempv = self.afterSetDataBeforeInsterRowEvent(row_data, Index) if isinstance(tempv, bool): if tempv: self.insertRows(self.rowCount()) self.afterInsterRowEvent() else: strErr = 'afterSetDataBeforeInsterRowEvent函数的返回值必须为逻辑值!' raise TypeError(strErr) # 回车向右 r, c = Index.row(), Index.column() tmp = None tmp = Index.sibling(r if r == self.rowCount() - 1 else r + 1, 0 if self.columnCount() - 1 else c + 1) if tmp.isValid(): self.editNext.emit(tmp) self.dataChanged[QModelIndex, object].emit(Index, Any) return True
def set_data_from_index(self, index: QModelIndex): """Called by the ImageListItemDelegate to populate the editor with model data.""" image: Image = index.sibling(index.row(), 0).data(Qt.UserRole) self.input_file_path = image.image_path self.output_path = image.output_path self.output_path_line_edit.setText(str(image.output_path)) set_url_label(self.file_name_label, self.input_file_path, self.input_file_path.name) self.selection_count_label.setText(str(len(image.selections)))
def setData(self, index: QModelIndex, value, role: int = Qt.EditRole): if role != Qt.EditRole or not index.isValid(): return False row = index.row() col = index.column() if col == 0: return False else: self.expr_data.iat[row, col - 1] = value self.app_data.expression_table_data = self.expr_data self.dataChanged.emit(index.sibling(0, 0), index.sibling(self.rowCount(), self.columnCount())) self.parent().selectionModel().clearSelection() return True
def setData(self, index: QModelIndex, value, role: int = Qt.EditRole): if role != Qt.EditRole or not index.isValid(): return False row = index.row() col = index.column() mv_df = self.app_data.doe_mv_bounds if col == 1: mv_df.at[row, 'lb'] = float(value) elif col == 2: mv_df.at[row, 'ub'] = float(value) else: return False self.app_data.doe_mv_bounds = mv_df self.dataChanged.emit(index.sibling(row, 1), index.sibling(row, 2)) return True
def load_selections(self, current: QModelIndex): selection_count: int = current.model().rowCount( current) # The number of child nodes, which are selections current_first_column = current.sibling( current.row(), 0) # Selections are below the first column selections: typing.List[Selection] = [ current_first_column.child(index, 0).data(Qt.UserRole) for index in range(selection_count) ] editor_logger.debug(f"Loading selection list: {selections}") for selection in selections: self._draw_rectangle(current, selection)
def setData(self, index: QModelIndex, value, role: int = Qt.EditRole): if role != Qt.EditRole or not index.isValid(): return False row = index.row() col = index.column() if self.dof_info.columns[col] == 'Checked': value = True if value == 1 else False # change corresponding data in app storage self.app_data.reduced_space_dof.iat[row, col] = value self.app_data.reduced_space_dof_changed.emit() # update the entire row self.dataChanged.emit(index.sibling(row, 0), index.sibling(row, self.columnCount() - 1)) return True else: return False
def setData(self, index: QModelIndex, value, role: int = Qt.EditRole): if role != Qt.EditRole or not index.isValid(): return False row = index.row() col = index.column() if self.variable_data.columns[col] in self.app_data._ALIAS_COLS: self.variable_data.iat[row, col] = value if self.mode == 'input': self.app_data.input_table_data = self.variable_data else: self.app_data.output_table_data = self.variable_data else: return False self.dataChanged.emit(index.sibling(0, col), index.sibling(self.rowCount(), col)) self.parent().selectionModel().clearSelection() return True
def setData(self, index: QModelIndex, value, role: int = Qt.EditRole): if role != Qt.EditRole: return False if index.isValid(): row = index.row() col = index.column() if col == 0: self.variable_data[row]['Path'] = value elif col == 1: self.variable_data[row]['Alias'] = value elif col == 2: self.variable_data[row]['Type'] = value else: return False self.data_changed_signal.emit() self.dataChanged.emit(index.sibling(0, col), index.sibling(self.rowCount(), col)) return True return False
def setData(self, index: QModelIndex, value, role: int = Qt.EditRole): if role != Qt.EditRole or not index.isValid(): return False row = index.row() col = index.column() expr_data = self.expr_data[row] if col == self._EXPR_NAME_COL: expr_data['Name'] = value elif col == self._EXPR_EXPR_COL: expr_data['Expr'] = value elif col == self._EXPR_TYPE_COL: expr_data['Type'] = value else: return False self.app_data.expr_data_changed.emit() self.dataChanged.emit( index.sibling(0, 0), index.sibling(self.rowCount(), self.columnCount())) return True
def _from_local_coordinates(self, image_index: QModelIndex, rectangle: QRectF) -> Selection: """ Scales a floating point rectangle from local coordinates to an integer based rectangle in the source image coordinates. """ image = image_index.sibling(image_index.row(), 0).data(Qt.UserRole) image_width: int = image.width scaling_factor = image_width / self.scene().width() return Selection( Point(round(rectangle.left() * scaling_factor), round(rectangle.top() * scaling_factor)), Point(round(rectangle.right() * scaling_factor), round(rectangle.bottom() * scaling_factor)), image)
def on_active_image_changed(self, current: QModelIndex, previous: QModelIndex): """ This slot gets called, if the currently active image changes. The function updates the root index, so that the list view shows the selections for the newly active image. """ logger.debug( f"Selection changed. " f"current: isValid={current.isValid()}, column={current.column()}, row={current.row()}; " f"previous: isValid={previous.isValid()}, column={previous.column()}, row={previous.row()}" ) # Be safe and map all indices to the first column. if current.column(): current = current.sibling(current.row(), 0) if self.model() is None: super(SelectionListView, self).setModel(self._model) if current.isValid(): super(SelectionListView, self).setRootIndex(current)
def activateNext(self): """Select and activate next item If an item is selected in this LocationList, selects the next item and activates it. If no item was currently select, uses the first element. """ count = self.model().rowCount() if not count: return current = self.currentIndex() if not current.isValid(): current = QModelIndex(0, 0) elif current.row() < count - 1: current = current.sibling(current.row() + 1, 0) else: return self.setCurrentIndex(current) self.activated.emit(current)
def _to_local_coordinates(self, current: QModelIndex, rectangle: Selection) -> QRectF: """ Scales a model Selection to local coordinates. Large images are scaled down, so the rectangles need to be scaled, too. This function performs the scaling and conversion to floating point based rectangles, as expected by QGraphicsView. """ scaling_factor: float = self.width() / current.sibling( current.row(), 0).data(Qt.UserRole).width if scaling_factor >= 1: result = rectangle.as_qrectf else: result = QRectF(rectangle.top_left.x * scaling_factor, rectangle.top_left.y * scaling_factor, rectangle.width * scaling_factor, rectangle.height * scaling_factor) scene_logger.debug( f"Scaled {rectangle} to {result.topLeft(), result.bottomRight()}" ) return result