Update diveplannerpoints cylinderidx when deleting a cylinder

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
This commit is contained in:
Stefan Fuchs 2017-10-11 21:27:06 +02:00 committed by Robert C. Helling
parent df6933326d
commit 73d2ab8099
3 changed files with 10 additions and 5 deletions

View file

@ -576,11 +576,8 @@ void CylindersModel::remove(const QModelIndex &index)
} }
changed = true; changed = true;
endRemoveRows(); endRemoveRows();
struct divecomputer *dc = &displayed_dive.dc; cylinder_renumber(&displayed_dive, mapping);
while (dc) { DivePlannerPointsModel::instance()->cylinderRenumber(mapping);
dc_cylinder_renumber(&displayed_dive, dc, mapping);
dc = dc->next;
}
dataChanged(index, index); dataChanged(index, index);
} }

View file

@ -353,6 +353,13 @@ void DivePlannerPointsModel::gaschange(const QModelIndex &index, int newcylinder
emitDataChanged(); emitDataChanged();
} }
void DivePlannerPointsModel::cylinderRenumber(int mapping[])
{
for (int i = 0; i < rowCount(); i++)
divepoints[i].cylinderid = mapping[divepoints[i].cylinderid];
emitDataChanged();
}
QVariant DivePlannerPointsModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant DivePlannerPointsModel::headerData(int section, Qt::Orientation orientation, int role) const
{ {
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {

View file

@ -32,6 +32,7 @@ public:
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
virtual Qt::ItemFlags flags(const QModelIndex &index) const; virtual Qt::ItemFlags flags(const QModelIndex &index) const;
void gaschange(const QModelIndex &index, int newcylinderid); void gaschange(const QModelIndex &index, int newcylinderid);
void cylinderRenumber(int mapping[]);
void removeSelectedPoints(const QVector<int> &rows); void removeSelectedPoints(const QVector<int> &rows);
void setPlanMode(Mode mode); void setPlanMode(Mode mode);
bool isPlanner(); bool isPlanner();