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); } }
QWidget *WSInfoDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { /* 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); currWeight.type = copy_string(ws->description); currWeight.weight = ws->weight.grams; return editor; }
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); }