core: convert weightsystem_t and weightsystem_table to C++

As for cylinders, this had to be done simultaneously,

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-29 07:03:03 +02:00 committed by bstoeger
parent 28520da655
commit 640ecb345b
28 changed files with 137 additions and 247 deletions

View file

@ -195,21 +195,19 @@ QString formatSumWeight(const dive *d)
return get_weight_string(weight_t { total_weight(d) }, true);
}
static QString getFormattedWeight(const struct dive *dive, int idx)
static QString getFormattedWeight(const weightsystem_t &weight)
{
const weightsystem_t *weight = &dive->weightsystems.weightsystems[idx];
if (!weight->description)
if (weight.description.empty())
return QString();
QString fmt = QString(weight->description);
fmt += ", " + get_weight_string(weight->weight, true);
return fmt;
return QString::fromStdString(weight.description) +
", " + get_weight_string(weight.weight, true);
}
QString formatWeightList(const dive *d)
{
QString weights;
for (int i = 0; i < d->weightsystems.nr; i++) {
QString w = getFormattedWeight(d, i);
for (auto &ws: d->weightsystems) {
QString w = getFormattedWeight(ws);
if (w.isEmpty())
continue;
weights += w + "; ";
@ -220,8 +218,8 @@ QString formatWeightList(const dive *d)
QStringList formatWeights(const dive *d)
{
QStringList weights;
for (int i = 0; i < d->weightsystems.nr; i++) {
QString w = getFormattedWeight(d, i);
for (auto &ws: d->weightsystems) {
QString w = getFormattedWeight(ws);
if (w.isEmpty())
continue;
weights << w;