diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-10-29 16:25:00 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-10-29 16:25:00 -0700 |
commit | 669da22d8cc8cc8373a5c500e6207d2b97813a18 (patch) | |
tree | 6c32e5228dc47df5c904ba7f22cfe522ad5a6b21 | |
parent | 1291d100f6b99e22bf8aee4fa30cc7b49f572722 (diff) | |
download | subsurface-669da22d8cc8cc8373a5c500e6207d2b97813a18.tar.gz |
Allow the user to switch to a gas in a specific tank
When entering a gas switch manually, explicitly show the different tanks
that are available and correctly switch between different tanks with the
same gas.
See #702
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/profile/profilewidget2.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/qt-ui/profile/profilewidget2.cpp b/qt-ui/profile/profilewidget2.cpp index 664232502..22e5c46df 100644 --- a/qt-ui/profile/profilewidget2.cpp +++ b/qt-ui/profile/profilewidget2.cpp @@ -1102,7 +1102,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) int rowCount = model->rowCount(); for (int i = 0; i < rowCount; i++) { QAction *action = new QAction(&m); - action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString()); + action->setText(model->data(model->index(i, 0), Qt::DisplayRole).toString() + QString(tr(" (Tank %1)")).arg(i + 1)); connect(action, SIGNAL(triggered(bool)), this, SLOT(changeGas())); action->setData(event->globalPos()); gasChange->addAction(action); @@ -1228,12 +1228,22 @@ void ProfileWidget2::changeGas() QAction *action = qobject_cast<QAction *>(sender()); QPointF scenePos = mapToScene(mapFromGlobal(action->data().toPoint())); QString gas = action->text(); + gas.remove(QRegExp(" \\(.*\\)")); + // backup the things on the dataModel, since we will clear that out. struct gasmix gasmix; int seconds = timeAxis->valueAt(scenePos); validate_gas(gas.toUtf8().constData(), &gasmix); - add_gas_switch_event(&displayed_dive, current_dc, seconds, get_gasidx(&displayed_dive, &gasmix)); + QRegExp rx("\\(\\D*(\\d+)"); + int tank; + if (rx.indexIn(action->text()) > -1) { + tank = rx.cap(1).toInt() - 1; // we display the tank 1 based + } else { + qDebug() << "failed to parse tank number"; + tank = get_gasidx(&displayed_dive, &gasmix); + } + add_gas_switch_event(&displayed_dive, current_dc, seconds, tank); // this means we potentially have a new tank that is being used and needs to be shown fixup_dive(&displayed_dive); |