From 1327043d6e28856f6d0cd8acffdc34331f2a7d0d Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 3 Aug 2021 10:32:08 +0200 Subject: [PATCH] profile: rectify animSpeed data flow The cartesian axes use animSpeed to animate changes. Instead of passing down the value to the respective functions, the speed was stored in the ProfileScene and the axes would access it there. Very messy. Let's just pass down the speed. There still are back-references from the axes to the scene, notably to place labels "outside" of the scene. Let's try to remove them later. Signed-off-by: Berthold Stoeger --- profile-widget/divecartesianaxis.cpp | 34 ++++++++--------- profile-widget/divecartesianaxis.h | 8 ++-- profile-widget/profilescene.cpp | 55 ++++++++++++++-------------- profile-widget/profilescene.h | 3 +- profile-widget/profilewidget2.cpp | 4 +- 5 files changed, 52 insertions(+), 52 deletions(-) diff --git a/profile-widget/divecartesianaxis.cpp b/profile-widget/divecartesianaxis.cpp index 84815e59d..bbc0f1d26 100644 --- a/profile-widget/divecartesianaxis.cpp +++ b/profile-widget/divecartesianaxis.cpp @@ -130,7 +130,7 @@ void emptyList(QList &list, int steps, int speed) } } -void DiveCartesianAxis::updateTicks(color_index_t color) +void DiveCartesianAxis::updateTicks(int animSpeed, color_index_t color) { if (!changed && !printMode) return; @@ -143,8 +143,8 @@ void DiveCartesianAxis::updateTicks(color_index_t color) if (steps < 1) return; - emptyList(labels, steps, scene.animSpeed); - emptyList(lines, steps, scene.animSpeed); + emptyList(labels, steps, animSpeed); + emptyList(lines, steps, animSpeed); // Move the remaining ticks / text to their correct positions // regarding the possible new values for the axis @@ -171,9 +171,9 @@ void DiveCartesianAxis::updateTicks(color_index_t color) labels[i]->setText(textForValue(currValueText)); if (orientation == LeftToRight || orientation == RightToLeft) { - Animations::moveTo(labels[i], scene.animSpeed, childPos, m.y1() + tick_size); + Animations::moveTo(labels[i], animSpeed, childPos, m.y1() + tick_size); } else { - Animations::moveTo(labels[i], scene.animSpeed ,m.x1() - tick_size, childPos); + Animations::moveTo(labels[i], animSpeed ,m.x1() - tick_size, childPos); } } @@ -183,9 +183,9 @@ void DiveCartesianAxis::updateTicks(color_index_t color) begin - i * stepSize; if (orientation == LeftToRight || orientation == RightToLeft) { - Animations::moveTo(lines[i], scene.animSpeed, childPos, m.y1()); + Animations::moveTo(lines[i], animSpeed, childPos, m.y1()); } else { - Animations::moveTo(lines[i], scene.animSpeed, m.x1(), childPos); + Animations::moveTo(lines[i], animSpeed, m.x1(), childPos); } } @@ -206,11 +206,11 @@ void DiveCartesianAxis::updateTicks(color_index_t color) if (orientation == RightToLeft || orientation == LeftToRight) { label->setAlignment(Qt::AlignBottom | Qt::AlignHCenter); label->setPos(scene.sceneRect().width() + 10, m.y1() + tick_size); // position it outside of the scene; - Animations::moveTo(label, scene.animSpeed,childPos , m.y1() + tick_size); + Animations::moveTo(label, animSpeed,childPos , m.y1() + tick_size); } else { label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); label->setPos(m.x1() - tick_size, scene.sceneRect().height() + 10); - Animations::moveTo(label, scene.animSpeed, m.x1() - tick_size, childPos); + Animations::moveTo(label, animSpeed, m.x1() - tick_size, childPos); } } @@ -231,13 +231,13 @@ void DiveCartesianAxis::updateTicks(color_index_t color) if (orientation == RightToLeft || orientation == LeftToRight) { line->setLine(0, -line_size, 0, 0); line->setPos(scene.sceneRect().width() + 10, m.y1()); // position it outside of the scene); - Animations::moveTo(line, scene.animSpeed, childPos, m.y1()); + Animations::moveTo(line, animSpeed, childPos, m.y1()); } else { QPointF p1 = mapFromScene(3, 0); QPointF p2 = mapFromScene(line_size, 0); line->setLine(p1.x(), 0, p2.x(), 0); line->setPos(m.x1(), scene.sceneRect().height() + 10); - Animations::moveTo(line, scene.animSpeed, m.x1(), childPos); + Animations::moveTo(line, animSpeed, m.x1(), childPos); } } @@ -254,10 +254,10 @@ void DiveCartesianAxis::setLine(const QLineF &line) changed = true; } -void DiveCartesianAxis::animateChangeLine(const QLineF &newLine) +void DiveCartesianAxis::animateChangeLine(const QLineF &newLine, int animSpeed) { setLine(newLine); - updateTicks(); + updateTicks(animSpeed); sizeChanged(); } @@ -370,9 +370,9 @@ QString TimeAxis::textForValue(double value) const return QString::number(nr); } -void TimeAxis::updateTicks(color_index_t color) +void TimeAxis::updateTicks(int animSpeed, color_index_t color) { - DiveCartesianAxis::updateTicks(color); + DiveCartesianAxis::updateTicks(animSpeed, color); if (maximum() > 600) { for (int i = 0; i < labels.count(); i++) { labels[i]->setVisible(i % 2); @@ -391,7 +391,7 @@ PartialGasPressureAxis::PartialGasPressureAxis(const DivePlotDataModel &model, d { } -void PartialGasPressureAxis::update() +void PartialGasPressureAxis::update(int animSpeed) { bool showPhe = prefs.pp_graphs.phe; bool showPn2 = prefs.pp_graphs.pn2; @@ -412,5 +412,5 @@ void PartialGasPressureAxis::update() setMaximum(pp); setTickInterval(pp > 4 ? 0.5 : 0.25); - updateTicks(); + updateTicks(animSpeed); } diff --git a/profile-widget/divecartesianaxis.h b/profile-widget/divecartesianaxis.h index a92aeb2b2..72b8f98ed 100644 --- a/profile-widget/divecartesianaxis.h +++ b/profile-widget/divecartesianaxis.h @@ -44,12 +44,12 @@ public: qreal posAtValue(qreal value) const; void setColor(const QColor &color); void setTextColor(const QColor &color); - void animateChangeLine(const QLineF &newLine); + void animateChangeLine(const QLineF &newLine, int animSpeed); void setTextVisible(bool arg1); void setLinesVisible(bool arg1); void setLineSize(qreal lineSize); void setLine(const QLineF& line); - virtual void updateTicks(color_index_t color = TIME_GRID); + virtual void updateTicks(int animSpeed, color_index_t color = TIME_GRID); signals: void sizeChanged(); @@ -87,7 +87,7 @@ class TimeAxis : public DiveCartesianAxis { Q_OBJECT public: using DiveCartesianAxis::DiveCartesianAxis; - void updateTicks(color_index_t color = TIME_GRID) override; + void updateTicks(int animSpeed, color_index_t color = TIME_GRID) override; private: QString textForValue(double value) const override; QColor colorForValue(double value) const override; @@ -105,7 +105,7 @@ class PartialGasPressureAxis : public DiveCartesianAxis { Q_OBJECT public: PartialGasPressureAxis(const DivePlotDataModel &model, double fontPrintScale, ProfileScene &scene); - void update(); + void update(int animSpeed); private: const DivePlotDataModel &model; }; diff --git a/profile-widget/profilescene.cpp b/profile-widget/profilescene.cpp index 45cd620db..f5658e95a 100644 --- a/profile-widget/profilescene.cpp +++ b/profile-widget/profilescene.cpp @@ -62,7 +62,6 @@ PartialPressureGasItem *ProfileScene::createPPGas(int column, color_index_t colo } ProfileScene::ProfileScene(double fontPrintScale) : - animSpeed(0), d(nullptr), dc(-1), fontPrintScale(fontPrintScale), @@ -246,63 +245,65 @@ void ProfileScene::updateVisibility() tankItem->setVisible(prefs.tankbar); } -void ProfileScene::updateAxes() +void ProfileScene::updateAxes(bool instant) { + int animSpeed = instant || printMode ? 0 : qPrefDisplay::animation_speed(); + profileYAxis->setPos(itemPos.depth.on); #ifndef SUBSURFACE_MOBILE - gasYAxis->update(); // Initialize ticks of partial pressure graph + gasYAxis->update(animSpeed); // Initialize ticks of partial pressure graph if ((prefs.percentagegraph||prefs.hrgraph) && ppGraphsEnabled()) { - profileYAxis->animateChangeLine(itemPos.depth.shrinked); + profileYAxis->animateChangeLine(itemPos.depth.shrinked, animSpeed); temperatureAxis->setPos(itemPos.temperatureAll.on); - temperatureAxis->animateChangeLine(itemPos.temperature.shrinked); - cylinderPressureAxis->animateChangeLine(itemPos.cylinder.shrinked); + temperatureAxis->animateChangeLine(itemPos.temperature.shrinked, animSpeed); + cylinderPressureAxis->animateChangeLine(itemPos.cylinder.shrinked, animSpeed); if (prefs.tankbar) { percentageAxis->setPos(itemPos.percentageWithTankBar.on); - percentageAxis->animateChangeLine(itemPos.percentageWithTankBar.expanded); + percentageAxis->animateChangeLine(itemPos.percentageWithTankBar.expanded, animSpeed); heartBeatAxis->setPos(itemPos.heartBeatWithTankBar.on); - heartBeatAxis->animateChangeLine(itemPos.heartBeatWithTankBar.expanded); + heartBeatAxis->animateChangeLine(itemPos.heartBeatWithTankBar.expanded, animSpeed); } else { percentageAxis->setPos(itemPos.percentage.on); - percentageAxis->animateChangeLine(itemPos.percentage.expanded); + percentageAxis->animateChangeLine(itemPos.percentage.expanded, animSpeed); heartBeatAxis->setPos(itemPos.heartBeat.on); - heartBeatAxis->animateChangeLine(itemPos.heartBeat.expanded); + heartBeatAxis->animateChangeLine(itemPos.heartBeat.expanded, animSpeed); } gasYAxis->setPos(itemPos.partialPressureTissue.on); - gasYAxis->animateChangeLine(itemPos.partialPressureTissue.expanded); + gasYAxis->animateChangeLine(itemPos.partialPressureTissue.expanded, animSpeed); } else if (ppGraphsEnabled() || prefs.hrgraph || prefs.percentagegraph) { - profileYAxis->animateChangeLine(itemPos.depth.intermediate); + profileYAxis->animateChangeLine(itemPos.depth.intermediate, animSpeed); temperatureAxis->setPos(itemPos.temperature.on); - temperatureAxis->animateChangeLine(itemPos.temperature.intermediate); - cylinderPressureAxis->animateChangeLine(itemPos.cylinder.intermediate); + temperatureAxis->animateChangeLine(itemPos.temperature.intermediate, animSpeed); + cylinderPressureAxis->animateChangeLine(itemPos.cylinder.intermediate, animSpeed); if (prefs.tankbar) { percentageAxis->setPos(itemPos.percentageWithTankBar.on); - percentageAxis->animateChangeLine(itemPos.percentageWithTankBar.expanded); + percentageAxis->animateChangeLine(itemPos.percentageWithTankBar.expanded, animSpeed); gasYAxis->setPos(itemPos.partialPressureWithTankBar.on); - gasYAxis->animateChangeLine(itemPos.partialPressureWithTankBar.expanded); + gasYAxis->animateChangeLine(itemPos.partialPressureWithTankBar.expanded, animSpeed); heartBeatAxis->setPos(itemPos.heartBeatWithTankBar.on); - heartBeatAxis->animateChangeLine(itemPos.heartBeatWithTankBar.expanded); + heartBeatAxis->animateChangeLine(itemPos.heartBeatWithTankBar.expanded, animSpeed); } else { gasYAxis->setPos(itemPos.partialPressure.on); - gasYAxis->animateChangeLine(itemPos.partialPressure.expanded); + gasYAxis->animateChangeLine(itemPos.partialPressure.expanded, animSpeed); percentageAxis->setPos(itemPos.percentage.on); - percentageAxis->animateChangeLine(itemPos.percentage.expanded); + percentageAxis->animateChangeLine(itemPos.percentage.expanded, animSpeed); heartBeatAxis->setPos(itemPos.heartBeat.on); - heartBeatAxis->animateChangeLine(itemPos.heartBeat.expanded); + heartBeatAxis->animateChangeLine(itemPos.heartBeat.expanded, animSpeed); } } else { #else { #endif - profileYAxis->animateChangeLine(itemPos.depth.expanded); + profileYAxis->animateChangeLine(itemPos.depth.expanded, animSpeed); if (prefs.tankbar) { temperatureAxis->setPos(itemPos.temperatureAll.on); } else { temperatureAxis->setPos(itemPos.temperature.on); } - temperatureAxis->animateChangeLine(itemPos.temperature.expanded); - cylinderPressureAxis->animateChangeLine(itemPos.cylinder.expanded); + temperatureAxis->animateChangeLine(itemPos.temperature.expanded, animSpeed); + cylinderPressureAxis->animateChangeLine(itemPos.cylinder.expanded, animSpeed); } timeAxis->setPos(itemPos.time.on); @@ -464,7 +465,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM if (!currentdc || !currentdc->samples) return; - animSpeed = instant || printMode ? 0 : qPrefDisplay::animation_speed(); + int animSpeed = instant || printMode ? 0 : qPrefDisplay::animation_speed(); bool setpointflag = (currentdc->divemode == CCR) && prefs.pp_graphs.po2; bool sensorflag = setpointflag && prefs.show_ccr_sensors; @@ -511,7 +512,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM // It seems that I'll have a lot of boilerplate setting the model / axis for // each item, I'll mostly like to fix this in the future, but I'll keep at this for now. profileYAxis->setMaximum(maxdepth); - profileYAxis->updateTicks(); + profileYAxis->updateTicks(animSpeed); temperatureAxis->setMinimum(plotInfo.mintemp); temperatureAxis->setMaximum(plotInfo.maxtemp - plotInfo.mintemp > 2000 ? plotInfo.maxtemp : plotInfo.mintemp + 2000); @@ -559,7 +560,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM while (maxtime / incr > 12) incr *= 2; timeAxis->setTickInterval(incr); - timeAxis->updateTicks(); + timeAxis->updateTicks(animSpeed); cylinderPressureAxis->setMinimum(plotInfo.minpressure); cylinderPressureAxis->setMaximum(plotInfo.maxpressure); @@ -602,7 +603,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM #endif tankItem->setData(&plotInfo, d); - gasYAxis->update(); + gasYAxis->update(animSpeed); // Replot dive items for (AbstractProfilePolygonItem *item: profileItems) diff --git a/profile-widget/profilescene.h b/profile-widget/profilescene.h index 24af16f08..2da45c851 100644 --- a/profile-widget/profilescene.h +++ b/profile-widget/profilescene.h @@ -38,12 +38,11 @@ public: ProfileScene(double fontPrintScale); ~ProfileScene(); - void updateAxes(); // Update axes according to preferences + void updateAxes(bool instant); // Update axes according to preferences void clear(); bool isPointOutOfBoundaries(const QPointF &point) const; // If a plannerModel is passed, the deco-information is taken from there. - int animSpeed; void plotDive(const struct dive *d, int dc, DivePlannerPointsModel *plannerModel = nullptr, bool inPlanner = false, bool instant = false, bool calcMax = true); diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 81a95a07e..26ee354b9 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -262,7 +262,7 @@ void ProfileWidget2::actionRequestedReplot(bool) void ProfileWidget2::settingsChanged() { - profileScene->updateAxes(); + profileScene->updateAxes(false); replot(); } @@ -446,7 +446,7 @@ void ProfileWidget2::setProfileState() currentState = PROFILE; setBackgroundBrush(getColor(::BACKGROUND, profileScene->isGrayscale)); - profileScene->updateAxes(); + profileScene->updateAxes(true); #ifndef SUBSURFACE_MOBILE toolTipItem->readPos();