class RecordTableView(qt.QTableView): """TableView using DatabaseTableModel as default model. """ def __init__(self, parent=None): """ Constructor :param qt.QWidget parent: parent QWidget """ qt.QTableView.__init__(self, parent) model = _ShowEditorProxyModel(self) model.setSourceModel(RecordTableModel()) self.setModel(model) self.__multilineView = _MultiLineItem(self) self.setEditTriggers(qt.QAbstractItemView.AllEditTriggers) self._copyAction = CopySelectedCellsAction(self) self.addAction(self._copyAction) def copy(self): self._copyAction.trigger() def setArrayData(self, data): self.model().sourceModel().setArrayData(data) if data is not None: if issubclass(data.dtype.type, (numpy.string_, numpy.unicode_)): # TODO it would be nice to also fix fields # but using it only for string array is already very useful self.setItemDelegateForColumn(0, self.__multilineView) self.model().forceCellEditor(True) else: self.setItemDelegateForColumn(0, None) self.model().forceCellEditor(False)
class HexaTableView(qt.QTableView): """TableView using HexaTableModel as default model. It customs the column size to provide a better layout. """ def __init__(self, parent=None): """ Constructor :param qt.QWidget parent: parent QWidget """ qt.QTableView.__init__(self, parent) model = HexaTableModel(self) self.setModel(model) self._copyAction = CopySelectedCellsAction(self) self.addAction(self._copyAction) def copy(self): self._copyAction.trigger() def setArrayData(self, data): """Set the data array. :param data: A numpy object or a dataset. """ self.model().setArrayData(data) self.__fixHeader() def __fixHeader(self): """Update the view according to the state of the auto-resize""" header = self.horizontalHeader() if qt.qVersion() < "5.0": setResizeMode = header.setResizeMode else: setResizeMode = header.setSectionResizeMode header.setDefaultSectionSize(30) header.setStretchLastSection(True) for i in range(0x10): setResizeMode(i, qt.QHeaderView.Fixed) setResizeMode(0x10, qt.QHeaderView.Stretch)