diff options
Diffstat (limited to 'qt-ui/modeldelegates.cpp')
-rw-r--r-- | qt-ui/modeldelegates.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index 0cffe98c4..b80e30fcd 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -92,3 +92,43 @@ void TankInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, TankInfoDelegate::TankInfoDelegate(QObject* parent): QStyledItemDelegate(parent) { } + +QWidget* WSInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + QComboBox *comboDelegate = new QComboBox(parent); + WSInfoModel *model = WSInfoModel::instance(); + comboDelegate->setModel(model); + comboDelegate->setEditable(true); + comboDelegate->setAutoCompletion(true); + comboDelegate->setAutoCompletionCaseSensitivity(Qt::CaseInsensitive); + comboDelegate->completer()->setCompletionMode(QCompleter::PopupCompletion); + return comboDelegate; +} + +void WSInfoDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const +{ + QComboBox *c = qobject_cast<QComboBox*>(editor); + QString data = index.model()->data(index, Qt::DisplayRole).toString(); + int i = c->findText(data); + if (i != -1) + c->setCurrentIndex(i); + else + c->setEditText(data); +} + +void WSInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const +{ + QComboBox *c = static_cast<QComboBox*>(editor); + WeightModel *mymodel = qobject_cast<WeightModel *>(model); + WSInfoModel *ws = WSInfoModel::instance(); + QModelIndex wsIndex = ws->match(ws->index(0,0), Qt::DisplayRole, c->currentText()).first(); + + int grams = ws->data(ws->index(wsIndex.row(), WSInfoModel::GR)).toInt(); + + mymodel->setData(index, c->currentText(), Qt::EditRole); + mymodel->passInData(model->index(index.row(), WeightModel::WEIGHT), grams); +} + +WSInfoDelegate::WSInfoDelegate(QObject* parent): QStyledItemDelegate(parent) +{ +} |