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/diveeventitem.h"
|
|
|
|
#include "qt-models/diveplotdatamodel.h"
|
|
|
|
#include "profile-widget/divecartesianaxis.h"
|
|
|
|
#include "profile-widget/animationfunctions.h"
|
|
|
|
#include "core/libdivecomputer.h"
|
|
|
|
#include "core/profile.h"
|
|
|
|
#include "core/gettextfromc.h"
|
|
|
|
#include "core/metrics.h"
|
2018-01-21 13:58:00 +00:00
|
|
|
#include "core/membuffer.h"
|
2014-01-16 17:02:32 +00:00
|
|
|
|
2014-03-16 04:12:34 +00:00
|
|
|
extern struct ev_select *ev_namelist;
|
|
|
|
extern int evn_used;
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
DiveEventItem::DiveEventItem(QObject *parent) : DivePixmapItem(parent),
|
|
|
|
vAxis(NULL),
|
|
|
|
hAxis(NULL),
|
|
|
|
dataModel(NULL),
|
|
|
|
internalEvent(NULL)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
|
|
|
setFlag(ItemIgnoresTransformations);
|
|
|
|
}
|
|
|
|
|
2015-12-04 05:42:23 +00:00
|
|
|
DiveEventItem::~DiveEventItem()
|
|
|
|
{
|
|
|
|
free(internalEvent);
|
|
|
|
}
|
2014-01-16 17:02:32 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DiveEventItem::setHorizontalAxis(DiveCartesianAxis *axis)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
|
|
|
hAxis = axis;
|
2014-02-15 23:05:47 +00:00
|
|
|
recalculatePos(true);
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DiveEventItem::setModel(DivePlotDataModel *model)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
|
|
|
dataModel = model;
|
2014-02-15 23:05:47 +00:00
|
|
|
recalculatePos(true);
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DiveEventItem::setVerticalAxis(DiveCartesianAxis *axis)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
|
|
|
vAxis = axis;
|
2014-02-15 23:05:47 +00:00
|
|
|
recalculatePos(true);
|
|
|
|
connect(vAxis, SIGNAL(sizeChanged()), this, SLOT(recalculatePos()));
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 20:27:12 +00:00
|
|
|
struct event *DiveEventItem::getEvent()
|
|
|
|
{
|
|
|
|
return internalEvent;
|
|
|
|
}
|
|
|
|
|
2018-01-20 16:58:52 +00:00
|
|
|
void DiveEventItem::setEvent(struct event *ev, struct gasmix *lastgasmix)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
2014-02-23 16:35:06 +00:00
|
|
|
if (!ev)
|
|
|
|
return;
|
2015-12-04 05:42:23 +00:00
|
|
|
|
|
|
|
free(internalEvent);
|
|
|
|
internalEvent = clone_event(ev);
|
2018-01-20 17:21:39 +00:00
|
|
|
setupPixmap(lastgasmix);
|
2018-01-20 16:58:52 +00:00
|
|
|
setupToolTipString(lastgasmix);
|
2014-02-15 23:05:47 +00:00
|
|
|
recalculatePos(true);
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
2018-01-20 17:21:39 +00:00
|
|
|
void DiveEventItem::setupPixmap(struct gasmix *lastgasmix)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
2014-10-19 14:15:18 +00:00
|
|
|
const IconMetrics& metrics = defaultIconMetrics();
|
2016-02-06 05:27:52 +00:00
|
|
|
#ifndef SUBSURFACE_MOBILE
|
2014-10-19 14:15:18 +00:00
|
|
|
int sz_bigger = metrics.sz_med + metrics.sz_small; // ex 40px
|
2016-03-28 21:43:40 +00:00
|
|
|
#else
|
|
|
|
#if defined(Q_OS_IOS)
|
|
|
|
// on iOS devices we need to adjust for Device Pixel Ratio
|
|
|
|
int sz_bigger = metrics.sz_med * metrics.dpr;
|
2016-02-06 05:27:52 +00:00
|
|
|
#else
|
2017-11-13 19:04:59 +00:00
|
|
|
// SUBSURFACE_MOBILE, seems a little big from the code,
|
|
|
|
// but looks fine on device
|
|
|
|
int sz_bigger = metrics.sz_big + metrics.sz_med;
|
2016-03-28 21:43:40 +00:00
|
|
|
#endif
|
2016-02-06 05:27:52 +00:00
|
|
|
#endif
|
2014-10-19 14:15:18 +00:00
|
|
|
int sz_pix = sz_bigger/2; // ex 20px
|
|
|
|
|
|
|
|
#define EVENT_PIXMAP(PIX) QPixmap(QString(PIX)).scaled(sz_pix, sz_pix, Qt::KeepAspectRatio, Qt::SmoothTransformation)
|
|
|
|
#define EVENT_PIXMAP_BIGGER(PIX) QPixmap(QString(PIX)).scaled(sz_bigger, sz_bigger, Qt::KeepAspectRatio, Qt::SmoothTransformation)
|
2018-01-07 10:12:48 +00:00
|
|
|
if (empty_string(internalEvent->name)) {
|
2017-11-29 09:57:08 +00:00
|
|
|
setPixmap(EVENT_PIXMAP(":status-warning-icon"));
|
2014-04-03 19:16:15 +00:00
|
|
|
} else if (internalEvent->type == SAMPLE_EVENT_BOOKMARK) {
|
2017-11-29 09:57:08 +00:00
|
|
|
setPixmap(EVENT_PIXMAP(":dive-bookmark-icon"));
|
2017-10-19 19:55:46 +00:00
|
|
|
} else if (event_is_gaschange(internalEvent)) {
|
|
|
|
struct gasmix *mix = get_gasmix_from_event(&displayed_dive, internalEvent);
|
2018-01-20 17:21:39 +00:00
|
|
|
struct icd_data icd_data;
|
|
|
|
bool icd = isobaric_counterdiffusion(lastgasmix, mix, &icd_data);
|
|
|
|
if (mix->he.permille) {
|
|
|
|
if (icd)
|
|
|
|
setPixmap(EVENT_PIXMAP_BIGGER(":gaschange-trimix-ICD-icon"));
|
|
|
|
else
|
|
|
|
setPixmap(EVENT_PIXMAP_BIGGER(":gaschange-trimix-icon"));
|
|
|
|
} else if (gasmix_is_air(mix)) {
|
|
|
|
if (icd)
|
|
|
|
setPixmap(EVENT_PIXMAP_BIGGER(":gaschange-air-ICD-icon"));
|
|
|
|
else
|
|
|
|
setPixmap(EVENT_PIXMAP_BIGGER(":gaschange-air-icon"));
|
|
|
|
} else if (mix->o2.permille == 1000) {
|
|
|
|
if (icd)
|
|
|
|
setPixmap(EVENT_PIXMAP_BIGGER(":gaschange-oxygen-ICD-icon"));
|
|
|
|
else
|
|
|
|
setPixmap(EVENT_PIXMAP_BIGGER(":gaschange-oxygen-icon"));
|
|
|
|
} else {
|
|
|
|
if (icd)
|
|
|
|
setPixmap(EVENT_PIXMAP_BIGGER(":gaschange-ean-ICD-icon"));
|
|
|
|
else
|
|
|
|
setPixmap(EVENT_PIXMAP_BIGGER(":gaschange-ean-icon"));
|
|
|
|
}
|
2016-07-23 07:08:41 +00:00
|
|
|
#ifdef SAMPLE_FLAGS_SEVERITY_SHIFT
|
|
|
|
} else if ((((internalEvent->flags & SAMPLE_FLAGS_SEVERITY_MASK) >> SAMPLE_FLAGS_SEVERITY_SHIFT) == 1) ||
|
|
|
|
// those are useless internals of the dive computer
|
|
|
|
#else
|
|
|
|
} else if (
|
|
|
|
#endif
|
2016-07-23 08:48:34 +00:00
|
|
|
same_string_caseinsensitive(internalEvent->name, "heading") ||
|
|
|
|
(same_string_caseinsensitive(internalEvent->name, "SP change") && internalEvent->time.seconds == 0)) {
|
2015-02-07 16:47:59 +00:00
|
|
|
// 2 cases:
|
|
|
|
// a) some dive computers have heading in every sample
|
|
|
|
// b) at t=0 we might have an "SP change" to indicate dive type
|
|
|
|
// in both cases we want to get the right data into the tooltip but don't want the visual clutter
|
|
|
|
// so set an "almost invisible" pixmap (a narrow but somewhat tall, basically transparent pixmap)
|
2014-11-14 19:52:55 +00:00
|
|
|
// that allows tooltips to work when we don't want to show a specific
|
|
|
|
// pixmap for an event, but want to show the event value in the tooltip
|
|
|
|
QPixmap transparentPixmap(4, 20);
|
|
|
|
transparentPixmap.fill(QColor::fromRgbF(1.0, 1.0, 1.0, 0.01));
|
|
|
|
setPixmap(transparentPixmap);
|
2016-07-23 07:08:41 +00:00
|
|
|
#ifdef SAMPLE_FLAGS_SEVERITY_SHIFT
|
|
|
|
} else if (((internalEvent->flags & SAMPLE_FLAGS_SEVERITY_MASK) >> SAMPLE_FLAGS_SEVERITY_SHIFT) == 2) {
|
2017-11-29 09:57:08 +00:00
|
|
|
setPixmap(EVENT_PIXMAP(":status-info-icon"));
|
2016-07-23 07:08:41 +00:00
|
|
|
} else if (((internalEvent->flags & SAMPLE_FLAGS_SEVERITY_MASK) >> SAMPLE_FLAGS_SEVERITY_SHIFT) == 3) {
|
2017-11-29 09:57:08 +00:00
|
|
|
setPixmap(EVENT_PIXMAP(":status-warning-icon"));
|
2016-07-23 07:08:41 +00:00
|
|
|
} else if (((internalEvent->flags & SAMPLE_FLAGS_SEVERITY_MASK) >> SAMPLE_FLAGS_SEVERITY_SHIFT) == 4) {
|
2017-11-29 09:57:08 +00:00
|
|
|
setPixmap(EVENT_PIXMAP(":status-violation-icon"));
|
2016-07-23 07:08:41 +00:00
|
|
|
#endif
|
2016-07-23 08:48:34 +00:00
|
|
|
} else if (same_string_caseinsensitive(internalEvent->name, "violation") || // generic libdivecomputer
|
|
|
|
same_string_caseinsensitive(internalEvent->name, "Safety stop violation") || // the rest are from the Uemis downloader
|
|
|
|
same_string_caseinsensitive(internalEvent->name, "pO₂ ascend alarm") ||
|
|
|
|
same_string_caseinsensitive(internalEvent->name, "RGT alert") ||
|
|
|
|
same_string_caseinsensitive(internalEvent->name, "Dive time alert") ||
|
|
|
|
same_string_caseinsensitive(internalEvent->name, "Low battery alert") ||
|
|
|
|
same_string_caseinsensitive(internalEvent->name, "Speed alarm")) {
|
2017-11-29 09:57:08 +00:00
|
|
|
setPixmap(EVENT_PIXMAP(":status-violation-icon"));
|
2016-07-23 08:48:34 +00:00
|
|
|
} else if (same_string_caseinsensitive(internalEvent->name, "non stop time") || // generic libdivecomputer
|
|
|
|
same_string_caseinsensitive(internalEvent->name, "safety stop") ||
|
|
|
|
same_string_caseinsensitive(internalEvent->name, "safety stop (voluntary)") ||
|
|
|
|
same_string_caseinsensitive(internalEvent->name, "Tank change suggested") || // Uemis downloader
|
|
|
|
same_string_caseinsensitive(internalEvent->name, "Marker")) {
|
2017-11-29 09:57:08 +00:00
|
|
|
setPixmap(EVENT_PIXMAP(":status-info-icon"));
|
2014-01-16 17:02:32 +00:00
|
|
|
} else {
|
2016-07-23 07:08:41 +00:00
|
|
|
// we should do some guessing based on the type / name of the event;
|
|
|
|
// for now they all get the warning icon
|
2017-11-29 09:57:08 +00:00
|
|
|
setPixmap(EVENT_PIXMAP(":status-warning-icon"));
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
|
|
|
#undef EVENT_PIXMAP
|
2016-07-22 00:00:35 +00:00
|
|
|
#undef EVENT_PIXMAP_BIGGER
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
2018-01-20 16:58:52 +00:00
|
|
|
void DiveEventItem::setupToolTipString(struct gasmix *lastgasmix)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
2014-02-25 20:27:12 +00:00
|
|
|
// we display the event on screen - so translate
|
2014-04-30 05:37:19 +00:00
|
|
|
QString name = gettextFromC::instance()->tr(internalEvent->name);
|
2014-02-25 20:27:12 +00:00
|
|
|
int value = internalEvent->value;
|
2014-04-30 05:37:19 +00:00
|
|
|
int type = internalEvent->type;
|
2015-01-03 06:09:01 +00:00
|
|
|
|
Start using the actual cylinder data for gas switch events
Now that gas switch events always have indices into the cylinder table,
start using that to look up the gas mix from the cylinders rather than
from the gas switch event itself. In other words, the cylinder index is
now the primary data for gas switch events.
This means that now as you change the cylinder information, the gas
switch events will automatically update to reflect those changes.
Note that on loading data from the outside (either from a xml file, from
a git/cloud account, or from a dive computer), we may or may not
initially have an index for the gas change event. The external data may
be from an older version of subsurface, or it may be from a
libdivecomputer download that just doesn't give index data at all.
In that case, we will do:
- if there is no index, but there is explicit gas mix information, we
will look up the index based on that gas mix, picking the cylinder
that has the closest mix.
- if there isn't even explicit gas mix data, so we only have the event
value from libdivecomputer, we will turn that value into a gasmix,
and use that to look up the cylinder index as above.
- if no valid cylinder information is available at all, gas switch
events will just be dropped.
When saving the data, we now always save the cylinder index, and the gas
mix associated with that cylinder (that gas mix will be ignored on load,
since the index is the primary, but it makes the event much easier to
read).
It is worth noting we do not modify the libdivecomputer value, even if
the gasmix has changed, so that remains as a record of the original
download.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-02 21:07:06 +00:00
|
|
|
if (event_is_gaschange(internalEvent)) {
|
2018-01-20 20:39:38 +00:00
|
|
|
struct icd_data icd_data;
|
Start using the actual cylinder data for gas switch events
Now that gas switch events always have indices into the cylinder table,
start using that to look up the gas mix from the cylinders rather than
from the gas switch event itself. In other words, the cylinder index is
now the primary data for gas switch events.
This means that now as you change the cylinder information, the gas
switch events will automatically update to reflect those changes.
Note that on loading data from the outside (either from a xml file, from
a git/cloud account, or from a dive computer), we may or may not
initially have an index for the gas change event. The external data may
be from an older version of subsurface, or it may be from a
libdivecomputer download that just doesn't give index data at all.
In that case, we will do:
- if there is no index, but there is explicit gas mix information, we
will look up the index based on that gas mix, picking the cylinder
that has the closest mix.
- if there isn't even explicit gas mix data, so we only have the event
value from libdivecomputer, we will turn that value into a gasmix,
and use that to look up the cylinder index as above.
- if no valid cylinder information is available at all, gas switch
events will just be dropped.
When saving the data, we now always save the cylinder index, and the gas
mix associated with that cylinder (that gas mix will be ignored on load,
since the index is the primary, but it makes the event much easier to
read).
It is worth noting we do not modify the libdivecomputer value, even if
the gasmix has changed, so that remains as a record of the original
download.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-02 21:07:06 +00:00
|
|
|
struct gasmix *mix = get_gasmix_from_event(&displayed_dive, internalEvent);
|
2018-01-21 13:58:00 +00:00
|
|
|
struct membuffer mb = {};
|
Start using the actual cylinder data for gas switch events
Now that gas switch events always have indices into the cylinder table,
start using that to look up the gas mix from the cylinders rather than
from the gas switch event itself. In other words, the cylinder index is
now the primary data for gas switch events.
This means that now as you change the cylinder information, the gas
switch events will automatically update to reflect those changes.
Note that on loading data from the outside (either from a xml file, from
a git/cloud account, or from a dive computer), we may or may not
initially have an index for the gas change event. The external data may
be from an older version of subsurface, or it may be from a
libdivecomputer download that just doesn't give index data at all.
In that case, we will do:
- if there is no index, but there is explicit gas mix information, we
will look up the index based on that gas mix, picking the cylinder
that has the closest mix.
- if there isn't even explicit gas mix data, so we only have the event
value from libdivecomputer, we will turn that value into a gasmix,
and use that to look up the cylinder index as above.
- if no valid cylinder information is available at all, gas switch
events will just be dropped.
When saving the data, we now always save the cylinder index, and the gas
mix associated with that cylinder (that gas mix will be ignored on load,
since the index is the primary, but it makes the event much easier to
read).
It is worth noting we do not modify the libdivecomputer value, even if
the gasmix has changed, so that remains as a record of the original
download.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-02 21:07:06 +00:00
|
|
|
name += ": ";
|
|
|
|
name += gasname(mix);
|
|
|
|
|
|
|
|
/* Do we have an explicit cylinder index? Show it. */
|
|
|
|
if (internalEvent->gas.index >= 0)
|
2017-02-21 17:04:00 +00:00
|
|
|
name += tr(" (cyl. %1)").arg(internalEvent->gas.index + 1);
|
2018-01-20 20:39:38 +00:00
|
|
|
bool icd = isobaric_counterdiffusion(lastgasmix, mix, &icd_data);
|
|
|
|
if (icd_data.dHe < 0) {
|
2018-01-24 19:50:35 +00:00
|
|
|
put_format(&mb, "\n%s %s:%+.3g%% %s:%+.3g%%%s%+.3g%%",
|
2018-02-25 12:51:41 +00:00
|
|
|
qPrintable(tr("ICD")),
|
|
|
|
qPrintable(tr("ΔHe")), icd_data.dHe / 10.0,
|
|
|
|
qPrintable(tr("ΔN₂")), icd_data.dN2 / 10.0,
|
2018-01-24 19:50:35 +00:00
|
|
|
icd ? ">" : "<", lrint(-icd_data.dHe / 5.0) / 10.0);
|
2018-01-21 13:58:00 +00:00
|
|
|
name += QString::fromUtf8(mb.buffer, mb.len);
|
2018-01-22 19:29:55 +00:00
|
|
|
free_buffer(&mb);
|
2018-01-20 20:39:38 +00:00
|
|
|
}
|
2018-01-20 16:58:52 +00:00
|
|
|
*lastgasmix = *mix;
|
Start using the actual cylinder data for gas switch events
Now that gas switch events always have indices into the cylinder table,
start using that to look up the gas mix from the cylinders rather than
from the gas switch event itself. In other words, the cylinder index is
now the primary data for gas switch events.
This means that now as you change the cylinder information, the gas
switch events will automatically update to reflect those changes.
Note that on loading data from the outside (either from a xml file, from
a git/cloud account, or from a dive computer), we may or may not
initially have an index for the gas change event. The external data may
be from an older version of subsurface, or it may be from a
libdivecomputer download that just doesn't give index data at all.
In that case, we will do:
- if there is no index, but there is explicit gas mix information, we
will look up the index based on that gas mix, picking the cylinder
that has the closest mix.
- if there isn't even explicit gas mix data, so we only have the event
value from libdivecomputer, we will turn that value into a gasmix,
and use that to look up the cylinder index as above.
- if no valid cylinder information is available at all, gas switch
events will just be dropped.
When saving the data, we now always save the cylinder index, and the gas
mix associated with that cylinder (that gas mix will be ignored on load,
since the index is the primary, but it makes the event much easier to
read).
It is worth noting we do not modify the libdivecomputer value, even if
the gasmix has changed, so that remains as a record of the original
download.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-02 21:07:06 +00:00
|
|
|
} else if (value) {
|
2017-02-21 17:04:00 +00:00
|
|
|
if (type == SAMPLE_EVENT_PO2 && same_string(internalEvent->name, "SP change")) {
|
|
|
|
name += QString(": %1bar").arg((double)value / 1000, 0, 'f', 1);
|
2017-02-21 18:26:38 +00:00
|
|
|
} else if (type == SAMPLE_EVENT_CEILING && same_string(internalEvent->name, "planned waypoint above ceiling")) {
|
|
|
|
const char *depth_unit;
|
|
|
|
double depth_value = get_depth_units(value*1000, NULL, &depth_unit);
|
|
|
|
name += QString(": %1%2").arg((int) round(depth_value)).arg(depth_unit);
|
2014-01-16 17:02:32 +00:00
|
|
|
} else {
|
2017-02-21 17:04:00 +00:00
|
|
|
name += QString(": %1").arg(value);
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
2017-02-21 17:04:00 +00:00
|
|
|
} else if (type == SAMPLE_EVENT_PO2 && same_string(internalEvent->name, "SP change")) {
|
2014-05-05 16:28:58 +00:00
|
|
|
// this is a bad idea - we are abusing an existing event type that is supposed to
|
2017-03-06 12:36:42 +00:00
|
|
|
// warn of high or low pO₂ and are turning it into a setpoint change event
|
2017-02-21 17:04:00 +00:00
|
|
|
name += ":\n" + tr("Manual switch to OC");
|
2014-01-16 17:02:32 +00:00
|
|
|
} else {
|
2016-07-23 07:01:26 +00:00
|
|
|
name += internalEvent->flags & SAMPLE_FLAGS_BEGIN ? tr(" begin", "Starts with space!") :
|
|
|
|
internalEvent->flags & SAMPLE_FLAGS_END ? tr(" end", "Starts with space!") : "";
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
2014-02-25 20:27:12 +00:00
|
|
|
setToolTip(name);
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void DiveEventItem::eventVisibilityChanged(const QString &eventName, bool visible)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
2016-03-08 05:22:34 +00:00
|
|
|
//WARN: lookslike we should implement this.
|
|
|
|
Q_UNUSED(eventName);
|
|
|
|
Q_UNUSED(visible);
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
2014-03-16 22:10:03 +00:00
|
|
|
bool DiveEventItem::shouldBeHidden()
|
|
|
|
{
|
2014-07-01 19:07:38 +00:00
|
|
|
struct event *event = internalEvent;
|
2016-05-31 18:56:35 +00:00
|
|
|
struct dive *dive = &displayed_dive;
|
|
|
|
struct divecomputer *dc = get_dive_dc(dive, dc_number);
|
2014-07-01 19:07:38 +00:00
|
|
|
|
|
|
|
/*
|
2014-10-28 20:48:15 +00:00
|
|
|
* Some gas change events are special. Some dive computers just tell us the initial gas this way.
|
|
|
|
* Don't bother showing those
|
2014-07-01 19:07:38 +00:00
|
|
|
*/
|
2016-05-31 18:56:35 +00:00
|
|
|
struct sample *first_sample = &dc->sample[0];
|
2015-03-11 19:31:00 +00:00
|
|
|
if (!strcmp(event->name, "gaschange") &&
|
|
|
|
(event->time.seconds == 0 ||
|
|
|
|
(first_sample && event->time.seconds == first_sample->time.seconds)))
|
2014-10-28 20:48:15 +00:00
|
|
|
return true;
|
|
|
|
|
2016-05-31 18:56:35 +00:00
|
|
|
/*
|
|
|
|
* Some divecomputers give "surface" events that just aren't interesting.
|
|
|
|
* Like at the beginning or very end of a dive. Well, duh.
|
|
|
|
*/
|
|
|
|
if (!strcmp(event->name, "surface")) {
|
|
|
|
int time = event->time.seconds;
|
2016-07-23 07:12:16 +00:00
|
|
|
if (time <= 30 || time + 30 >= (int)dc->duration.seconds)
|
2016-05-31 18:56:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-16 22:10:03 +00:00
|
|
|
for (int i = 0; i < evn_used; i++) {
|
2014-07-01 19:07:38 +00:00
|
|
|
if (!strcmp(event->name, ev_namelist[i].ev_name) && ev_namelist[i].plot_ev == false)
|
2014-03-16 22:10:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-15 23:05:47 +00:00
|
|
|
void DiveEventItem::recalculatePos(bool instant)
|
2014-01-16 17:02:32 +00:00
|
|
|
{
|
2014-02-23 16:35:06 +00:00
|
|
|
if (!vAxis || !hAxis || !internalEvent || !dataModel)
|
2014-01-16 17:02:32 +00:00
|
|
|
return;
|
2014-02-23 16:35:06 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
QModelIndexList result = dataModel->match(dataModel->index(0, DivePlotDataModel::TIME), Qt::DisplayRole, internalEvent->time.seconds);
|
2014-01-16 23:30:47 +00:00
|
|
|
if (result.isEmpty()) {
|
2014-02-23 16:35:06 +00:00
|
|
|
Q_ASSERT("can't find a spot in the dataModel");
|
2014-01-16 17:02:32 +00:00
|
|
|
hide();
|
|
|
|
return;
|
|
|
|
}
|
2014-03-16 22:10:03 +00:00
|
|
|
if (!isVisible() && !shouldBeHidden())
|
2014-01-16 17:02:32 +00:00
|
|
|
show();
|
|
|
|
int depth = dataModel->data(dataModel->index(result.first().row(), DivePlotDataModel::DEPTH)).toInt();
|
|
|
|
qreal x = hAxis->posAtValue(internalEvent->time.seconds);
|
|
|
|
qreal y = vAxis->posAtValue(depth);
|
2014-02-23 16:35:06 +00:00
|
|
|
if (!instant)
|
2014-03-11 20:27:05 +00:00
|
|
|
Animations::moveTo(this, x, y);
|
2014-02-23 16:35:06 +00:00
|
|
|
else
|
2014-02-28 04:09:57 +00:00
|
|
|
setPos(x, y);
|
2014-03-16 22:10:03 +00:00
|
|
|
if (isVisible() && shouldBeHidden())
|
2014-03-16 04:12:34 +00:00
|
|
|
hide();
|
2014-01-16 17:02:32 +00:00
|
|
|
}
|