waveform: add remove, clear waveform actions

This commit is contained in:
Simon Renblad 2024-02-01 17:15:23 +08:00 committed by Sébastien Bourdeauducq
parent 1e9070a2af
commit 8b503c3b4f

View File

@ -434,8 +434,18 @@ class _WaveformView(QtWidgets.QWidget):
w.setXLink(self._ref_vb)
w.setStoppedX(self._stopped_x)
w.setTimescale(self._timescale)
action = QtWidgets.QAction("Delete waveform", w)
action.triggered.connect(lambda: self._delete_waveform(w))
w.addAction(action)
action = QtWidgets.QAction("Clear waveforms", w)
action.triggered.connect(self._model.clear)
w.addAction(action)
return w
def _delete_waveform(self, waveform):
row = self._splitter.indexOf(waveform)
self._model.pop(row)
def _resize(self):
self._splitter.setFixedHeight(
int((WAVEFORM_MIN_HEIGHT + WAVEFORM_MAX_HEIGHT) * self._model.rowCount() / 2))
@ -479,6 +489,11 @@ class _WaveformModel(QtCore.QAbstractTableModel):
self.backing_struct.insert(dest, self.backing_struct.pop(src))
self.endMoveRows()
def clear(self):
self.beginRemoveRows(QtCore.QModelIndex(), 0, len(self.backing_struct) - 1)
self.backing_struct.clear()
self.endRemoveRows()
def update_data(self, waveform_data, top, bottom):
name_col = self.headers.index("name")
data_col = self.headers.index("data")