diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp index 97a33c571..92c50a67e 100644 --- a/commands/command_edit.cpp +++ b/commands/command_edit.cpp @@ -1009,7 +1009,7 @@ RemoveWeight::RemoveWeight(int index, bool currentDiveOnly) : void RemoveWeight::undo() { for (size_t i = 0; i < dives.size(); ++i) { - add_to_weightsystem_table(&dives[i]->weightsystems, indices[i], ws); + dives[i]->weightsystems.add(indices[i], ws); emit diveListNotifier.weightAdded(dives[i], indices[i]); dives[i]->invalidate_cache(); // Ensure that dive is written in git_save() } diff --git a/core/equipment.cpp b/core/equipment.cpp index f157815a4..124b0c978 100644 --- a/core/equipment.cpp +++ b/core/equipment.cpp @@ -312,10 +312,10 @@ void remove_weightsystem(struct dive *dive, int idx) dive->weightsystems.erase(dive->weightsystems.begin() + idx); } -void add_to_weightsystem_table(weightsystem_table *table, int idx, weightsystem_t ws) +void weightsystem_table::add(int idx, weightsystem_t ws) { - idx = std::clamp(idx, 0, static_cast(table->size())); - table->insert(table->begin() + idx, std::move(ws)); + idx = std::clamp(idx, 0, static_cast(size())); + insert(begin() + idx, std::move(ws)); } void set_weightsystem(struct dive *dive, int idx, weightsystem_t ws) diff --git a/core/equipment.h b/core/equipment.h index 247e108b4..845fefd01 100644 --- a/core/equipment.h +++ b/core/equipment.h @@ -68,7 +68,9 @@ struct weightsystem_t * *not* pointers * to weightsystems. Therefore pointers to * weightsystems are *not* stable. */ -using weightsystem_table = std::vector; +struct weightsystem_table : public std::vector { + void add(int idx, weightsystem_t ws); +}; extern enum cylinderuse cylinderuse_from_text(const char *text); extern void copy_cylinder_types(const struct dive *s, struct dive *d); @@ -88,7 +90,6 @@ extern void dump_cylinders(struct dive *dive, bool verbose); #endif /* Weightsystem table functions */ -extern void add_to_weightsystem_table(weightsystem_table *, int idx, weightsystem_t ws); /* Cylinder table functions */ extern void add_cylinder(struct cylinder_table *, int idx, cylinder_t cyl); diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 260f01c30..0688ecb89 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -1228,7 +1228,7 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt // defined - for now just ignore that case if (d->weightsystems.size() == 0) { weightsystem_t ws = { { parseWeightToGrams(weight) } , tr("weight").toStdString(), false }; - add_to_weightsystem_table(&d->weightsystems, 0, std::move(ws)); + d->weightsystems.add(0, std::move(ws)); } else if (d->weightsystems.size() == 1) { d->weightsystems[0].weight.grams = parseWeightToGrams(weight); }