diff options
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/modeldelegates.cpp | 8 | ||||
-rw-r--r-- | qt-ui/models.cpp | 22 | ||||
-rw-r--r-- | qt-ui/models.h | 1 |
3 files changed, 27 insertions, 4 deletions
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index 2dc52e655..0cffe98c4 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -77,16 +77,16 @@ void TankInfoDelegate::setEditorData(QWidget* editor, const QModelIndex& index) void TankInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { QComboBox *c = static_cast<QComboBox*>(editor); - + CylindersModel *mymodel = qobject_cast<CylindersModel *>(model); TankInfoModel *tanks = TankInfoModel::instance(); QModelIndex tankIndex = tanks->match(tanks->index(0,0), Qt::DisplayRole, c->currentText()).first(); int tankSize = tanks->data(tanks->index(tankIndex.row(), TankInfoModel::ML)).toInt(); int tankPressure = tanks->data(tanks->index(tankIndex.row(), TankInfoModel::BAR)).toInt(); - model->setData(index, c->currentText(), Qt::EditRole); - model->setData(model->index(index.row(), CylindersModel:: SIZE), tankSize ); - model->setData(model->index(index.row(), CylindersModel::WORKINGPRESS), tankPressure); + mymodel->setData(index, c->currentText(), Qt::EditRole); + mymodel->passInData(model->index(index.row(), CylindersModel::WORKINGPRESS), tankPressure); + mymodel->passInData(model->index(index.row(), CylindersModel::SIZE), tankSize); } TankInfoDelegate::TankInfoDelegate(QObject* parent): QStyledItemDelegate(parent) diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 029a788bf..0ef054533 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -111,6 +111,28 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const return ret; } +// this is our magic 'pass data in' function that allows the delegate to get +// the data here without silly unit conversions; +// so we only implement the two columns we care about +void CylindersModel::passInData(const QModelIndex& index, const QVariant& value) +{ + cylinder_t *cyl = ¤t->cylinder[index.row()]; + switch(index.column()) { + case SIZE: + if (cyl->type.size.mliter != value.toInt()) { + cyl->type.size.mliter = value.toInt(); + mark_divelist_changed(TRUE); + } + break; + case WORKINGPRESS: + if (cyl->type.workingpressure.mbar != value.toInt()) { + cyl->type.workingpressure.mbar = value.toInt(); + mark_divelist_changed(TRUE); + } + break; + } +} + #define CHANGED(_t,_u1,_u2) value._t() != data(index, role).toString().replace(_u1,"").replace(_u2,"")._t() bool CylindersModel::setData(const QModelIndex& index, const QVariant& value, int role) diff --git a/qt-ui/models.h b/qt-ui/models.h index 038f400a7..556651ffe 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -51,6 +51,7 @@ public: /*reimp*/ Qt::ItemFlags flags(const QModelIndex& index) const; /*reimp*/ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); + void passInData(const QModelIndex& index, const QVariant& value); void add(); void clear(); void update(); |