core: use C++ structures for weightsystem info

Use std::vector<> instead of fixed size array.
Doesn't do any logic change, even though the back-translation
logic is ominous.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-04-17 17:31:50 +08:00 committed by bstoeger
parent c5f96d877d
commit 1af00703b3
8 changed files with 58 additions and 72 deletions

View file

@ -1079,12 +1079,12 @@ EditWeight::EditWeight(int index, weightsystem_t wsIn, bool currentDiveOnly) :
// Try to untranslate the weightsystem name
new_ws = clone_weightsystem(wsIn);
QString vString(new_ws.description);
for (int i = 0; i < MAX_WS_INFO && ws_info[i].name; ++i) {
if (gettextFromC::tr(ws_info[i].name) == vString) {
free_weightsystem(new_ws);
new_ws.description = copy_string(ws_info[i].name);
break;
}
auto it = std::find_if(ws_info_table.begin(), ws_info_table.end(),
[&vString](const ws_info &info)
{ return gettextFromC::tr(info.name.c_str()) == vString; });
if (it != ws_info_table.end()) {
free_weightsystem(new_ws);
new_ws.description = strdup(it->name.c_str());
}
// If that doesn't change anything, do nothing
@ -1102,7 +1102,7 @@ EditWeight::~EditWeight()
void EditWeight::redo()
{
for (size_t i = 0; i < dives.size(); ++i) {
add_weightsystem_description(&new_ws); // This updates the weightsystem info table
add_weightsystem_description(new_ws); // This updates the weightsystem info table
set_weightsystem(dives[i], indices[i], new_ws);
emit diveListNotifier.weightEdited(dives[i], indices[i]);
invalidate_dive_cache(dives[i]); // Ensure that dive is written in git_save()