Ejemplo n.º 1
0
void DeliverOrderDelegate::setModelData(
        QWidget *editor, QAbstractItemModel * model, const QModelIndex &index) const
{
    QStandardItemModel * sModel = qobject_cast<QStandardItemModel *>(model);

    if (0 == index.column()) {

        FindClientDialog * w = qobject_cast<FindClientDialog *>(editor);
        if (QDialog::Accepted == w->result() && !w->foundClient().isEmpty())
            sModel->itemFromIndex(index)->setText(w->foundClient());

    } else if (2 == index.column()) {

        // Select product.
        FindProductDialog * w = qobject_cast<FindProductDialog *>(editor);
        const data::Product & product = w->foundProduct();
        if (-1 == product.id || QDialog::Accepted != w->result())
            return;

        sModel->blockSignals(true);
        sModel->item(index.row(), 1)->setText(product.category.name);
        sModel->item(index.row(), 4)->setText(product.unit);
        sModel->blockSignals(false);
        sModel->itemFromIndex(index)->setText(product.name);

    } else if (3 == index.column()) {

        QSpinBox * w = qobject_cast<QSpinBox *>(editor);
        sModel->itemFromIndex(index)->setText(QString("%1").arg(w->value()));

    } else if (5 == index.column()) {

        QLineEdit * w = qobject_cast<QLineEdit *>(editor);
        sModel->itemFromIndex(index)->setText(w->text());

    } else {
       return QStyledItemDelegate::setEditorData(editor, index);
    }
}