waveform: changes

This commit is contained in:
Simon Renblad 2024-01-22 15:55:29 +08:00
parent 4d97cb5426
commit 70f374c293

View File

@ -445,27 +445,27 @@ class _WaveformView(QtWidgets.QWidget):
self._model.rowsInserted.connect(self.onInsert) self._model.rowsInserted.connect(self.onInsert)
self._model.rowsRemoved.connect(self.onRemove) self._model.rowsRemoved.connect(self.onRemove)
self._model.rowsMoved.connect(self.onMove) self._model.rowsMoved.connect(self.onMove)
def onDataChange(self, top, bottom, roles): def onDataChange(self, top, bottom, roles):
first = top.row() first = top.row()
last = bottom.row() last = bottom.row()
for i in range(first, last + 1): for i in range(first, last + 1):
data = self._model.data(self._model.index(i, 2)) data = self._model.data(self._model.index(i, 2))
self._splitter.widget(i).onDataChange(data) self._splitter.widget(i).onDataChange(data)
def onInsert(self, parent, first, last): def onInsert(self, parent, first, last):
for i in range(first, last + 1): for i in range(first, last + 1):
w = self._create_waveform(self.index(i, 0)) w = self._create_waveform(self.index(i, 0))
self.splitter.insertWidget(i, w) self.splitter.insertWidget(i, w)
self._resize() self._resize()
def onRemove(self, parent, first, last): def onRemove(self, parent, first, last):
for i in reversed(range(first, last + 1)): for i in reversed(range(first, last + 1)):
w = self.splitter.widget(i) w = self.splitter.widget(i)
w.deleteLater() w.deleteLater()
self.splitter.refresh() self.splitter.refresh()
self._resize() self._resize()
def onMove(self, src_parent, src_start, src_end, dest_parent, dest_row): def onMove(self, src_parent, src_start, src_end, dest_parent, dest_row):
w = self.splitter.widget(src_start) w = self.splitter.widget(src_start)
self.splitter.insertWidget(dest_row, w) self.splitter.insertWidget(dest_row, w)
@ -492,15 +492,15 @@ class _WaveformModel(QtCore.QAbstractTableModel):
self.backing_struct = [] self.backing_struct = []
self.headers = ["name", "type", "width", "data"] self.headers = ["name", "type", "width", "data"]
QtCore.QAbstractTableModel.__init__(self) QtCore.QAbstractTableModel.__init__(self)
def rowCount(self): def rowCount(self):
return len(self.backing_struct) return len(self.backing_struct)
def columnCount(self): def columnCount(self):
return len(self.headers) return len(self.headers)
def data(self, index, role=QtCore.Qt.DisplayRole): def data(self, index, role=QtCore.Qt.DisplayRole):
if index.isValid(): if index.isValid():
return self.backing_struct[index.row()][index.col()] return self.backing_struct[index.row()][index.col()]
return None return None
@ -521,12 +521,12 @@ class _WaveformModel(QtCore.QAbstractTableModel):
self.backing_struct.insert(dest, self.backing_struct.pop(src)) self.backing_struct.insert(dest, self.backing_struct.pop(src))
self.endMoveRows() self.endMoveRows()
def update_data(self, waveform_data): def update_data(self, waveform_data):
for i in range(len(self.backing_struct)): for i in range(len(self.backing_struct)):
name = self.data(self.index(i, 0)) name = self.data(self.index(i, 0))
if name in waveform_data: if name in waveform_data:
self.backing_struct[i][3] = waveform_data[name] self.backing_struct[i][3] = waveform_data[name]
self.dataChanged.emit(self.index(0, 0), self.dataChanged.emit(self.index(0, 0),
self.index(len(self.backing_struct)-1, len(self.headers))) self.index(len(self.backing_struct)-1, len(self.headers)))