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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-08-03 10:32:08 +02:00 committed by Dirk Hohndel
parent d19b095db1
commit 1327043d6e
5 changed files with 52 additions and 52 deletions

View file

@ -130,7 +130,7 @@ void emptyList(QList<T *> &list, int steps, int speed)
} }
} }
void DiveCartesianAxis::updateTicks(color_index_t color) void DiveCartesianAxis::updateTicks(int animSpeed, color_index_t color)
{ {
if (!changed && !printMode) if (!changed && !printMode)
return; return;
@ -143,8 +143,8 @@ void DiveCartesianAxis::updateTicks(color_index_t color)
if (steps < 1) if (steps < 1)
return; return;
emptyList(labels, steps, scene.animSpeed); emptyList(labels, steps, animSpeed);
emptyList(lines, steps, scene.animSpeed); emptyList(lines, steps, animSpeed);
// Move the remaining ticks / text to their correct positions // Move the remaining ticks / text to their correct positions
// regarding the possible new values for the axis // regarding the possible new values for the axis
@ -171,9 +171,9 @@ void DiveCartesianAxis::updateTicks(color_index_t color)
labels[i]->setText(textForValue(currValueText)); labels[i]->setText(textForValue(currValueText));
if (orientation == LeftToRight || orientation == RightToLeft) { 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 { } 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; begin - i * stepSize;
if (orientation == LeftToRight || orientation == RightToLeft) { if (orientation == LeftToRight || orientation == RightToLeft) {
Animations::moveTo(lines[i], scene.animSpeed, childPos, m.y1()); Animations::moveTo(lines[i], animSpeed, childPos, m.y1());
} else { } 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) { if (orientation == RightToLeft || orientation == LeftToRight) {
label->setAlignment(Qt::AlignBottom | Qt::AlignHCenter); label->setAlignment(Qt::AlignBottom | Qt::AlignHCenter);
label->setPos(scene.sceneRect().width() + 10, m.y1() + tick_size); // position it outside of the scene; 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 { } else {
label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); label->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
label->setPos(m.x1() - tick_size, scene.sceneRect().height() + 10); 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) { if (orientation == RightToLeft || orientation == LeftToRight) {
line->setLine(0, -line_size, 0, 0); line->setLine(0, -line_size, 0, 0);
line->setPos(scene.sceneRect().width() + 10, m.y1()); // position it outside of the scene); 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 { } else {
QPointF p1 = mapFromScene(3, 0); QPointF p1 = mapFromScene(3, 0);
QPointF p2 = mapFromScene(line_size, 0); QPointF p2 = mapFromScene(line_size, 0);
line->setLine(p1.x(), 0, p2.x(), 0); line->setLine(p1.x(), 0, p2.x(), 0);
line->setPos(m.x1(), scene.sceneRect().height() + 10); 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; changed = true;
} }
void DiveCartesianAxis::animateChangeLine(const QLineF &newLine) void DiveCartesianAxis::animateChangeLine(const QLineF &newLine, int animSpeed)
{ {
setLine(newLine); setLine(newLine);
updateTicks(); updateTicks(animSpeed);
sizeChanged(); sizeChanged();
} }
@ -370,9 +370,9 @@ QString TimeAxis::textForValue(double value) const
return QString::number(nr); 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) { if (maximum() > 600) {
for (int i = 0; i < labels.count(); i++) { for (int i = 0; i < labels.count(); i++) {
labels[i]->setVisible(i % 2); 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 showPhe = prefs.pp_graphs.phe;
bool showPn2 = prefs.pp_graphs.pn2; bool showPn2 = prefs.pp_graphs.pn2;
@ -412,5 +412,5 @@ void PartialGasPressureAxis::update()
setMaximum(pp); setMaximum(pp);
setTickInterval(pp > 4 ? 0.5 : 0.25); setTickInterval(pp > 4 ? 0.5 : 0.25);
updateTicks(); updateTicks(animSpeed);
} }

View file

@ -44,12 +44,12 @@ public:
qreal posAtValue(qreal value) const; qreal posAtValue(qreal value) const;
void setColor(const QColor &color); void setColor(const QColor &color);
void setTextColor(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 setTextVisible(bool arg1);
void setLinesVisible(bool arg1); void setLinesVisible(bool arg1);
void setLineSize(qreal lineSize); void setLineSize(qreal lineSize);
void setLine(const QLineF& line); 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: signals:
void sizeChanged(); void sizeChanged();
@ -87,7 +87,7 @@ class TimeAxis : public DiveCartesianAxis {
Q_OBJECT Q_OBJECT
public: public:
using DiveCartesianAxis::DiveCartesianAxis; using DiveCartesianAxis::DiveCartesianAxis;
void updateTicks(color_index_t color = TIME_GRID) override; void updateTicks(int animSpeed, color_index_t color = TIME_GRID) override;
private: private:
QString textForValue(double value) const override; QString textForValue(double value) const override;
QColor colorForValue(double value) const override; QColor colorForValue(double value) const override;
@ -105,7 +105,7 @@ class PartialGasPressureAxis : public DiveCartesianAxis {
Q_OBJECT Q_OBJECT
public: public:
PartialGasPressureAxis(const DivePlotDataModel &model, double fontPrintScale, ProfileScene &scene); PartialGasPressureAxis(const DivePlotDataModel &model, double fontPrintScale, ProfileScene &scene);
void update(); void update(int animSpeed);
private: private:
const DivePlotDataModel &model; const DivePlotDataModel &model;
}; };

View file

@ -62,7 +62,6 @@ PartialPressureGasItem *ProfileScene::createPPGas(int column, color_index_t colo
} }
ProfileScene::ProfileScene(double fontPrintScale) : ProfileScene::ProfileScene(double fontPrintScale) :
animSpeed(0),
d(nullptr), d(nullptr),
dc(-1), dc(-1),
fontPrintScale(fontPrintScale), fontPrintScale(fontPrintScale),
@ -246,63 +245,65 @@ void ProfileScene::updateVisibility()
tankItem->setVisible(prefs.tankbar); 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); profileYAxis->setPos(itemPos.depth.on);
#ifndef SUBSURFACE_MOBILE #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()) { if ((prefs.percentagegraph||prefs.hrgraph) && ppGraphsEnabled()) {
profileYAxis->animateChangeLine(itemPos.depth.shrinked); profileYAxis->animateChangeLine(itemPos.depth.shrinked, animSpeed);
temperatureAxis->setPos(itemPos.temperatureAll.on); temperatureAxis->setPos(itemPos.temperatureAll.on);
temperatureAxis->animateChangeLine(itemPos.temperature.shrinked); temperatureAxis->animateChangeLine(itemPos.temperature.shrinked, animSpeed);
cylinderPressureAxis->animateChangeLine(itemPos.cylinder.shrinked); cylinderPressureAxis->animateChangeLine(itemPos.cylinder.shrinked, animSpeed);
if (prefs.tankbar) { if (prefs.tankbar) {
percentageAxis->setPos(itemPos.percentageWithTankBar.on); percentageAxis->setPos(itemPos.percentageWithTankBar.on);
percentageAxis->animateChangeLine(itemPos.percentageWithTankBar.expanded); percentageAxis->animateChangeLine(itemPos.percentageWithTankBar.expanded, animSpeed);
heartBeatAxis->setPos(itemPos.heartBeatWithTankBar.on); heartBeatAxis->setPos(itemPos.heartBeatWithTankBar.on);
heartBeatAxis->animateChangeLine(itemPos.heartBeatWithTankBar.expanded); heartBeatAxis->animateChangeLine(itemPos.heartBeatWithTankBar.expanded, animSpeed);
} else { } else {
percentageAxis->setPos(itemPos.percentage.on); percentageAxis->setPos(itemPos.percentage.on);
percentageAxis->animateChangeLine(itemPos.percentage.expanded); percentageAxis->animateChangeLine(itemPos.percentage.expanded, animSpeed);
heartBeatAxis->setPos(itemPos.heartBeat.on); heartBeatAxis->setPos(itemPos.heartBeat.on);
heartBeatAxis->animateChangeLine(itemPos.heartBeat.expanded); heartBeatAxis->animateChangeLine(itemPos.heartBeat.expanded, animSpeed);
} }
gasYAxis->setPos(itemPos.partialPressureTissue.on); gasYAxis->setPos(itemPos.partialPressureTissue.on);
gasYAxis->animateChangeLine(itemPos.partialPressureTissue.expanded); gasYAxis->animateChangeLine(itemPos.partialPressureTissue.expanded, animSpeed);
} else if (ppGraphsEnabled() || prefs.hrgraph || prefs.percentagegraph) { } else if (ppGraphsEnabled() || prefs.hrgraph || prefs.percentagegraph) {
profileYAxis->animateChangeLine(itemPos.depth.intermediate); profileYAxis->animateChangeLine(itemPos.depth.intermediate, animSpeed);
temperatureAxis->setPos(itemPos.temperature.on); temperatureAxis->setPos(itemPos.temperature.on);
temperatureAxis->animateChangeLine(itemPos.temperature.intermediate); temperatureAxis->animateChangeLine(itemPos.temperature.intermediate, animSpeed);
cylinderPressureAxis->animateChangeLine(itemPos.cylinder.intermediate); cylinderPressureAxis->animateChangeLine(itemPos.cylinder.intermediate, animSpeed);
if (prefs.tankbar) { if (prefs.tankbar) {
percentageAxis->setPos(itemPos.percentageWithTankBar.on); percentageAxis->setPos(itemPos.percentageWithTankBar.on);
percentageAxis->animateChangeLine(itemPos.percentageWithTankBar.expanded); percentageAxis->animateChangeLine(itemPos.percentageWithTankBar.expanded, animSpeed);
gasYAxis->setPos(itemPos.partialPressureWithTankBar.on); gasYAxis->setPos(itemPos.partialPressureWithTankBar.on);
gasYAxis->animateChangeLine(itemPos.partialPressureWithTankBar.expanded); gasYAxis->animateChangeLine(itemPos.partialPressureWithTankBar.expanded, animSpeed);
heartBeatAxis->setPos(itemPos.heartBeatWithTankBar.on); heartBeatAxis->setPos(itemPos.heartBeatWithTankBar.on);
heartBeatAxis->animateChangeLine(itemPos.heartBeatWithTankBar.expanded); heartBeatAxis->animateChangeLine(itemPos.heartBeatWithTankBar.expanded, animSpeed);
} else { } else {
gasYAxis->setPos(itemPos.partialPressure.on); gasYAxis->setPos(itemPos.partialPressure.on);
gasYAxis->animateChangeLine(itemPos.partialPressure.expanded); gasYAxis->animateChangeLine(itemPos.partialPressure.expanded, animSpeed);
percentageAxis->setPos(itemPos.percentage.on); percentageAxis->setPos(itemPos.percentage.on);
percentageAxis->animateChangeLine(itemPos.percentage.expanded); percentageAxis->animateChangeLine(itemPos.percentage.expanded, animSpeed);
heartBeatAxis->setPos(itemPos.heartBeat.on); heartBeatAxis->setPos(itemPos.heartBeat.on);
heartBeatAxis->animateChangeLine(itemPos.heartBeat.expanded); heartBeatAxis->animateChangeLine(itemPos.heartBeat.expanded, animSpeed);
} }
} else { } else {
#else #else
{ {
#endif #endif
profileYAxis->animateChangeLine(itemPos.depth.expanded); profileYAxis->animateChangeLine(itemPos.depth.expanded, animSpeed);
if (prefs.tankbar) { if (prefs.tankbar) {
temperatureAxis->setPos(itemPos.temperatureAll.on); temperatureAxis->setPos(itemPos.temperatureAll.on);
} else { } else {
temperatureAxis->setPos(itemPos.temperature.on); temperatureAxis->setPos(itemPos.temperature.on);
} }
temperatureAxis->animateChangeLine(itemPos.temperature.expanded); temperatureAxis->animateChangeLine(itemPos.temperature.expanded, animSpeed);
cylinderPressureAxis->animateChangeLine(itemPos.cylinder.expanded); cylinderPressureAxis->animateChangeLine(itemPos.cylinder.expanded, animSpeed);
} }
timeAxis->setPos(itemPos.time.on); timeAxis->setPos(itemPos.time.on);
@ -464,7 +465,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM
if (!currentdc || !currentdc->samples) if (!currentdc || !currentdc->samples)
return; 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 setpointflag = (currentdc->divemode == CCR) && prefs.pp_graphs.po2;
bool sensorflag = setpointflag && prefs.show_ccr_sensors; 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 // 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. // each item, I'll mostly like to fix this in the future, but I'll keep at this for now.
profileYAxis->setMaximum(maxdepth); profileYAxis->setMaximum(maxdepth);
profileYAxis->updateTicks(); profileYAxis->updateTicks(animSpeed);
temperatureAxis->setMinimum(plotInfo.mintemp); temperatureAxis->setMinimum(plotInfo.mintemp);
temperatureAxis->setMaximum(plotInfo.maxtemp - plotInfo.mintemp > 2000 ? plotInfo.maxtemp : plotInfo.mintemp + 2000); 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) while (maxtime / incr > 12)
incr *= 2; incr *= 2;
timeAxis->setTickInterval(incr); timeAxis->setTickInterval(incr);
timeAxis->updateTicks(); timeAxis->updateTicks(animSpeed);
cylinderPressureAxis->setMinimum(plotInfo.minpressure); cylinderPressureAxis->setMinimum(plotInfo.minpressure);
cylinderPressureAxis->setMaximum(plotInfo.maxpressure); cylinderPressureAxis->setMaximum(plotInfo.maxpressure);
@ -602,7 +603,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM
#endif #endif
tankItem->setData(&plotInfo, d); tankItem->setData(&plotInfo, d);
gasYAxis->update(); gasYAxis->update(animSpeed);
// Replot dive items // Replot dive items
for (AbstractProfilePolygonItem *item: profileItems) for (AbstractProfilePolygonItem *item: profileItems)

View file

@ -38,12 +38,11 @@ public:
ProfileScene(double fontPrintScale); ProfileScene(double fontPrintScale);
~ProfileScene(); ~ProfileScene();
void updateAxes(); // Update axes according to preferences void updateAxes(bool instant); // Update axes according to preferences
void clear(); void clear();
bool isPointOutOfBoundaries(const QPointF &point) const; bool isPointOutOfBoundaries(const QPointF &point) const;
// If a plannerModel is passed, the deco-information is taken from there. // 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, void plotDive(const struct dive *d, int dc, DivePlannerPointsModel *plannerModel = nullptr, bool inPlanner = false,
bool instant = false, bool calcMax = true); bool instant = false, bool calcMax = true);

View file

@ -262,7 +262,7 @@ void ProfileWidget2::actionRequestedReplot(bool)
void ProfileWidget2::settingsChanged() void ProfileWidget2::settingsChanged()
{ {
profileScene->updateAxes(); profileScene->updateAxes(false);
replot(); replot();
} }
@ -446,7 +446,7 @@ void ProfileWidget2::setProfileState()
currentState = PROFILE; currentState = PROFILE;
setBackgroundBrush(getColor(::BACKGROUND, profileScene->isGrayscale)); setBackgroundBrush(getColor(::BACKGROUND, profileScene->isGrayscale));
profileScene->updateAxes(); profileScene->updateAxes(true);
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
toolTipItem->readPos(); toolTipItem->readPos();