diff options
-rw-r--r-- | qt-ui/modeldelegates.cpp | 26 | ||||
-rw-r--r-- | qt-ui/modeldelegates.h | 3 | ||||
-rw-r--r-- | qt-ui/models.cpp | 5 | ||||
-rw-r--r-- | qt-ui/models.h | 2 |
4 files changed, 33 insertions, 3 deletions
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index 9ab706c59..998c246b8 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -58,6 +58,8 @@ QSize StarWidgetsDelegate::sizeHint(const QStyleOptionViewItem& option, const QM ComboBoxDelegate::ComboBoxDelegate(QAbstractItemModel *model, QObject* parent): QStyledItemDelegate(parent), model(model) { + connect(this, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), + this, SLOT(revertModelData(QWidget*, QAbstractItemDelegate::EndEditHint))); } void ComboBoxDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const @@ -172,8 +174,6 @@ void TankInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, TankInfoDelegate::TankInfoDelegate(QObject* parent): ComboBoxDelegate(TankInfoModel::instance(), parent) { - connect(this, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), - this, SLOT(revertModelData(QWidget*, QAbstractItemDelegate::EndEditHint))); } void TankInfoDelegate::revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint) @@ -199,6 +199,20 @@ QWidget* TankInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewI return delegate; } +struct RevertWeigthData { + QString type; + int weigth; +} currWeigth; + +void WSInfoDelegate::revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint) +{ + if (hint == QAbstractItemDelegate::NoHint || hint == QAbstractItemDelegate::RevertModelCache){ + WeightModel *mymodel = qobject_cast<WeightModel *>(currCombo.model); + mymodel->setData(IDX(WeightModel::TYPE), currWeigth.type, Qt::EditRole); + mymodel->passInData(IDX(WeightModel::WEIGHT), currWeigth.weigth); + } +} + void WSInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& thisindex) const { WeightModel *mymodel = qobject_cast<WeightModel *>(currCombo.model); @@ -231,5 +245,11 @@ WSInfoDelegate::WSInfoDelegate(QObject* parent): ComboBoxDelegate(WSInfoModel::i QWidget* WSInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const { - return ComboBoxDelegate::createEditor(parent, option, index); + /* First, call the combobox-create editor, it will setup our globals. */ + QWidget *editor = ComboBoxDelegate::createEditor(parent, option, index); + WeightModel *mymodel = qobject_cast<WeightModel *>(currCombo.model); + weightsystem_t *ws = mymodel->weightSystemAt(index); + currWeigth.type = ws->description; + currWeigth.weigth = ws->weight.grams; + return editor; } diff --git a/qt-ui/modeldelegates.h b/qt-ui/modeldelegates.h index 4ddf53df3..9603d5dce 100644 --- a/qt-ui/modeldelegates.h +++ b/qt-ui/modeldelegates.h @@ -24,6 +24,7 @@ public: virtual bool eventFilter(QObject* object, QEvent* event); public slots: void testActivation(const QString& s); + virtual void revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint) = 0; protected: QAbstractItemModel *model; }; @@ -44,6 +45,8 @@ public: explicit WSInfoDelegate(QObject* parent = 0); virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const; virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const; +public slots: + void revertModelData(QWidget* widget, QAbstractItemDelegate::EndEditHint hint); }; #endif diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index fe15a98c3..347301424 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -348,6 +348,11 @@ WeightModel::WeightModel(QObject* parent): QAbstractTableModel(parent), current( { } +weightsystem_t* WeightModel::weightSystemAt(const QModelIndex& index) +{ + return ¤t->weightsystem[index.row()]; +} + void WeightModel::remove(const QModelIndex& index) { if (index.column() != REMOVE) { diff --git a/qt-ui/models.h b/qt-ui/models.h index b7a72b1d2..e8a7daaf3 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -114,6 +114,8 @@ public: void clear(); void update(); void setDive(struct dive *d); + weightsystem_t *weightSystemAt(const QModelIndex& index); + public slots: void remove(const QModelIndex& index); |