summaryrefslogtreecommitdiffstats
path: root/profile-widget
diff options
context:
space:
mode:
authorGravatar Michael Werle <micha@michaelwerle.com>2020-08-25 05:37:08 +0900
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-08-26 07:11:49 -0700
commitf5ba42e933ae4701f40ba8b8b8058e5dd8c82cc0 (patch)
treeb07b47202ecc15a818751cda9b83937214392555 /profile-widget
parente946ce98feb6144548d0f3a12d8c39b5b2a6d02d (diff)
downloadsubsurface-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>
Diffstat (limited to 'profile-widget')
-rw-r--r--profile-widget/profilewidget2.cpp33
1 files changed, 29 insertions, 4 deletions
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); });