Profile: keep the plotInfo in the corresponding member variable

We had the variable. As a pointer. Which we used memset to clear. Ouch -
that smells like some bad cut and paste.

With this change the object keeps the corresponding plotInfo around (just
like some others do) and can use it later. I suspect this code could use
some larger cleanup, but it's a bit too late for this in the development
cycle, I guess. I'm sure I'll regret this in the future...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-11-19 22:28:16 +00:00
parent 76c44dd6a3
commit 21658383e5
2 changed files with 20 additions and 19 deletions

View file

@ -491,16 +491,16 @@ void ProfileWidget2::plotDive(struct dive *d, bool force)
* so I'll *not* calculate everything if something is not being * so I'll *not* calculate everything if something is not being
* shown. * shown.
*/ */
struct plot_info pInfo = calculate_max_limits_new(&displayed_dive, currentdc); plotInfo = calculate_max_limits_new(&displayed_dive, currentdc);
create_plot_info_new(&displayed_dive, currentdc, &pInfo); create_plot_info_new(&displayed_dive, currentdc, &plotInfo);
if(shouldCalculateMaxTime) if(shouldCalculateMaxTime)
maxtime = get_maxtime(&pInfo); maxtime = get_maxtime(&plotInfo);
/* Only update the max depth if it's bigger than the current ones /* Only update the max depth if it's bigger than the current ones
* when we are dragging the handler to plan / add dive. * when we are dragging the handler to plan / add dive.
* otherwhise, update normally. * otherwhise, update normally.
*/ */
int newMaxDepth = get_maxdepth(&pInfo); int newMaxDepth = get_maxdepth(&plotInfo);
if(!shouldCalculateMaxDepth) { if(!shouldCalculateMaxDepth) {
if (maxdepth < newMaxDepth) { if (maxdepth < newMaxDepth) {
maxdepth = newMaxDepth; maxdepth = newMaxDepth;
@ -509,23 +509,23 @@ void ProfileWidget2::plotDive(struct dive *d, bool force)
maxdepth = newMaxDepth; maxdepth = newMaxDepth;
} }
dataModel->setDive(&displayed_dive, pInfo); dataModel->setDive(&displayed_dive, plotInfo);
toolTipItem->setPlotInfo(pInfo); toolTipItem->setPlotInfo(plotInfo);
// 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();
temperatureAxis->setMinimum(pInfo.mintemp); temperatureAxis->setMinimum(plotInfo.mintemp);
temperatureAxis->setMaximum(pInfo.maxtemp); temperatureAxis->setMaximum(plotInfo.maxtemp);
if (pInfo.maxhr) { if (plotInfo.maxhr) {
heartBeatAxis->setMinimum(pInfo.minhr); heartBeatAxis->setMinimum(plotInfo.minhr);
heartBeatAxis->setMaximum(pInfo.maxhr); heartBeatAxis->setMaximum(plotInfo.maxhr);
heartBeatAxis->updateTicks(HR_AXIS); // this shows the ticks heartBeatAxis->updateTicks(HR_AXIS); // this shows the ticks
} }
heartBeatAxis->setVisible(prefs.hrgraph && pInfo.maxhr); heartBeatAxis->setVisible(prefs.hrgraph && plotInfo.maxhr);
percentageAxis->setMinimum(0); percentageAxis->setMinimum(0);
percentageAxis->setMaximum(100); percentageAxis->setMaximum(100);
@ -550,15 +550,15 @@ void ProfileWidget2::plotDive(struct dive *d, bool force)
incr *= 2; incr *= 2;
timeAxis->setTickInterval(incr); timeAxis->setTickInterval(incr);
timeAxis->updateTicks(); timeAxis->updateTicks();
cylinderPressureAxis->setMinimum(pInfo.minpressure); cylinderPressureAxis->setMinimum(plotInfo.minpressure);
cylinderPressureAxis->setMaximum(pInfo.maxpressure); cylinderPressureAxis->setMaximum(plotInfo.maxpressure);
rulerItem->setPlotInfo(pInfo); rulerItem->setPlotInfo(plotInfo);
tankItem->setData(dataModel, &pInfo, &displayed_dive); tankItem->setData(dataModel, &plotInfo, &displayed_dive);
meanDepth->setVisible(prefs.show_average_depth); meanDepth->setVisible(prefs.show_average_depth);
meanDepth->setMeanDepth(pInfo.meandepth); meanDepth->setMeanDepth(plotInfo.meandepth);
meanDepth->setLine(0, 0, timeAxis->posAtValue(currentdc->duration.seconds), 0); meanDepth->setLine(0, 0, timeAxis->posAtValue(currentdc->duration.seconds), 0);
Animations::moveTo(meanDepth,3, profileYAxis->posAtValue(pInfo.meandepth)); Animations::moveTo(meanDepth,3, profileYAxis->posAtValue(plotInfo.meandepth));
dataModel->emitDataChanged(); dataModel->emitDataChanged();
// The event items are a bit special since we don't know how many events are going to // The event items are a bit special since we don't know how many events are going to

View file

@ -16,6 +16,7 @@
#include "graphicsview-common.h" #include "graphicsview-common.h"
#include "divelineitem.h" #include "divelineitem.h"
#include "diveprofileitem.h" #include "diveprofileitem.h"
#include "display.h"
class RulerItem2; class RulerItem2;
struct dive; struct dive;
@ -145,7 +146,7 @@ private:
// All those here should probably be merged into one structure, // All those here should probably be merged into one structure,
// So it's esyer to replicate for more dives later. // So it's esyer to replicate for more dives later.
// In the meantime, keep it here. // In the meantime, keep it here.
struct plot_info *plotInfo; struct plot_info plotInfo;
DepthAxis *profileYAxis; DepthAxis *profileYAxis;
PartialGasPressureAxis *gasYAxis; PartialGasPressureAxis *gasYAxis;
TemperatureAxis *temperatureAxis; TemperatureAxis *temperatureAxis;