core: convert cylinder_t and cylinder_table to C++

This had to be done simultaneously, because the table macros
do not work properly with C++ objects.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-28 21:31:11 +02:00 committed by bstoeger
parent 284582d2e8
commit 28520da655
48 changed files with 593 additions and 710 deletions

View file

@ -298,7 +298,7 @@ void ProfileWidget::cylindersChanged(struct dive *changed, int pos)
// If we're editing the current dive we have to update the
// cylinders of the edited dive.
if (editedDive) {
copy_cylinders(&d->cylinders, &editedDive.get()->cylinders);
editedDive.get()->cylinders = d->cylinders;
// TODO: Holy moly that function sends too many signals. Fix it!
DivePlannerPointsModel::instance()->loadFromDive(editedDive.get(), dc);
}

View file

@ -23,6 +23,7 @@
#include "profile-widget/profilewidget2.h"
#include "commands/command.h"
#include "core/metadata.h"
#include "core/range.h"
#include "core/tag.h"
void RenumberDialog::buttonClicked(QAbstractButton *button)
@ -348,11 +349,10 @@ void DiveComponentSelection::buttonClicked(QAbstractButton *button)
text << "\n";
}
if (what->cylinders) {
int cyl;
text << tr("Cylinders:\n");
for (cyl = 0; cyl < current_dive->cylinders.nr; cyl++) {
if (is_cylinder_used(current_dive, cyl))
text << get_cylinder(current_dive, cyl)->type.description << " " << gasname(get_cylinder(current_dive, cyl)->gasmix) << "\n";
for (auto [idx, cyl]: enumerated_range(current_dive->cylinders)) {
if (is_cylinder_used(current_dive, idx))
text << QString::fromStdString(cyl.type.description) << " " << gasname(cyl.gasmix) << "\n";
}
}
if (what->weights) {

View file

@ -126,14 +126,14 @@ void TabDiveInformation::updateProfile()
std::vector<volume_t> gases = get_gas_used(currentDive);
QString volumes;
std::vector<int> mean(currentDive->cylinders.nr), duration(currentDive->cylinders.nr);
std::vector<int> mean(currentDive->cylinders.size()), duration(currentDive->cylinders.size());
struct divecomputer *currentdc = parent.getCurrentDC();
if (currentdc && currentDive->cylinders.nr >= 0)
if (currentdc && !currentDive->cylinders.empty())
per_cylinder_mean_depth(currentDive, currentdc, mean.data(), duration.data());
volume_t sac;
QString gaslist, SACs, separator;
for (int i = 0; i < currentDive->cylinders.nr; i++) {
for (size_t i = 0; i < currentDive->cylinders.size(); i++) {
if (!is_cylinder_used(currentDive, i))
continue;
gaslist.append(separator); volumes.append(separator); SACs.append(separator);
@ -154,7 +154,7 @@ void TabDiveInformation::updateProfile()
ui->diveTimeText->setText(get_dive_duration_string(currentDive->duration.seconds, tr("h"), tr("min"), tr("sec"),
" ", currentDive->dcs[0].divemode == FREEDIVE));
ui->sacText->setText(currentDive->cylinders.nr > 0 && mean[0] && currentDive->dcs[0].divemode != CCR ? std::move(SACs) : QString());
ui->sacText->setText(!currentDive->cylinders.empty() && 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

@ -303,9 +303,9 @@ static int findEnd(const QList<token> &tokenList, int from, int to, token_t star
static std::vector<const cylinder_t *> cylinderList(const dive *d)
{
std::vector<const cylinder_t *> res;
res.reserve(d->cylinders.nr);
for (int i = 0; i < d->cylinders.nr; ++i)
res.push_back(&d->cylinders.cylinders[i]);
res.reserve(d->cylinders.size());
for (auto &cyl: d->cylinders)
res.push_back(&cyl);
return res;
}
@ -481,7 +481,7 @@ QVariant TemplateLayout::getValue(QString list, QString property, const State &s
return QVariant();
const cylinder_t *cylinder = *state.currentCylinderObject;
if (property == "description") {
return cylinder->type.description;
return QString::fromStdString(cylinder->type.description);
} else if (property == "size") {
return get_volume_string(cylinder->type.size, true);
} else if (property == "workingPressure") {