2017-04-27 18:26:36 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "profile-widget/tankitem.h"
|
2020-12-23 11:39:07 +00:00
|
|
|
#include "profile-widget/divecartesianaxis.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "profile-widget/divetextitem.h"
|
2020-12-23 11:39:07 +00:00
|
|
|
#include "core/dive.h"
|
2020-10-25 08:14:16 +00:00
|
|
|
#include "core/event.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "core/profile.h"
|
2014-08-18 16:47:18 +00:00
|
|
|
#include <QPen>
|
2014-08-15 00:22:27 +00:00
|
|
|
|
2019-10-27 17:32:04 +00:00
|
|
|
static const qreal height = 3.0;
|
|
|
|
|
2021-08-09 14:48:08 +00:00
|
|
|
TankItem::TankItem(const DiveCartesianAxis &axis, double dpr) :
|
2020-12-23 11:33:05 +00:00
|
|
|
hAxis(axis),
|
2021-06-03 15:19:38 +00:00
|
|
|
plotEndTime(-1),
|
2021-08-09 14:48:08 +00:00
|
|
|
dpr(dpr)
|
2014-08-15 00:22:27 +00:00
|
|
|
{
|
2014-08-15 03:40:47 +00:00
|
|
|
QColor red(PERSIANRED1);
|
|
|
|
QColor blue(AIR_BLUE);
|
|
|
|
QColor yellow(NITROX_YELLOW);
|
|
|
|
QColor green(NITROX_GREEN);
|
2014-08-15 13:30:31 +00:00
|
|
|
QLinearGradient nitroxGradient(QPointF(0, 0), QPointF(0, height));
|
2014-08-15 03:40:47 +00:00
|
|
|
nitroxGradient.setColorAt(0.0, green);
|
|
|
|
nitroxGradient.setColorAt(0.49, green);
|
|
|
|
nitroxGradient.setColorAt(0.5, yellow);
|
|
|
|
nitroxGradient.setColorAt(1.0, yellow);
|
|
|
|
nitrox = nitroxGradient;
|
2015-01-05 19:24:34 +00:00
|
|
|
oxygen = green;
|
2014-08-15 13:30:31 +00:00
|
|
|
QLinearGradient trimixGradient(QPointF(0, 0), QPointF(0, height));
|
2014-08-15 03:40:47 +00:00
|
|
|
trimixGradient.setColorAt(0.0, green);
|
|
|
|
trimixGradient.setColorAt(0.49, green);
|
|
|
|
trimixGradient.setColorAt(0.5, red);
|
|
|
|
trimixGradient.setColorAt(1.0, red);
|
|
|
|
trimix = trimixGradient;
|
|
|
|
air = blue;
|
2014-12-18 07:47:53 +00:00
|
|
|
}
|
|
|
|
|
2019-10-27 16:48:04 +00:00
|
|
|
void TankItem::createBar(int startTime, int stopTime, struct gasmix gas)
|
2014-08-15 03:40:47 +00:00
|
|
|
{
|
2020-12-23 11:33:05 +00:00
|
|
|
qreal x = hAxis.posAtValue(startTime);
|
|
|
|
qreal w = hAxis.posAtValue(stopTime) - hAxis.posAtValue(startTime);
|
2019-10-27 16:48:04 +00:00
|
|
|
|
2014-08-15 03:40:47 +00:00
|
|
|
// pick the right gradient, size, position and text
|
2014-08-15 13:30:31 +00:00
|
|
|
QGraphicsRectItem *rect = new QGraphicsRectItem(x, 0, w, height, this);
|
2014-08-15 03:40:47 +00:00
|
|
|
if (gasmix_is_air(gas))
|
|
|
|
rect->setBrush(air);
|
2018-08-16 17:10:10 +00:00
|
|
|
else if (gas.he.permille)
|
2014-08-15 03:40:47 +00:00
|
|
|
rect->setBrush(trimix);
|
2018-08-16 17:10:10 +00:00
|
|
|
else if (gas.o2.permille == 1000)
|
2015-01-05 19:24:34 +00:00
|
|
|
rect->setBrush(oxygen);
|
2014-08-15 03:40:47 +00:00
|
|
|
else
|
|
|
|
rect->setBrush(nitrox);
|
2014-08-18 16:47:18 +00:00
|
|
|
rect->setPen(QPen(QBrush(), 0.0)); // get rid of the thick line around the rectangle
|
2014-08-15 03:40:47 +00:00
|
|
|
rects.push_back(rect);
|
2021-08-12 20:57:57 +00:00
|
|
|
DiveTextItem *label = new DiveTextItem(dpr, 1.0, Qt::AlignBottom | Qt::AlignRight, rect);
|
2014-08-15 03:40:47 +00:00
|
|
|
label->setText(gasname(gas));
|
|
|
|
label->setBrush(Qt::black);
|
2014-08-15 13:30:31 +00:00
|
|
|
label->setPos(x + 1, 0);
|
2017-02-04 09:46:02 +00:00
|
|
|
#ifdef SUBSURFACE_MOBILE
|
|
|
|
label->setPos(x + 1, -2.5);
|
|
|
|
#endif
|
2014-08-15 03:40:47 +00:00
|
|
|
label->setZValue(101);
|
|
|
|
}
|
|
|
|
|
2021-01-11 17:54:48 +00:00
|
|
|
void TankItem::setData(const struct plot_info *plotInfo, const struct dive *d)
|
2014-08-15 00:22:27 +00:00
|
|
|
{
|
2021-01-03 20:57:59 +00:00
|
|
|
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.
|
2021-01-11 17:54:48 +00:00
|
|
|
const struct plot_data *last_entry = &plotInfo->entry[plotInfo->nr - 1];
|
2021-01-03 20:57:59 +00:00
|
|
|
plotEndTime = last_entry->sec;
|
|
|
|
|
2014-08-15 00:22:27 +00:00
|
|
|
// We don't have enougth data to calculate things, quit.
|
2019-10-27 17:08:07 +00:00
|
|
|
if (plotEndTime < 0)
|
2014-08-15 00:22:27 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// remove the old rectangles
|
2019-04-03 18:25:35 +00:00
|
|
|
qDeleteAll(rects);
|
2014-08-15 00:22:27 +00:00
|
|
|
rects.clear();
|
|
|
|
|
2019-08-04 17:39:47 +00:00
|
|
|
// Bail if there are no cylinders
|
2021-01-03 20:57:59 +00:00
|
|
|
if (d->cylinders.nr <= 0)
|
2019-08-04 17:39:47 +00:00
|
|
|
return;
|
|
|
|
|
2021-01-03 20:57:59 +00:00
|
|
|
// get the information directly from the displayed dive
|
|
|
|
// (get_dive_dc() always returns a valid dive computer)
|
2021-01-11 17:54:48 +00:00
|
|
|
const struct divecomputer *dc = get_dive_dc_const(d, dc_number);
|
2017-09-14 03:29:20 +00:00
|
|
|
|
|
|
|
// start with the first gasmix and at the start of the dive
|
2021-01-03 20:57:59 +00:00
|
|
|
int cyl = explicit_first_cylinder(d, dc);
|
|
|
|
struct gasmix gasmix = get_cylinder(d, cyl)->gasmix;
|
2017-09-14 03:29:20 +00:00
|
|
|
int startTime = 0;
|
|
|
|
|
|
|
|
// work through all the gas changes and add the rectangle for each gas while it was used
|
2018-08-16 22:58:30 +00:00
|
|
|
const struct event *ev = get_next_event(dc->events, "gaschange");
|
2019-10-27 17:08:07 +00:00
|
|
|
while (ev && (int)ev->time.seconds < plotEndTime) {
|
2019-10-27 16:48:04 +00:00
|
|
|
createBar(startTime, ev->time.seconds, gasmix);
|
2017-09-14 03:29:20 +00:00
|
|
|
startTime = ev->time.seconds;
|
2021-01-03 20:57:59 +00:00
|
|
|
gasmix = get_gasmix_from_event(d, ev);
|
2017-09-14 03:29:20 +00:00
|
|
|
ev = get_next_event(ev->next, "gaschange");
|
2014-08-15 00:22:27 +00:00
|
|
|
}
|
2019-10-27 17:08:07 +00:00
|
|
|
createBar(startTime, plotEndTime, gasmix);
|
2014-08-15 00:22:27 +00:00
|
|
|
}
|