Skip to content

Commit

Permalink
cabana: fix sparkline glitch (commaai#30320)
Browse files Browse the repository at this point in the history
fix glitch
  • Loading branch information
deanlee authored Oct 24, 2023
1 parent d3d5198 commit f47723d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions tools/cabana/signalview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ SignalView::SignalView(ChartsWidget *charts, QWidget *parent) : charts(charts),
QRegularExpression re("\\S+");
filter_edit->setValidator(new QRegularExpressionValidator(re, this));
filter_edit->setClearButtonEnabled(true);
filter_edit->setPlaceholderText(tr("filter signals"));
filter_edit->setPlaceholderText(tr("Filter Signal"));
hl->addWidget(filter_edit);
hl->addStretch(1);

Expand Down Expand Up @@ -502,6 +502,12 @@ SignalView::SignalView(ChartsWidget *charts, QWidget *parent) : charts(charts),
QObject::connect(tree->verticalScrollBar(), &QScrollBar::valueChanged, [this]() { updateState(); });
QObject::connect(tree->verticalScrollBar(), &QScrollBar::rangeChanged, [this]() { updateState(); });
QObject::connect(can, &AbstractStream::msgsReceived, this, &SignalView::updateState);
QObject::connect(tree->header(), &QHeaderView::sectionResized, [this](int logicalIndex, int oldSize, int newSize) {
if (logicalIndex == 1) {
value_column_width = newSize - delegate->button_size.width();
updateState();
}
});

setWhatsThis(tr(R"(
<b>Signal view</b><br />
Expand Down Expand Up @@ -638,11 +644,10 @@ void SignalView::updateState(const QHash<MessageId, CanData> *msgs) {
last_visible_row = bottom.parent().isValid() ? bottom.parent().row() : bottom.row();
}

QSize size(tree->columnWidth(1) - delegate->button_size.width(), delegate->button_size.height());
int min_max_width = std::min(size.width() - 10, QFontMetrics(delegate->minmax_font).width("-000.00") + 5);
int value_width = std::min<int>(max_value_width, size.width() * 0.35);
size -= {value_width + min_max_width, style()->pixelMetric(QStyle::PM_FocusFrameVMargin) * 2};

const static int min_max_width = QFontMetrics(delegate->minmax_font).width("-000.00") + 5;
int value_width = std::min<int>(max_value_width + min_max_width, value_column_width / 2);
QSize size(value_column_width - value_width,
delegate->button_size.height() - style()->pixelMetric(QStyle::PM_FocusFrameVMargin) * 2);
QFutureSynchronizer<void> synchronizer;
for (int i = first_visible_row; i <= last_visible_row; ++i) {
auto item = model->getItem(model->index(i, 1));
Expand Down
1 change: 1 addition & 0 deletions tools/cabana/signalview.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class SignalView : public QFrame {
}
};
int max_value_width = 0;
int value_column_width = 0;
TreeView *tree;
QLabel *sparkline_label;
QSlider *sparkline_range_slider;
Expand Down

0 comments on commit f47723d

Please sign in to comment.