diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-06-26 17:21:03 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-07-18 06:01:07 -0700 |
commit | a5e7f4253ac98ad18354973fda7049e9daaea8eb (patch) | |
tree | 16b95a18d0a1af296e4645d6b7a204b5b325ff01 /desktop-widgets/divelogexportdialog.cpp | |
parent | efdb3503eadd7e47cb64b1c252e50488d2e9d0fe (diff) | |
download | subsurface-a5e7f4253ac98ad18354973fda7049e9daaea8eb.tar.gz |
Core: dynamically resize weight table
Replace the fixed-size weightsystem table by a dynamically
relocated table. Reuse the table-macros used in other parts
of the code.
The table stores weightsystem entries, not pointers to
weightsystems. Thus, ownership of the description string is
taken when adding a weightsystem. An extra function adds
a cloned weightsystem at the end of the table.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/divelogexportdialog.cpp')
-rw-r--r-- | desktop-widgets/divelogexportdialog.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/desktop-widgets/divelogexportdialog.cpp b/desktop-widgets/divelogexportdialog.cpp index 1059d9bd0..e8047f551 100644 --- a/desktop-widgets/divelogexportdialog.cpp +++ b/desktop-widgets/divelogexportdialog.cpp @@ -447,16 +447,12 @@ void DiveLogExportDialog::export_TeX(const char *filename, const bool selected_o put_format(&buf, "\n%% Weighting information:\n"); qty_weight = 0; total_weight = 0; - for (i = 0; i < MAX_WEIGHTSYSTEMS; i++){ - if (dive->weightsystem[i].weight.grams){ - put_format(&buf, "\\def\\%sweight%ctype{%s}\n", ssrf, 'a' + i, dive->weightsystem[i].description); - put_format(&buf, "\\def\\%sweight%camt{%.3f\\%sweightunit}\n", ssrf, 'a' + i, get_weight_units(dive->weightsystem[i].weight.grams, NULL, &unit), ssrf); - qty_weight += 1; - total_weight += get_weight_units(dive->weightsystem[i].weight.grams, NULL, &unit); - } else { - put_format(&buf, "\\def\\%sweight%ctype{}\n", ssrf, 'a' + i); - put_format(&buf, "\\def\\%sweight%camt{}\n", ssrf, 'a' + i); - } + for (i = 0; i < dive->weightsystems.nr; i++) { + weightsystem_t w = dive->weightsystems.weightsystems[i]; + put_format(&buf, "\\def\\%sweight%ctype{%s}\n", ssrf, 'a' + i, w.description); + put_format(&buf, "\\def\\%sweight%camt{%.3f\\%sweightunit}\n", ssrf, 'a' + i, get_weight_units(w.weight.grams, NULL, &unit), ssrf); + qty_weight += 1; + total_weight += get_weight_units(w.weight.grams, NULL, &unit); } put_format(&buf, "\\def\\%sqtyweights{%d}\n", ssrf, qty_weight); put_format(&buf, "\\def\\%stotalweight{%.2f\\%sweightunit}\n", ssrf, total_weight, ssrf); |