aboutsummaryrefslogtreecommitdiffstats
path: root/profile-widget
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-01-30 15:20:36 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-01-30 19:33:21 +0200
commit997e7fe1d2e986c449d15a9cb6b8a2a6ddba3146 (patch)
tree1119ae2b8dda99a396e028076982e235fd8bbd3e /profile-widget
parent03f9e2914654b7c15045955ec2d331457cc89542 (diff)
downloadsubsurface-997e7fe1d2e986c449d15a9cb6b8a2a6ddba3146.tar.gz
Profile: fill gas change context menu from current dive
The gas change context menu was filled from the CylindersModel. This means that even before saving new cylinders, the user could add a gas change event to these cylinders. Instead, fill from the current dive. Fixes #2552. Reported-by: Doug Junkins <junkins@foghead.com> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget')
-rw-r--r--profile-widget/profilewidget2.cpp13
1 files changed, 4 insertions, 9 deletions
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp
index eb47c8586..8b1260f9c 100644
--- a/profile-widget/profilewidget2.cpp
+++ b/profile-widget/profilewidget2.cpp
@@ -1445,15 +1445,12 @@ 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;
- GasSelectionModel *model = GasSelectionModel::instance();
- model->repopulate();
- int rowCount = model->rowCount();
- if (rowCount > 1) {
+ 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 < rowCount; i++) {
+ for (int i = 0; i < current_dive->cylinders.nr; i++) {
QAction *action = new QAction(&m);
- action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString() + QString(tr(" (cyl. %1)")).arg(i + 1));
+ action->setText(QString(current_dive->cylinders.cylinders[i].type.description) + tr(" (cyl. %1)").arg(i + 1));
connect(action, &QAction::triggered, [this, i, seconds] { changeGas(i, seconds); } );
gasChange->addAction(action);
}
@@ -1699,11 +1696,9 @@ void ProfileWidget2::changeGas(int tank, int seconds)
gasChangeEvent = gasChangeEvent->next;
}
}
- // add this both to the displayed dive and the current dive
add_gas_switch_event(current_dive, current_dc, seconds, tank);
- add_gas_switch_event(&displayed_dive, get_dive_dc(&displayed_dive, dc_number), seconds, tank);
// this means we potentially have a new tank that is being used and needs to be shown
- fixup_dive(&displayed_dive);
+ fixup_dive(current_dive);
invalidate_dive_cache(current_dive);
// FIXME - this no longer gets written to the dive list - so we need to enableEdition() here