7#include <QStyleOptionViewItem>
15const QColor kOutputColor(0, 128, 0);
16const QColor kInputColor(0x75, 0x8e, 0xff);
19const QColor kUnknownColor(0x9e, 0x9e, 0x9e);
20const QColor kErrorColor(0xd3, 0x2f, 0x2f);
23constexpr double kLineThickness = 4.0 / 30.0;
24constexpr double kBarWidth = 4.0 / 100.0;
25constexpr double kHighTop = 8.0 / 30.0;
26constexpr double kLowTop = 20.0 / 30.0;
27constexpr double kHighBottom = 12.0 / 30.0;
28constexpr double kLowBottom = 24.0 / 30.0;
32 : QItemDelegate(parent)
49 if (value ==
static_cast<int>(Status::Unknown)) {
52 if (value ==
static_cast<int>(Status::Error)) {
62void SignalDelegate::drawWaveform(QPainter *painter,
const QRectF &cell,
const WaveSegment seg,
const bool isInput)
const
64 const double x = cell.x();
65 const double y = cell.y();
66 const double w = cell.width();
67 const double h = cell.height();
76 QColor stateBand = stateColor;
77 stateBand.setAlpha(64);
78 painter->fillRect(QRectF(x, y, w, h), stateBand);
79 const double midTop = ((kHighTop + kLowTop) / 2.0) * h;
80 painter->fillRect(QRectF(x, y + midTop, w, kLineThickness * h), stateColor);
84 const QColor color = isInput ? kInputColor : kOutputColor;
85 QColor bandColor = color;
86 bandColor.setAlpha(128);
90 const double lineTop = (high ? kHighTop : kLowTop) * h;
91 const double lineBottom = (high ? kHighBottom : kLowBottom) * h;
92 const double thickness = kLineThickness * h;
95 painter->fillRect(QRectF(x, y + lineBottom, w, h - lineBottom), bandColor);
96 painter->fillRect(QRectF(x, y + lineTop, w, thickness), color);
100 const double barTop = kHighTop * h;
101 const double barBottom = kLowBottom * h;
102 painter->fillRect(QRectF(x, y + barTop, kBarWidth * w, barBottom - barTop), color);
110 QStyleOptionViewItem opt(option);
111 opt.displayAlignment = Qt::AlignCenter;
112 QItemDelegate::paint(painter, opt, index);
118 const int value = index.data().toInt();
119 const QModelIndex prev = index.siblingAtColumn(index.column() - 1);
120 const bool hasPrev = prev.isValid();
124 if (
const auto *model = qobject_cast<const SignalModel *>(index.model())) {
125 isInput = model->isInputRow(index.row());
129 if (option.state & QStyle::State_Selected) {
130 painter->fillRect(option.rect, option.palette.highlight());
133 drawWaveform(painter, option.rect, seg, isInput);
Central enumeration types for element types, groups, and signal status.
SignalDelegate: paints digital waveform graphics into table cells.
WaveSegment
Identifies which waveform segment a Line-mode cell draws.
@ Falling
High → low transition (low plateau + leading edge).
@ Low
Logic-low plateau (signal stays at 0).
@ Rising
Low → high transition (high plateau + leading edge).
@ High
Logic-high plateau (signal stays at 1).
@ Unknown
Undefined (Status::Unknown): drawn mid-level in the canvas's "unknown" grey.
@ Error
Conflicting drivers (Status::Error): drawn mid-level in the canvas's red.
PlotType
Controls how signal cells are rendered in the waveform table.
@ Number
Cells display the numeric value (0/1).
SignalModel for the beWavedDolphin waveform table.
void setPlotType(PlotType plotType)
Selects the cell rendering mode (waveform graphics vs. numeric text).
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
PlotType plotType() const
Returns the current cell rendering mode.
static WaveSegment segmentFor(int value, bool hasPrev, int prevValue)
Returns the waveform segment a cell should draw.
SignalDelegate(QObject *parent=nullptr)
Constructs the delegate.