QWidget *ItemLineEditDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/*option*/, const QModelIndex &index) const { if (!index.isValid()) return 0; ItemLineEdit *widget = new ItemLineEdit(parent); // Make editor share certain properties with template widget->setType(_template->type()); QStringList clauses = _template->getExtraClauseList(); for (int i = 0; i < clauses.size(); i++) widget->addExtraClause(clauses.at(i)); return widget; }
QWidget *ToitemTableDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/*style*/, const QModelIndex &index) const { const ToitemTableModel *model = (ToitemTableModel*)(index.model()); QWidget *editor = 0; switch (index.column()) { case ITEM_NUMBER_COL: { ItemLineEdit *item = new ItemLineEdit(parent); item->setType(ItemLineEdit::cActive); item->addExtraClause(QString("(item_id IN (" " SELECT itemsite_item_id" " FROM itemsite" " WHERE itemsite_warehous_id=%1))") .arg(model->srcWhsId())); editor = item; break; } case TOITEM_QTY_ORDERED_COL: { QLineEdit *qty = new QLineEdit(parent); qty->setValidator(omfgThis->qtyVal()); editor = qty; break; } case TOITEM_FREIGHT_COL: { QLineEdit *price = new QLineEdit(parent); price->setValidator(omfgThis->priceVal()); editor = price; break; } case TOITEM_DUEDATE_COL: { DLineEdit *duedate = new DLineEdit(parent); editor = duedate; editor->setObjectName("toitem_duedate"); break; } #ifdef QE_PROJECT case PRJ_NUMBER_COL: { ProjectLineEdit *prj = new ProjectLineEdit(parent); prj->setType(ProjectLineEdit::PurchaseOrder); editor = prj; editor->setObjectName("prj_number"); break; } #endif default: { editor = 0; break; } } if (editor) { #ifdef Q_WS_MAC // compensate for many custom widgets making themselves smaller on OS X QFont f = editor->font(); f.setPointSize(f.pointSize() + 2); editor->setFont(f); #endif editor->installEventFilter(const_cast<ToitemTableDelegate*>(this)); } return editor; }