Planner: Improve Gas Handling in CCR Mode.

This has become a bit of a catch-all overhaul of a large portion of the
planner - I started out wanting to improve the CCR mode, but then as I
started pulling all the other threads that needed addressing started to
come with it.

Improve how the gas selection is handled when planning dives in CCR
mode, by making the type (OC / CCR) of segments dependent on the gas use
type that was set for the selected gas.
Add a preference to allow the user to chose to use OC gases as diluent,
in a similar fashion to the original implementation.
Hide gases that cannot be used in the currently selected dive mode in
all drop downs.
Include usage type in gas names if this is needed.
Hide columns and disable elements in the 'Dive planner points' table if
they can they can not be edited in the curently selected dive mode.
Visually identify gases and usage types that are not appropriate for the
currently selected dive mode.
Move the 'Dive mode' selection to the top of the planner view, to
accommodate the fact that this is a property of the dive and not a
planner setting.
Show a warning instead of the dive plan if the plan contains gases that
are not usable in the selected dive mode.
Fix the data entry for the setpoint in the 'Dive planner points' table.
Fix problems with enabling / disabling planner settings when switching
between dive modes.
Refactor some names to make them more appropriate for their current
usage.

One point that is still open is to hide gas usage graphs in the planner
profile if the gas isn't used for OC, as there is no way to meaningfully
interpolate such usage.

Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
Michael Keller 2024-05-15 17:23:39 +12:00
parent 7106c4d5f0
commit 2d8e343221
63 changed files with 678 additions and 383 deletions

View file

@ -500,16 +500,6 @@ struct int ProfileWidget2::getEntryFromPos(QPointF pos)
#endif
#ifndef SUBSURFACE_MOBILE
/// Prints cylinder information for display.
/// eg : "Cyl 1 (AL80 EAN32)"
static QString printCylinderDescription(int i, const cylinder_t &cylinder)
{
QString label = gettextFromC::tr("Cyl") + QString(" %1").arg(i+1);
QString mix = get_gas_string(cylinder.gasmix);
label += QString(" (%2 %3)").arg(QString::fromStdString(cylinder.type.description)).arg(mix);
return label;
}
static bool isDiveTextItem(const QGraphicsItem *item, const DiveTextItem *textItem)
{
while (item) {
@ -520,6 +510,16 @@ static bool isDiveTextItem(const QGraphicsItem *item, const DiveTextItem *textIt
return false;
}
void ProfileWidget2::addGasChangeMenu(QMenu &m, QString menuTitle, const struct dive &d, int dcNr, int changeTime)
{
QMenu *gasChange = m.addMenu(menuTitle);
std::vector<std::pair<int, QString>> gases = get_dive_gas_list(&d, dcNr, true);
for (unsigned i = 0; i < gases.size(); i++) {
int cylinderIndex = gases[i].first;
gasChange->addAction(gases[i].second, [this, cylinderIndex, changeTime] { addGasSwitch(cylinderIndex, changeTime); });
}
}
void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
{
if (currentState == EDIT || currentState == PLAN) {
@ -558,19 +558,10 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
// Add or edit Gas Change
if (d && item && item->ev.is_gaschange()) {
int eventTime = item->ev.time.seconds;
QMenu *gasChange = m.addMenu(tr("Edit Gas Change"));
for (auto [i, cyl]: enumerated_range(d->cylinders)) {
QString label = printCylinderDescription(i, cyl);
gasChange->addAction(label, [this, idx = i, eventTime] { addGasSwitch(idx, eventTime); });
}
addGasChangeMenu(m, tr("Edit Gas Change"), *d, dc, item->ev.time.seconds);
} else if (d && d->cylinders.size() > 1) {
// if we have more than one gas, offer to switch to another one
QMenu *gasChange = m.addMenu(tr("Add gas change"));
for (auto [i, cyl]: enumerated_range(d->cylinders)) {
QString label = printCylinderDescription(i, cyl);
gasChange->addAction(label, [this, idx = i, seconds] { addGasSwitch(idx, seconds); });
}
addGasChangeMenu(m, tr("Add gas change"), *d, dc, seconds);
}
m.addAction(tr("Add setpoint change"), [this, seconds]() { ProfileWidget2::addSetpointChange(seconds); });
m.addAction(tr("Add bookmark"), [this, seconds]() { addBookmark(seconds); });
@ -837,7 +828,7 @@ int ProfileWidget2::handleIndex(const DiveHandler *h) const
DiveHandler *ProfileWidget2::createHandle()
{
DiveHandler *item = new DiveHandler(d);
DiveHandler *item = new DiveHandler(d, dc);
scene()->addItem(item);
connect(item, &DiveHandler::moved, this, &ProfileWidget2::divePlannerHandlerMoved);
connect(item, &DiveHandler::clicked, this, &ProfileWidget2::divePlannerHandlerClicked);