From 85d1e1d19929326e2324488850b54f7e80554af3 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 8 Oct 2021 21:28:32 +0200 Subject: [PATCH] profile: only plot visible range of tank info This was a rather trivial change: simply pass in the first and the last second to the plot function. Signed-off-by: Berthold Stoeger --- profile-widget/profilescene.cpp | 2 +- profile-widget/tankitem.cpp | 35 ++++++++++++++++----------------- profile-widget/tankitem.h | 2 +- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/profile-widget/profilescene.cpp b/profile-widget/profilescene.cpp index 8a436effe..ef5541519 100644 --- a/profile-widget/profilescene.cpp +++ b/profile-widget/profilescene.cpp @@ -447,7 +447,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM ocpo2GasItem->setVisible(false); } #endif - tankItem->setData(&plotInfo, d); + tankItem->setData(d, firstSecond, lastSecond); if (ppGraphsEnabled()) { double max = prefs.pp_graphs.phe ? dataModel->pheMax() : -1; diff --git a/profile-widget/tankitem.cpp b/profile-widget/tankitem.cpp index ff4bd99d3..8377cbfdd 100644 --- a/profile-widget/tankitem.cpp +++ b/profile-widget/tankitem.cpp @@ -64,27 +64,19 @@ void TankItem::createBar(int startTime, int stopTime, struct gasmix gas) label->setZValue(101); } -void TankItem::setData(const struct plot_info *plotInfo, const struct dive *d) +void TankItem::setData(const struct dive *d, int plotStartTime, int plotEndTime) { - if (!d) - return; - - // If there is nothing to plot, quit early. - if (plotInfo->nr <= 0) - return; - - // Find correct end of the dive plot for correct end of the tankbar. - const struct plot_data *last_entry = &plotInfo->entry[plotInfo->nr - 1]; - int plotEndTime = last_entry->sec; - - // We don't have enougth data to calculate things, quit. - if (plotEndTime < 0) - return; - // remove the old rectangles qDeleteAll(rects); rects.clear(); + if (!d) + return; + + // We don't have enougth data to calculate things, quit. + if (plotEndTime < 0 || plotEndTime <= plotStartTime) + return; + // Bail if there are no cylinders if (d->cylinders.nr <= 0) return; @@ -96,15 +88,22 @@ void TankItem::setData(const struct plot_info *plotInfo, const struct dive *d) // start with the first gasmix and at the start of the dive int cyl = explicit_first_cylinder(d, dc); struct gasmix gasmix = get_cylinder(d, cyl)->gasmix; - int startTime = 0; + + // skip over all gas changes before the plotted range + const struct event *ev = get_next_event(dc->events, "gaschange"); + while (ev && (int)ev->time.seconds <= plotStartTime) + ev = get_next_event(ev->next, "gaschange"); // work through all the gas changes and add the rectangle for each gas while it was used - const struct event *ev = get_next_event(dc->events, "gaschange"); + int startTime = plotStartTime; while (ev && (int)ev->time.seconds < plotEndTime) { + gasmix = get_gasmix_from_event(d, ev); createBar(startTime, ev->time.seconds, gasmix); startTime = ev->time.seconds; gasmix = get_gasmix_from_event(d, ev); ev = get_next_event(ev->next, "gaschange"); } + if (ev) + gasmix = get_gasmix_from_event(d, ev); createBar(startTime, plotEndTime, gasmix); } diff --git a/profile-widget/tankitem.h b/profile-widget/tankitem.h index 66a942a8c..895c313f7 100644 --- a/profile-widget/tankitem.h +++ b/profile-widget/tankitem.h @@ -14,7 +14,7 @@ class TankItem : public QGraphicsRectItem { public: explicit TankItem(const DiveCartesianAxis &axis, double dpr); - void setData(const struct plot_info *plotInfo, const struct dive *d); + void setData(const struct dive *d, int plotStartTime, int plotEndTime); double height() const; private: