crash fix: Don't cast to CylindersModel or CylindersModelFiltered

The tank-info-delegate cast its model to CylindersModelFiltered,
since this is what the equipment-tab uses since implementing the
filtering of unused cylinders. However, the planner users the same
delegate and still uses the unfiltered CylindersModel. This means
that the (dynamic) cast returns a null pointer and crashes.

One possibility would be to derive CylindersModelFiltered and
CylindersModel from the same class that defines virtual functions
and cast to that class.

This is a different attempt: don't cast (i.e. stay with a
QAbstractItemModel and play it via Qt's model-view system. Firstly,
replace the passInData function by a role to setData(). Secondly,
read the working-pressure and size via new columns using data().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-02-27 19:46:48 +01:00 committed by Dirk Hohndel
parent 9214bdb3c5
commit cb80ff746b
3 changed files with 44 additions and 40 deletions

View file

@ -25,16 +25,20 @@ public:
MOD,
MND,
USE,
WORKINGPRESS_INT,
SIZE_INT,
COLUMNS
};
enum Roles {
PASS_IN_ROLE = Qt::UserRole + 1 // For setting data: don't do any conversions
};
explicit CylindersModel(QObject *parent = 0);
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
void passInData(const QModelIndex &index, const QVariant &value);
void add();
void clear();
void updateDive();
@ -67,7 +71,6 @@ public:
void add();
void updateDive();
cylinder_t *cylinderAt(const QModelIndex &index);
void passInData(const QModelIndex &index, const QVariant &value);
public
slots:
void remove(QModelIndex index);