profile: pass dive to ToolTipItem::refresh()

Don't access the global displayed_dive variable in a step
to make the profile reentrant.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-01-09 18:11:56 +01:00 committed by Dirk Hohndel
parent 193513a61f
commit 54e8fe5d9e
5 changed files with 10 additions and 10 deletions

View file

@ -1414,7 +1414,7 @@ struct divecomputer *select_dc(struct dive *dive)
return get_dive_dc(dive, i); return get_dive_dc(dive, i);
} }
static void plot_string(const struct plot_info *pi, int idx, struct membuffer *b) static void plot_string(const struct dive *d, const struct plot_info *pi, int idx, struct membuffer *b)
{ {
int pressurevalue, mod, ead, end, eadd; int pressurevalue, mod, ead, end, eadd;
const char *depth_unit, *pressure_unit, *temp_unit, *vertical_speed_unit; const char *depth_unit, *pressure_unit, *temp_unit, *vertical_speed_unit;
@ -1429,7 +1429,7 @@ static void plot_string(const struct plot_info *pi, int idx, struct membuffer *b
int mbar = get_plot_pressure(pi, idx, cyl); int mbar = get_plot_pressure(pi, idx, cyl);
if (!mbar) if (!mbar)
continue; continue;
struct gasmix mix = get_cylinder(&displayed_dive, cyl)->gasmix; struct gasmix mix = get_cylinder(d, cyl)->gasmix;
pressurevalue = get_pressure_units(mbar, &pressure_unit); pressurevalue = get_pressure_units(mbar, &pressure_unit);
put_format_loc(b, translate("gettextFromC", "P: %d%s (%s)\n"), pressurevalue, pressure_unit, gasname(mix)); put_format_loc(b, translate("gettextFromC", "P: %d%s (%s)\n"), pressurevalue, pressure_unit, gasname(mix));
} }
@ -1569,7 +1569,7 @@ static void plot_string(const struct plot_info *pi, int idx, struct membuffer *b
strip_mb(b); strip_mb(b);
} }
int get_plot_details_new(const struct plot_info *pi, int time, struct membuffer *mb) int get_plot_details_new(const struct dive *d, const struct plot_info *pi, int time, struct membuffer *mb)
{ {
int i; int i;
@ -1580,7 +1580,7 @@ int get_plot_details_new(const struct plot_info *pi, int time, struct membuffer
if (pi->entry[i].sec >= time) if (pi->entry[i].sec >= time)
break; break;
} }
plot_string(pi, i, mb); plot_string(d, pi, i, mb);
return i; return i;
} }

View file

@ -84,7 +84,7 @@ extern void compare_samples(struct plot_info *p1, int idx1, int idx2, char *buf,
extern void init_plot_info(struct plot_info *pi); extern void init_plot_info(struct plot_info *pi);
/* when planner_dc is non-null, this is called in planner mode. */ /* when planner_dc is non-null, this is called in planner mode. */
extern void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool fast, const struct deco_state *planner_ds); extern void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool fast, const struct deco_state *planner_ds);
extern int get_plot_details_new(const struct plot_info *pi, int time, struct membuffer *); extern int get_plot_details_new(const struct dive *d, const struct plot_info *pi, int time, struct membuffer *);
extern void free_plot_info_data(struct plot_info *pi); extern void free_plot_info_data(struct plot_info *pi);
/* /*

View file

@ -222,7 +222,7 @@ void ToolTipItem::setTimeAxis(DiveCartesianAxis *axis)
timeAxis = axis; timeAxis = axis;
} }
void ToolTipItem::refresh(const QPointF &pos) void ToolTipItem::refresh(const dive *d, const QPointF &pos)
{ {
static QPixmap tissues(16,60); static QPixmap tissues(16,60);
static QPainter painter(&tissues); static QPainter painter(&tissues);
@ -238,7 +238,7 @@ void ToolTipItem::refresh(const QPointF &pos)
clear(); clear();
mb.len = 0; mb.len = 0;
int idx = get_plot_details_new(&pInfo, time, &mb); int idx = get_plot_details_new(d, &pInfo, time, &mb);
tissues.fill(); tissues.fill();
painter.setPen(QColor(0, 0, 0, 0)); painter.setPen(QColor(0, 0, 0, 0));

View file

@ -36,7 +36,7 @@ public:
void expand(); void expand();
void clear(); void clear();
void addToolTip(const QString &toolTip, const QIcon &icon = QIcon(), const QPixmap &pixmap = QPixmap()); void addToolTip(const QString &toolTip, const QIcon &icon = QIcon(), const QPixmap &pixmap = QPixmap());
void refresh(const QPointF &pos); void refresh(const dive *d, const QPointF &pos);
bool isExpanded() const; bool isExpanded() const;
void persistPos(); void persistPos();
void readPos(); void readPos();

View file

@ -809,7 +809,7 @@ void ProfileWidget2::plotDive(const struct dive *d, bool force, bool doClearPict
else else
plotPicturesInternal(d, instant); plotPicturesInternal(d, instant);
toolTipItem->refresh(mapToScene(mapFromGlobal(QCursor::pos()))); toolTipItem->refresh(&displayed_dive, mapToScene(mapFromGlobal(QCursor::pos())));
#endif #endif
// OK, how long did this take us? Anything above the second is way too long, // OK, how long did this take us? Anything above the second is way too long,
@ -1025,7 +1025,7 @@ void ProfileWidget2::scrollViewTo(const QPoint &pos)
void ProfileWidget2::mouseMoveEvent(QMouseEvent *event) void ProfileWidget2::mouseMoveEvent(QMouseEvent *event)
{ {
QPointF pos = mapToScene(event->pos()); QPointF pos = mapToScene(event->pos());
toolTipItem->refresh(mapToScene(mapFromGlobal(QCursor::pos()))); toolTipItem->refresh(&displayed_dive, mapToScene(mapFromGlobal(QCursor::pos())));
if (zoomLevel == 0) { if (zoomLevel == 0) {
QGraphicsView::mouseMoveEvent(event); QGraphicsView::mouseMoveEvent(event);