planner: fix removal of points from DivePlannerPointsModel

The beginRemoveRows() function was fed erroneous values. It
is a mystery why this didn't crash. In any case, deletion
of multiple points did not work properly. Instead of trying
to be fancy, remove each point one-by-one.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-01-24 08:50:10 +01:00 committed by Dirk Hohndel
parent 35c5ec09b7
commit 1b14a211f0

View file

@ -28,20 +28,18 @@ CylindersModel *DivePlannerPointsModel::cylindersModel()
return &cylinders;
}
/* TODO: Port this to CleanerTableModel to remove a bit of boilerplate. */
void DivePlannerPointsModel::removeSelectedPoints(const QVector<int> &rows)
{
if (!rows.count())
return;
int firstRow = rowCount() - rows.count();
QVector<int> v2 = rows;
std::sort(v2.begin(), v2.end());
beginRemoveRows(QModelIndex(), firstRow, rowCount() - 1);
for (int i = v2.count() - 1; i >= 0; i--) {
divepoints.remove(v2[i]);
beginRemoveRows(QModelIndex(), v2[i], v2[i]);
divepoints.erase(divepoints.begin() + v2[i]);
endRemoveRows();
}
endRemoveRows();
cylinders.updateTrashIcon();
}