Cylinders: dynamically allocate cylinder arrays

When keeping track of cylinder related data, the code was using
static arrays of MAX_CYLINDERS length. If we want to use dynamically
sized cylinder arrays, these have to be dynamically allocated.
In C++ code, this is trivial: simply replace the C-style arrays
by std::vector<>. Don't use QVector, as no reference counting or
COW semantics are needed here. These are purely local and unshared
arrays.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-06-27 07:52:15 +02:00 committed by Dirk Hohndel
parent 11467fa326
commit ff653f721c
3 changed files with 15 additions and 15 deletions

View file

@ -507,7 +507,7 @@ Qt::ItemFlags CylindersModel::flags(const QModelIndex &index) const
void CylindersModel::remove(const QModelIndex &index)
{
int mapping[MAX_CYLINDERS];
std::vector<int> mapping(MAX_CYLINDERS);
if (index.column() == USE) {
cylinder_t *cyl = cylinderAt(index);
@ -538,9 +538,9 @@ void CylindersModel::remove(const QModelIndex &index)
for (int i = index.row() + 1; i < MAX_CYLINDERS; i++)
mapping[i] = i - 1;
cylinder_renumber(&displayed_dive, mapping);
cylinder_renumber(&displayed_dive, &mapping[0]);
if (in_planner())
DivePlannerPointsModel::instance()->cylinderRenumber(mapping);
DivePlannerPointsModel::instance()->cylinderRenumber(&mapping[0]);
changed = true;
endRemoveRows();
dataChanged(index, index);
@ -548,7 +548,7 @@ void CylindersModel::remove(const QModelIndex &index)
void CylindersModel::moveAtFirst(int cylid)
{
int mapping[MAX_CYLINDERS];
std::vector<int> mapping(MAX_CYLINDERS);
cylinder_t temp_cyl;
beginMoveRows(QModelIndex(), cylid, cylid, QModelIndex(), 0);
@ -561,9 +561,9 @@ void CylindersModel::moveAtFirst(int cylid)
mapping[cylid] = 0;
for (int i = cylid + 1; i < MAX_CYLINDERS; i++)
mapping[i] = i;
cylinder_renumber(&displayed_dive, mapping);
cylinder_renumber(&displayed_dive, &mapping[0]);
if (in_planner())
DivePlannerPointsModel::instance()->cylinderRenumber(mapping);
DivePlannerPointsModel::instance()->cylinderRenumber(&mapping[0]);
changed = true;
endMoveRows();
}