mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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:
parent
1291d100f6
commit
669da22d8c
1 changed files with 12 additions and 2 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue