From 0146a0c8925e243d808a4e5488d068d6f8f065b6 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 3 Jan 2021 21:57:59 +0100 Subject: profile: remove displayed_dive from TankItem The only time the TankItem is replot is when new data is set. Therefore, replot() can be folded into setData(). The good thing is that setData() is passed the dive to be plot. So the data can be extracted from there instead of the global displayed_dive variable. Signed-off-by: Berthold Stoeger --- profile-widget/tankitem.cpp | 43 +++++++++++++++++++++---------------------- profile-widget/tankitem.h | 1 - 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/profile-widget/tankitem.cpp b/profile-widget/tankitem.cpp index 6fde6203b..48d755dcf 100644 --- a/profile-widget/tankitem.cpp +++ b/profile-widget/tankitem.cpp @@ -33,21 +33,6 @@ TankItem::TankItem(const DiveCartesianAxis &axis) : air = blue; } -void TankItem::setData(struct plot_info *plotInfo, struct dive *d) -{ - // If there is nothing to plot, quit early. - if (plotInfo->nr <= 0) { - plotEndTime = -1; - return; - } - - // Find correct end of the dive plot for correct end of the tankbar. - struct plot_data *last_entry = &plotInfo->entry[plotInfo->nr - 1]; - plotEndTime = last_entry->sec; - - replot(); -} - void TankItem::createBar(int startTime, int stopTime, struct gasmix gas) { qreal x = hAxis.posAtValue(startTime); @@ -76,8 +61,21 @@ void TankItem::createBar(int startTime, int stopTime, struct gasmix gas) label->setZValue(101); } -void TankItem::replot() +void TankItem::setData(struct plot_info *plotInfo, struct dive *d) { + if (!d) + return; + + // If there is nothing to plot, quit early. + if (plotInfo->nr <= 0) { + plotEndTime = -1; + return; + } + + // Find correct end of the dive plot for correct end of the tankbar. + struct plot_data *last_entry = &plotInfo->entry[plotInfo->nr - 1]; + plotEndTime = last_entry->sec; + // We don't have enougth data to calculate things, quit. if (plotEndTime < 0) return; @@ -87,15 +85,16 @@ void TankItem::replot() rects.clear(); // Bail if there are no cylinders - if (displayed_dive.cylinders.nr <= 0) + if (d->cylinders.nr <= 0) return; - // get the information directly from the displayed_dive (the dc always exists) - struct divecomputer *dc = get_dive_dc(&displayed_dive, dc_number); + // get the information directly from the displayed dive + // (get_dive_dc() always returns a valid dive computer) + struct divecomputer *dc = get_dive_dc(d, dc_number); // start with the first gasmix and at the start of the dive - int cyl = explicit_first_cylinder(&displayed_dive, dc); - struct gasmix gasmix = get_cylinder(&displayed_dive, cyl)->gasmix; + int cyl = explicit_first_cylinder(d, dc); + struct gasmix gasmix = get_cylinder(d, cyl)->gasmix; int startTime = 0; // work through all the gas changes and add the rectangle for each gas while it was used @@ -103,7 +102,7 @@ void TankItem::replot() while (ev && (int)ev->time.seconds < plotEndTime) { createBar(startTime, ev->time.seconds, gasmix); startTime = ev->time.seconds; - gasmix = get_gasmix_from_event(&displayed_dive, ev); + gasmix = get_gasmix_from_event(d, ev); ev = get_next_event(ev->next, "gaschange"); } createBar(startTime, plotEndTime, gasmix); diff --git a/profile-widget/tankitem.h b/profile-widget/tankitem.h index 265407cde..9890eb93d 100644 --- a/profile-widget/tankitem.h +++ b/profile-widget/tankitem.h @@ -18,7 +18,6 @@ public: private: void createBar(int startTime, int stopTime, struct gasmix gas); - void replot(); const DiveCartesianAxis &hAxis; int plotEndTime; QBrush air, nitrox, oxygen, trimix; -- cgit v1.2.3-70-g09d2