From 71629521b70d4aa2aa0a620f5838dcc47d864aec Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 22 Oct 2021 18:23:15 +0200 Subject: [PATCH] profile: don't recalculate plot-info when zooming / scrolling This is a potentially expensive operation (e.g. interpolation of pressure values), so don't recalculate the plot data for every redraw. Signed-off-by: Berthold Stoeger --- profile-widget/profilescene.cpp | 5 +++-- profile-widget/profilescene.h | 2 +- profile-widget/profilewidget2.cpp | 10 ++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/profile-widget/profilescene.cpp b/profile-widget/profilescene.cpp index 5685be29b..0b422856f 100644 --- a/profile-widget/profilescene.cpp +++ b/profile-widget/profilescene.cpp @@ -324,7 +324,7 @@ bool ProfileScene::isPointOutOfBoundaries(const QPointF &point) const } void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsModel *plannerModel, - bool inPlanner, bool instant, bool calcMax, double zoom, double zoomedPosition) + bool inPlanner, bool instant, bool keepPlotInfo, bool calcMax, double zoom, double zoomedPosition) { d = dIn; dc = dcIn; @@ -363,7 +363,8 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM * shown. * create_plot_info_new() automatically frees old plot data. */ - create_plot_info_new(d, get_dive_dc_const(d, dc), &plotInfo, !calcMax, planner_ds); + if (!keepPlotInfo) + create_plot_info_new(d, get_dive_dc_const(d, dc), &plotInfo, !calcMax, planner_ds); bool hasHeartBeat = plotInfo.maxhr; // For mobile we might want to turn of some features that are normally shown. diff --git a/profile-widget/profilescene.h b/profile-widget/profilescene.h index 2ed8ec17c..2147e8c85 100644 --- a/profile-widget/profilescene.h +++ b/profile-widget/profilescene.h @@ -42,7 +42,7 @@ public: // If a plannerModel is passed, the deco-information is taken from there. void plotDive(const struct dive *d, int dc, DivePlannerPointsModel *plannerModel = nullptr, bool inPlanner = false, - bool instant = false, bool calcMax = true, double zoom = 1.0, double zoomedPosition = 0.0); + bool instant = false, bool keepPlotInfo = false, bool calcMax = true, double zoom = 1.0, double zoomedPosition = 0.0); void draw(QPainter *painter, const QRect &pos, const struct dive *d, int dc, diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 09384b959..6c91eb394 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -205,7 +205,9 @@ void ProfileWidget2::plotDive(const struct dive *dIn, int dcIn, int flags) bool inPlanner = currentState == PLAN; double zoom = zoomLevel == 0 ? 1.0 : pow(zoomFactor, zoomLevel); - profileScene->plotDive(d, dc, model, inPlanner, flags & RenderFlags::Instant, shouldCalculateMax, zoom, zoomedPosition); + profileScene->plotDive(d, dc, model, inPlanner, flags & RenderFlags::Instant, + flags & RenderFlags::DontRecalculatePlotInfo, + shouldCalculateMax, zoom, zoomedPosition); #ifndef SUBSURFACE_MOBILE rulerItem->setVisible(prefs.rulergraph && currentState != PLAN && currentState != EDIT); @@ -256,7 +258,7 @@ void ProfileWidget2::resizeEvent(QResizeEvent *event) { QGraphicsView::resizeEvent(event); profileScene->resize(viewport()->size()); - plotDive(d, dc, RenderFlags::Instant); // disable animation on resize events + plotDive(d, dc, RenderFlags::Instant | RenderFlags::DontRecalculatePlotInfo); // disable animation on resize events } #ifndef SUBSURFACE_MOBILE @@ -305,7 +307,7 @@ void ProfileWidget2::setZoom(int level) double pos = mapToScene(mapFromGlobal(QCursor::pos())).x(); zoomedPosition = pos / profileScene->width(); } - replot(); + plotDive(d, dc, RenderFlags::DontRecalculatePlotInfo); } #ifndef SUBSURFACE_MOBILE @@ -343,7 +345,7 @@ void ProfileWidget2::mouseMoveEvent(QMouseEvent *event) if (zoomLevel != 0) { zoomedPosition = pos.x() / profileScene->width(); - plotDive(d, dc, RenderFlags::Instant); // TODO: animations don't work when scrolling + plotDive(d, dc, RenderFlags::Instant | RenderFlags::DontRecalculatePlotInfo); // TODO: animations don't work when scrolling } double vValue = profileScene->profileYAxis->valueAt(pos);