diff options
author | Michael Werle <micha@michaelwerle.com> | 2020-08-25 05:37:08 +0900 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-08-26 07:11:49 -0700 |
commit | f5ba42e933ae4701f40ba8b8b8058e5dd8c82cc0 (patch) | |
tree | b07b47202ecc15a818751cda9b83937214392555 | |
parent | e946ce98feb6144548d0f3a12d8c39b5b2a6d02d (diff) | |
download | subsurface-f5ba42e933ae4701f40ba8b8b8058e5dd8c82cc0.tar.gz |
Add an "Edit Gas Change" right-click option.
This new option allows a user to select a new destination tank for an
existing "Gas Change" event. This is useful when Subsurface's heuristics
get tanks wrong after an import from a divecomputer. The use-case arose
from sidemount divers with air-integrated transmitters as well as carrying
a deco tank.
Signed-off-by: Michael Werle <micha@michaelwerle.com>
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | profile-widget/profilewidget2.cpp | 33 |
2 files changed, 30 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 18240f402..5d64136a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +desktop: add an "Edit Gas Change" right-click option [#2910] core: add support for Shearwater Peregrine (requires firmware V79 or newer) core: fix renumbering of imported dives [#2731] mobile: fix editing tank information diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 10c52f95d..7fffb04e2 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -1399,6 +1399,18 @@ struct int ProfileWidget2::getEntryFromPos(QPointF pos) #endif #ifndef SUBSURFACE_MOBILE +/// Prints cylinder information for display. +/// eg : "Cyl 1 (AL80 EAN32)" +static QString printCylinderDescription(int i, const cylinder_t *cylinder) +{ + QString label = gettextFromC::tr("Cyl") + QString(" %1").arg(i+1); + if( cylinder != NULL ) { + QString mix = get_gas_string(cylinder->gasmix); + label += QString(" (%2 %3)").arg(cylinder->type.description).arg(mix); + } + return label; +} + void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) { if (currentState == ADD || currentState == PLAN) { @@ -1440,12 +1452,25 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) QPointF scenePos = mapToScene(mapFromGlobal(event->globalPos())); qreal sec_val = timeAxis->valueAt(scenePos); int seconds = (sec_val < 0.0) ? 0 : (int)sec_val; - if (current_dive && current_dive->cylinders.nr > 1) { + DiveEventItem *item = dynamic_cast<DiveEventItem *>(sceneItem); + + // Add or edit Gas Change + if (current_dive && item && event_is_gaschange(item->getEvent())) { + int eventTime = item->getEvent()->time.seconds; + QMenu *gasChange = m.addMenu(tr("Edit Gas Change")); + for (int i = 0; i < current_dive->cylinders.nr; i++) { + const cylinder_t *cylinder = get_cylinder(current_dive, i); + QString label = printCylinderDescription(i, cylinder); + gasChange->addAction(label, [this, i, eventTime] { changeGas(i, eventTime); }); + } + } else if (current_dive && current_dive->cylinders.nr > 1) { // if we have more than one gas, offer to switch to another one QMenu *gasChange = m.addMenu(tr("Add gas change")); - for (int i = 0; i < current_dive->cylinders.nr; i++) - gasChange->addAction(QString(current_dive->cylinders.cylinders[i].type.description) + tr(" (cyl. %1)").arg(i + 1), - [this, i, seconds] { changeGas(i, seconds); }); + for (int i = 0; i < current_dive->cylinders.nr; i++) { + const cylinder_t *cylinder = get_cylinder(current_dive, i); + QString label = printCylinderDescription(i, cylinder); + gasChange->addAction(label, [this, i, seconds] { changeGas(i, seconds); }); + } } m.addAction(tr("Add setpoint change"), [this, seconds]() { ProfileWidget2::addSetpointChange(seconds); }); m.addAction(tr("Add bookmark"), [this, seconds]() { addBookmark(seconds); }); |