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>
This commit is contained in:
Dirk Hohndel 2014-10-29 16:25:00 -07:00
parent 1291d100f6
commit 669da22d8c

View file

@ -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);