mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-12 12:52:13 +08:00
Cabana: align the charts properly (#26116)
old-commit-hash: 60586e0d5835dbb3928321700c9d4d99cdeec216
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <QGraphicsLayout>
|
||||
#include <QRubberBand>
|
||||
#include <QTimer>
|
||||
#include <QtCharts/QLineSeries>
|
||||
#include <QtCharts/QValueAxis>
|
||||
|
||||
@@ -183,7 +184,6 @@ ChartView::ChartView(const QString &id, const Signal *sig, QWidget *parent)
|
||||
font.setBold(true);
|
||||
chart->setTitleFont(font);
|
||||
chart->setMargins({0, 0, 0, 0});
|
||||
chart->layout()->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
track_line = new QGraphicsLineItem(chart);
|
||||
track_line->setPen(QPen(Qt::gray, 1, Qt::DashLine));
|
||||
@@ -202,14 +202,32 @@ ChartView::ChartView(const QString &id, const Signal *sig, QWidget *parent)
|
||||
rubber->setPalette(pal);
|
||||
}
|
||||
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer->setInterval(100);
|
||||
timer->setSingleShot(true);
|
||||
timer->callOnTimeout(this, &ChartView::adjustChartMargins);
|
||||
|
||||
QObject::connect(can, &CANMessages::updated, this, &ChartView::updateState);
|
||||
QObject::connect(can, &CANMessages::rangeChanged, this, &ChartView::rangeChanged);
|
||||
QObject::connect(can, &CANMessages::eventsMerged, this, &ChartView::updateSeries);
|
||||
QObject::connect(dynamic_cast<QValueAxis *>(chart->axisX()), &QValueAxis::rangeChanged, can, &CANMessages::setRange);
|
||||
QObject::connect(chart, &QChart::plotAreaChanged, [=](const QRectF &plotArea) {
|
||||
// use a singleshot timer to avoid recursion call.
|
||||
timer->start();
|
||||
});
|
||||
|
||||
updateSeries();
|
||||
}
|
||||
|
||||
void ChartView::adjustChartMargins() {
|
||||
// TODO: Remove hardcoded aligned_pos
|
||||
const int aligned_pos = 60;
|
||||
if (chart()->plotArea().left() != aligned_pos) {
|
||||
const float left_margin = chart()->margins().left() + aligned_pos - chart()->plotArea().left();
|
||||
chart()->setMargins(QMargins(left_margin, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
void ChartWidget::setHeight(int height) {
|
||||
chart_view->setFixedHeight(height);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ private:
|
||||
void mouseMoveEvent(QMouseEvent *ev) override;
|
||||
void enterEvent(QEvent *event) override;
|
||||
void leaveEvent(QEvent *event) override;
|
||||
void adjustChartMargins();
|
||||
|
||||
void rangeChanged(qreal min, qreal max);
|
||||
void updateAxisY();
|
||||
|
||||
Reference in New Issue
Block a user