core: turn divecomputer list into std::vector<>

Since struct divecomputer is now fully C++ (i.e. cleans up
after itself), we can simply turn the list of divecomputers
into an std::vector<>. This makes the code quite a bit simpler,
because the first divecomputer was actually a subobject.

Yes, this makes the common case of a single divecomputer a
little bit less efficient, but it really shouldn't matter.
If it does, we can still write a special std::vector<>-
like container that keeps the first element inline.

This change makes pointers-to-divecomputers not stable.
So always access the divecomputer via its index. As
far as I can tell, most of the code already does this.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-27 17:09:48 +02:00 committed by bstoeger
parent e237f29fb2
commit 284582d2e8
54 changed files with 738 additions and 893 deletions

View file

@ -563,7 +563,7 @@ int PlannerWidgets::getDcNr()
divemode_t PlannerWidgets::getRebreatherMode() const
{
return get_dive_dc_const(planned_dive.get(), dcNr)->divemode;
return get_dive_dc(planned_dive.get(), dcNr)->divemode;
}
void PlannerWidgets::preparePlanDive(const dive *currentDive, int currentDcNr)
@ -575,8 +575,8 @@ void PlannerWidgets::preparePlanDive(const dive *currentDive, int currentDcNr)
// plan the dive in the same mode as the currently selected one
if (currentDive) {
plannerSettingsWidget.setDiveMode(get_dive_dc_const(currentDive, currentDcNr)->divemode);
plannerSettingsWidget.setBailoutVisibility(get_dive_dc_const(currentDive, currentDcNr)->divemode);
plannerSettingsWidget.setDiveMode(get_dive_dc(currentDive, currentDcNr)->divemode);
plannerSettingsWidget.setBailoutVisibility(get_dive_dc(currentDive, currentDcNr)->divemode);
if (currentDive->salinity)
plannerWidget.setSalinity(currentDive->salinity);
else // No salinity means salt water

View file

@ -705,11 +705,11 @@ void MainWindow::on_actionAddDive_triggered()
struct dive d;
d.id = dive_getUniqID();
d.when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset() + 3600;
d.dc.duration.seconds = 40 * 60;
d.dc.maxdepth.mm = M_OR_FT(15, 45);
d.dc.meandepth.mm = M_OR_FT(13, 39); // this creates a resonable looking safety stop
make_manually_added_dive_dc(&d.dc);
fake_dc(&d.dc);
d.dcs[0].duration.seconds = 40 * 60;
d.dcs[0].maxdepth.mm = M_OR_FT(15, 45);
d.dcs[0].meandepth.mm = M_OR_FT(13, 39); // this creates a resonable looking safety stop
make_manually_added_dive_dc(&d.dcs[0]);
fake_dc(&d.dcs[0]);
add_default_cylinder(&d);
fixup_dive(&d);

View file

@ -167,7 +167,7 @@ void ProfileWidget::setDive(const struct dive *d, int dcNr)
{
stack->setCurrentIndex(1); // show profile
bool freeDiveMode = get_dive_dc_const(d, dcNr)->divemode == FREEDIVE;
bool freeDiveMode = get_dive_dc(d, dcNr)->divemode == FREEDIVE;
ui.profCalcCeiling->setDisabled(freeDiveMode);
ui.profCalcCeiling->setDisabled(freeDiveMode);
ui.profCalcAllTissues ->setDisabled(freeDiveMode);

View file

@ -152,9 +152,9 @@ void TabDiveInformation::updateProfile()
ui->oxygenHeliumText->setText(gaslist);
ui->diveTimeText->setText(get_dive_duration_string(currentDive->duration.seconds, tr("h"), tr("min"), tr("sec"),
" ", currentDive->dc.divemode == FREEDIVE));
" ", currentDive->dcs[0].divemode == FREEDIVE));
ui->sacText->setText(currentDive->cylinders.nr > 0 && mean[0] && currentDive->dc.divemode != CCR ? std::move(SACs) : QString());
ui->sacText->setText(currentDive->cylinders.nr > 0 && mean[0] && currentDive->dcs[0].divemode != CCR ? std::move(SACs) : QString());
if (currentDive->surface_pressure.mbar == 0) {
ui->atmPressVal->clear(); // If no atm pressure for dive then clear text box

View file

@ -254,7 +254,7 @@ void TabDiveNotes::updateData(const std::vector<dive *> &, dive *currentDive, in
ui.LocationLabel->setText(tr("Location"));
ui.NotesLabel->setText(tr("Notes"));
ui.tagWidget->setText(QString::fromStdString(taglist_get_tagstring(currentDive->tag_list)));
bool isManual = is_dc_manually_added_dive(&currentDive->dc);
bool isManual = is_dc_manually_added_dive(&currentDive->dcs[0]);
ui.depth->setVisible(isManual);
ui.depthLabel->setVisible(isManual);
ui.duration->setVisible(isManual);

View file

@ -108,7 +108,7 @@ void TabDiveStatistics::updateData(const std::vector<dive *> &, dive *currentDiv
}
bool is_freedive = currentDive && currentDive->dc.divemode == FREEDIVE;
bool is_freedive = currentDive && currentDive->dcs[0].divemode == FREEDIVE;
ui->divesAllText->setText(QString::number(stats_selection.selection_size));
ui->totalTimeAllText->setText(get_dive_duration_string(stats_selection.total_time.seconds, tr("h"), tr("min"), tr("sec"), " ", is_freedive));

View file

@ -534,11 +534,11 @@ QVariant TemplateLayout::getValue(QString list, QString property, const State &s
} else if (property == "duration") {
return formatDiveDuration(d);
} else if (property == "noDive") {
return d->duration.seconds == 0 && d->dc.duration.seconds == 0;
return d->duration.seconds == 0 && d->dcs[0].duration.seconds == 0;
} else if (property == "depth") {
return get_depth_string(d->dc.maxdepth.mm, true, true);
return get_depth_string(d->dcs[0].maxdepth.mm, true, true);
} else if (property == "meandepth") {
return get_depth_string(d->dc.meandepth.mm, true, true);
return get_depth_string(d->dcs[0].meandepth.mm, true, true);
} else if (property == "divemaster") {
return d->diveguide;
} else if (property == "diveguide") {