void WSInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& thisindex) const { WeightModel *mymodel = qobject_cast<WeightModel *>(currCombo.model); WSInfoModel *wsim = WSInfoModel::instance(); QModelIndexList matches = wsim->match(wsim->index(0,0), Qt::DisplayRole, currCombo.activeText); int row; if (matches.isEmpty()) { // we need to add this puppy wsim->insertRows(wsim->rowCount(), 1); wsim->setData(wsim->index(wsim->rowCount() - 1, 0), currCombo.activeText); row = wsim->rowCount() - 1; } else { row = matches.first().row(); } int grams = wsim->data(wsim->index(row, WSInfoModel::GR)).toInt(); QVariant v = QString(currCombo.activeText); // don't set if it's the same as it was before setting. if (mymodel->data(thisindex, WeightModel::TYPE).toString() == currCombo.activeText){ return; } mymodel->setData(IDX(WeightModel::TYPE), v, Qt::EditRole); mymodel->passInData(IDX(WeightModel::WEIGHT), grams); qDebug() << "Fixme, every weigth is 0.0 grams. see:" << grams; }
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), currWeight.type, Qt::EditRole); mymodel->passInData(IDX(WeightModel::WEIGHT), currWeight.weight); } }
void WSInfoDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &thisindex) const { WeightModel *mymodel = qobject_cast<WeightModel *>(currCombo.model); WSInfoModel *wsim = WSInfoModel::instance(); QModelIndexList matches = wsim->match(wsim->index(0, 0), Qt::DisplayRole, currCombo.activeText); int row; if (matches.isEmpty()) { // we need to add this puppy wsim->insertRows(wsim->rowCount(), 1); wsim->setData(wsim->index(wsim->rowCount() - 1, 0), currCombo.activeText); row = wsim->rowCount() - 1; } else { row = matches.first().row(); } int grams = wsim->data(wsim->index(row, WSInfoModel::GR)).toInt(); QVariant v = QString(currCombo.activeText); mymodel->setData(IDX(WeightModel::TYPE), v, Qt::EditRole); mymodel->passInData(IDX(WeightModel::WEIGHT), grams); }