mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-03 04:22:09 +08:00
cabana: show units (#27433)
* show units on chart y axis * show in signal list * show in historyview * use clear() old-commit-hash: a5644faa3f1095c2aa36b12e534fbba1b2ac921d
This commit is contained in:
@@ -542,9 +542,16 @@ void ChartView::updateAxisY() {
|
||||
|
||||
double min = std::numeric_limits<double>::max();
|
||||
double max = std::numeric_limits<double>::lowest();
|
||||
QString unit = sigs[0].sig->unit;
|
||||
|
||||
for (auto &s : sigs) {
|
||||
if (!s.series->isVisible()) continue;
|
||||
|
||||
// Only show unit when all signals have the same unit
|
||||
if (unit != s.sig->unit) {
|
||||
unit.clear();
|
||||
}
|
||||
|
||||
auto first = std::lower_bound(s.vals.begin(), s.vals.end(), axis_x->min(), [](auto &p, double x) { return p.x() < x; });
|
||||
auto last = std::lower_bound(first, s.vals.end(), axis_x->max(), [](auto &p, double x) { return p.x() < x; });
|
||||
for (auto it = first; it != last; ++it) {
|
||||
@@ -552,6 +559,8 @@ void ChartView::updateAxisY() {
|
||||
if (it->y() > max) max = it->y();
|
||||
}
|
||||
}
|
||||
axis_y->setTitleText(unit);
|
||||
|
||||
if (min == std::numeric_limits<double>::max()) min = 0;
|
||||
if (max == std::numeric_limits<double>::lowest()) max = 0;
|
||||
|
||||
@@ -563,7 +572,8 @@ void ChartView::updateAxisY() {
|
||||
|
||||
QFontMetrics fm(axis_y->labelsFont());
|
||||
int n = qMax(int(-qFloor(std::log10((max_y - min_y) / (tick_count - 1)))), 0) + 1;
|
||||
y_label_width = qMax(fm.width(QString::number(min_y, 'f', n)), fm.width(QString::number(max_y, 'f', n))) + 15; // left margin 15
|
||||
int title_spacing = axis_y->titleText().isEmpty() ? 0 : 20;
|
||||
y_label_width = title_spacing + qMax(fm.width(QString::number(min_y, 'f', n)), fm.width(QString::number(max_y, 'f', n))) + 15; // left margin 15
|
||||
axis_y->setLabelFormat(QString("%.%1f").arg(n));
|
||||
emit axisYLabelWidthChanged(y_label_width);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,15 @@ QVariant HistoryLogModel::headerData(int section, Qt::Orientation orientation, i
|
||||
if (section == 0) {
|
||||
return "Time";
|
||||
}
|
||||
return show_signals ? sigs[section - 1]->name : "Data";
|
||||
if (show_signals) {
|
||||
QString name = sigs[section - 1]->name;
|
||||
if (!sigs[section - 1]->unit.isEmpty()) {
|
||||
name += QString(" (%1)").arg(sigs[section - 1]->unit);
|
||||
}
|
||||
return name;
|
||||
} else {
|
||||
return "Data";
|
||||
}
|
||||
} else if (role == Qt::BackgroundRole && section > 0 && show_signals) {
|
||||
return QBrush(getColor(sigs[section - 1]));
|
||||
}
|
||||
|
||||
@@ -62,6 +62,9 @@ void SignalModel::updateState(const QHash<MessageId, CanData> *msgs) {
|
||||
int row = 0;
|
||||
for (auto item : root->children) {
|
||||
QString value = QString::number(get_raw_value((uint8_t *)dat.begin(), dat.size(), *item->sig));
|
||||
if (!item->sig->unit.isEmpty()){
|
||||
value += " " + item->sig->unit;
|
||||
}
|
||||
if (value != item->sig_val) {
|
||||
item->sig_val = value;
|
||||
emit dataChanged(index(row, 1), index(row, 1), {Qt::DisplayRole});
|
||||
|
||||
Reference in New Issue
Block a user