def data(self, index, role=None): # logger.debug("index={}, role={}".format(QModelIndex, role)) row, column = index.row(), index.column() if role == Qt.DisplayRole: cell = Cell.get(row, column) return cell.data if cell else None if role == Qt.EditRole: cell = Cell.get(row, column) return str(cell.data) if cell else None if role == Qt.SizeHintRole: return CellModel.CellSize if role == Qt.TextAlignmentRole: column = Column.get(column) if column: if column.type.type == DataType.Numeric: return CellModel.NumericCellAlign
def setData(self, index, data, role=None): row, column = index.row(), index.column() cell = Cell.get(row, column) if not cell: if data: cell = Cell(row, column) cell.data = data self.headerDataChanged.emit(Qt.Horizontal, column, Qt.DisplayRole) ColList.List.reset() else: cell.data = data return True
def execute(self): query = Query(select=self.input.toPlainText()) query.execute() if query.error == Query.NoError: var_name = self.target.text().strip() column = None new_column = False if var_name: logger.debug("var_name={}".format(var_name)) column = Column.get_by_name(var_name) if not column: column = Column(Column.count(), name=var_name) new_column = True logger.debug("new_column={}".format(new_column)) for row, data in query.result.items(): if new_column: Cell(row, column.id, data=data) else: cell = Cell.get(row, column.id) cell.data = data