Desktop: Fix Gas Editing for Manually Added Dives.

- show the correct gasmix in the profile;
- make gases available for gas switches in the profile after they have
  been added;
- persist gas changes;
- add air as a default gas when adding a dive.

This still has problems when undoing a gas switch - instead of
completely removing the gas switch it is just moved to the next point in the
profile.

Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
Michael Keller 2024-05-25 19:03:39 +12:00
parent 9243921cbb
commit f65afaf5d2
13 changed files with 121 additions and 54 deletions

View file

@ -62,10 +62,10 @@ void DiveHandler::selfRemove()
void DiveHandler::changeGas()
{
ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
QAction *action = qobject_cast<QAction *>(sender());
DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
QModelIndex index = plannerModel->index(parentIndex(), DivePlannerPointsModel::GAS);
plannerModel->gasChange(index.sibling(index.row() + 1, index.column()), action->data().toInt());
view->changeGas(parentIndex(), action->data().toInt());
}
void DiveHandler::mouseMoveEvent(QGraphicsSceneMouseEvent *event)

View file

@ -565,7 +565,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
for (int i = 0; i < d->cylinders.nr; i++) {
const cylinder_t *cylinder = get_cylinder(d, i);
QString label = printCylinderDescription(i, cylinder);
gasChange->addAction(label, [this, i, eventTime] { changeGas(i, eventTime); });
gasChange->addAction(label, [this, i, eventTime] { addGasSwitch(i, eventTime); });
}
} else if (d && d->cylinders.nr > 1) {
// if we have more than one gas, offer to switch to another one
@ -573,7 +573,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
for (int i = 0; i < d->cylinders.nr; i++) {
const cylinder_t *cylinder = get_cylinder(d, i);
QString label = printCylinderDescription(i, cylinder);
gasChange->addAction(label, [this, i, seconds] { changeGas(i, seconds); });
gasChange->addAction(label, [this, i, seconds] { addGasSwitch(i, seconds); });
}
}
m.addAction(tr("Add setpoint change"), [this, seconds]() { ProfileWidget2::addSetpointChange(seconds); });
@ -759,16 +759,25 @@ void ProfileWidget2::splitDive(int seconds)
Command::splitDives(mutable_dive(), duration_t{ seconds });
}
void ProfileWidget2::changeGas(int tank, int seconds)
void ProfileWidget2::addGasSwitch(int tank, int seconds)
{
if (!d || tank < 0 || tank >= d->cylinders.nr)
return;
Command::addGasSwitch(mutable_dive(), dc, seconds, tank);
}
#endif
#ifndef SUBSURFACE_MOBILE
void ProfileWidget2::changeGas(int index, int newCylinderId)
{
if ((currentState == PLAN || currentState == EDIT) && plannerModel) {
QModelIndex modelIndex = plannerModel->index(index, DivePlannerPointsModel::GAS);
plannerModel->gasChange(modelIndex.sibling(modelIndex.row() + 1, modelIndex.column()), newCylinderId);
if (currentState == EDIT)
emit stopEdited();
}
}
void ProfileWidget2::editName(DiveEventItem *item)
{
struct event *event = item->getEventMutable();

View file

@ -68,6 +68,7 @@ signals:
void stopAdded(); // only emitted in edit mode
void stopRemoved(int count); // only emitted in edit mode
void stopMoved(int count); // only emitted in edit mode
void stopEdited(); // only emitted in edit mode
public
slots: // Necessary to call from QAction's signals.
@ -111,7 +112,8 @@ private:
void replot();
void setZoom(int level);
void changeGas(int tank, int seconds);
void addGasSwitch(int tank, int seconds);
void changeGas(int index, int newCylinderId);
void setupSceneAndFlags();
void addItemsToScene();
void setupItemOnScene();