mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-30 02:52:04 +08:00
cabana: dynamically switch between OpenGL (#27167)
* cabana: dynamically switch between OpenGL * put back todo * only switch when x axis changes old-commit-hash: 49e955d321aff222665ac89b62d9de0b5d8395d2
This commit is contained in:
@@ -358,11 +358,6 @@ void ChartView::setPlotAreaLeftPosition(int pos) {
|
||||
void ChartView::addSeries(const QString &msg_id, const Signal *sig) {
|
||||
QLineSeries *series = new QLineSeries(this);
|
||||
|
||||
// TODO: Due to a bug in CameraWidget the camera frames
|
||||
// are drawn instead of the graphs on MacOS. Re-enable OpenGL when fixed
|
||||
#ifndef __APPLE__
|
||||
series->setUseOpenGL(true);
|
||||
#endif
|
||||
chart()->addSeries(series);
|
||||
series->attachAxis(axis_x);
|
||||
series->attachAxis(axis_y);
|
||||
@@ -476,17 +471,32 @@ void ChartView::updatePlot(double cur, double min, double max) {
|
||||
if (min != axis_x->min() || max != axis_x->max()) {
|
||||
axis_x->setRange(min, max);
|
||||
updateAxisY();
|
||||
}
|
||||
|
||||
// Show points when zoomed in enough
|
||||
for (auto &s : sigs) {
|
||||
auto begin = std::lower_bound(s.vals.begin(), s.vals.end(), axis_x->min(), [](auto &p, double x) { return p.x() < x; });
|
||||
auto end = std::lower_bound(s.vals.begin(), s.vals.end(), axis_x->max(), [](auto &p, double x) { return p.x() < x; });
|
||||
// Show points when zoomed in enough
|
||||
for (auto &s : sigs) {
|
||||
auto begin = std::lower_bound(s.vals.begin(), s.vals.end(), axis_x->min(), [](auto &p, double x) { return p.x() < x; });
|
||||
auto end = std::lower_bound(s.vals.begin(), s.vals.end(), axis_x->max(), [](auto &p, double x) { return p.x() < x; });
|
||||
|
||||
int num_points = std::max<int>(end - begin, 1);
|
||||
int pixels_per_point = width() / num_points;
|
||||
int num_points = std::max<int>(end - begin, 1);
|
||||
int pixels_per_point = width() / num_points;
|
||||
|
||||
s.series->setPointsVisible(pixels_per_point > 20);
|
||||
s.series->setPointsVisible(pixels_per_point > 20);
|
||||
|
||||
// TODO: On MacOS QChartWidget doesn't work with the OpenGL settings that CameraWidget needs.
|
||||
#ifndef __APPLE
|
||||
// OpenGL mode lacks certain features (such as showing points), only use when drawing many points
|
||||
bool use_opengl = pixels_per_point < 1;
|
||||
s.series->setUseOpenGL(use_opengl);
|
||||
|
||||
// Qt doesn't properly apply device pixel ratio in OpenGL mode
|
||||
QApplication* application = static_cast<QApplication *>(QApplication::instance());
|
||||
float scale = use_opengl ? application->devicePixelRatio() : 1.0;
|
||||
|
||||
QPen pen = s.series->pen();
|
||||
pen.setWidth(2.0 * scale);
|
||||
s.series->setPen(pen);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
scene()->invalidate({}, QGraphicsScene::ForegroundLayer);
|
||||
|
||||
Reference in New Issue
Block a user