mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-24 15:32:07 +08:00
cabana: fixed segfault when search in signals (#28078)
This commit is contained in:
+22
-20
@@ -599,29 +599,31 @@ void SignalView::updateState(const QHash<MessageId, CanData> *msgs) {
|
||||
max_value_width = std::max(max_value_width, fontMetrics().width(item->sig_val));
|
||||
}
|
||||
|
||||
// update visible sparkline
|
||||
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};
|
||||
|
||||
QModelIndex top = tree->indexAt(QPoint(0, 0));
|
||||
QModelIndex bottom = tree->indexAt(tree->viewport()->rect().bottomLeft());
|
||||
int start_row = top.parent().isValid() ? top.parent().row() + 1 : top.row();
|
||||
int end_row = model->rowCount() - 1;
|
||||
if (bottom.isValid()) {
|
||||
end_row = bottom.parent().isValid() ? bottom.parent().row() : bottom.row();
|
||||
}
|
||||
QFutureSynchronizer<void> synchronizer;
|
||||
for (int i = start_row; i <= end_row; ++i) {
|
||||
auto item = model->getItem(model->index(i, 1));
|
||||
auto &s = item->sparkline;
|
||||
if (s.last_ts != last_msg.ts || s.size() != size || s.time_range != settings.sparkline_range) {
|
||||
synchronizer.addFuture(QtConcurrent::run(
|
||||
&s, &Sparkline::update, model->msg_id, item->sig, last_msg.ts, settings.sparkline_range, size));
|
||||
if (top.isValid()) {
|
||||
// update visible sparkline
|
||||
int first_visible_row = top.parent().isValid() ? top.parent().row() + 1 : top.row();
|
||||
int last_visible_row = model->rowCount() - 1;
|
||||
QModelIndex bottom = tree->indexAt(tree->viewport()->rect().bottomLeft());
|
||||
if (bottom.isValid()) {
|
||||
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};
|
||||
|
||||
QFutureSynchronizer<void> synchronizer;
|
||||
for (int i = first_visible_row; i <= last_visible_row; ++i) {
|
||||
auto item = model->getItem(model->index(i, 1));
|
||||
auto &s = item->sparkline;
|
||||
if (s.last_ts != last_msg.ts || s.size() != size || s.time_range != settings.sparkline_range) {
|
||||
synchronizer.addFuture(QtConcurrent::run(
|
||||
&s, &Sparkline::update, model->msg_id, item->sig, last_msg.ts, settings.sparkline_range, size));
|
||||
}
|
||||
}
|
||||
}
|
||||
synchronizer.waitForFinished();
|
||||
|
||||
for (int i = 0; i < model->rowCount(); ++i) {
|
||||
emit model->dataChanged(model->index(i, 1), model->index(i, 1), {Qt::DisplayRole});
|
||||
|
||||
Reference in New Issue
Block a user