core: move get_dive_dc() to struct dive

Feels natural in a C++ code base.

This removes a nullptr-check so some care has to be taken.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-06-30 20:38:12 +02:00 committed by bstoeger
parent 731052c776
commit f1f082d86a
15 changed files with 59 additions and 55 deletions

View file

@ -213,9 +213,9 @@ static bool ppGraphsEnabled(const struct divecomputer *dc, bool simplified)
// Update visibility of non-interactive chart features according to preferences
void ProfileScene::updateVisibility(bool diveHasHeartBeat, bool simplified)
{
const struct divecomputer *currentdc = get_dive_dc(d, dc);
if (!currentdc)
if (!d)
return;
const struct divecomputer *currentdc = d->get_dc(dc);
bool ppGraphs = ppGraphsEnabled(currentdc, simplified);
diveCeiling->setVisible(prefs.calcceiling);
@ -291,9 +291,9 @@ struct VerticalAxisLayout {
void ProfileScene::updateAxes(bool diveHasHeartBeat, bool simplified)
{
const struct divecomputer *currentdc = get_dive_dc(d, dc);
if (!currentdc)
if (!d)
return;
const struct divecomputer *currentdc = d->get_dc(dc);
// Calculate left and right border needed for the axes and other chart items.
double leftBorder = profileYAxis->width();
@ -428,7 +428,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM
decoModelParameters->set(QString("GF %1/%2").arg(diveplan.gflow).arg(diveplan.gfhigh), getColor(PRESSURE_TEXT));
}
const struct divecomputer *currentdc = get_dive_dc(d, dc);
const struct divecomputer *currentdc = d->get_dc(dc);
if (!currentdc || currentdc->samples.empty()) {
clear();
return;

View file

@ -532,7 +532,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
// figure out if we are ontop of the dive computer name in the profile
QGraphicsItem *sceneItem = itemAt(mapFromGlobal(event->globalPos()));
if (isDiveTextItem(sceneItem, profileScene->diveComputerText)) {
const struct divecomputer *currentdc = get_dive_dc(d, dc);
const struct divecomputer *currentdc = d->get_dc(dc);
if (!currentdc->deviceid && dc == 0 && d->number_of_computers() == 1)
// nothing to do, can't rename, delete or reorder
return;
@ -576,7 +576,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
m.addAction(tr("Add bookmark"), [this, seconds]() { addBookmark(seconds); });
m.addAction(tr("Split dive into two"), [this, seconds]() { splitDive(seconds); });
divemode_loop loop(*get_dive_dc(d, dc));
divemode_loop loop(*d->get_dc(dc));
divemode_t divemode = loop.next(seconds);
QMenu *changeMode = m.addMenu(tr("Change divemode"));
if (divemode != OC)
@ -644,7 +644,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
}
m2->addAction(tr("All event types"), this, &ProfileWidget2::unhideEventTypes);
}
const struct divecomputer *currentdc = get_dive_dc(d, dc);
const struct divecomputer *currentdc = d->get_dc(dc);
if (currentdc && std::any_of(currentdc->events.begin(), currentdc->events.end(),
[] (auto &ev) { return ev.hidden; }))
m.addAction(tr("Unhide individually hidden events of this dive"), this, &ProfileWidget2::unhideEvents);
@ -671,10 +671,10 @@ void ProfileWidget2::makeFirstDC()
void ProfileWidget2::renameCurrentDC()
{
bool ok;
struct divecomputer *currentdc = get_dive_dc(mutable_dive(), dc);
if (!currentdc)
if (!d)
return;
bool ok;
struct divecomputer *currentdc = mutable_dive()->get_dc(dc);
QString newName = QInputDialog::getText(this, tr("Edit nickname"),
tr("Set new nickname for %1 (serial %2):").arg(QString::fromStdString(currentdc->model)).
arg(QString::fromStdString(currentdc->serial)),
@ -685,7 +685,9 @@ void ProfileWidget2::renameCurrentDC()
void ProfileWidget2::hideEvent(DiveEventItem *item)
{
struct divecomputer *currentdc = get_dive_dc(mutable_dive(), dc);
if (!d)
return;
struct divecomputer *currentdc = mutable_dive()->get_dc(dc);
int idx = item->idx;
if (!currentdc || idx < 0 || static_cast<size_t>(idx) >= currentdc->events.size())
return;
@ -704,7 +706,9 @@ void ProfileWidget2::hideEventType(DiveEventItem *item)
void ProfileWidget2::unhideEvents()
{
struct divecomputer *currentdc = get_dive_dc(mutable_dive(), dc);
if (!d)
return;
struct divecomputer *currentdc = mutable_dive()->get_dc(dc);
if (!currentdc)
return;
for (auto &ev: currentdc->events)