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; }
QWidget *PoitemTableDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/*style*/, const QModelIndex &index) const { const QAbstractItemModel *model = index.model(); QWidget *editor = 0; switch (index.column()) { case ITEM_NUMBER_COL: { ItemLineEdit *item = new ItemLineEdit(parent); item->setType(ItemLineEdit::cGeneralPurchased | ItemLineEdit::cActive); if ((qobject_cast<const PoitemTableModel*>(model))->_vendrestrictpurch) { int vendid = (qobject_cast<const PoitemTableModel*>(model))->_vendid; // TODO: put queries in ItemLineEdit, trigger them with a setVendId() item->setQuery( QString("SELECT DISTINCT item_id, item_number, item_descrip1, item_descrip2," " uom_name, item_type, item_config " "FROM item, itemsite, itemsrc, uom " "WHERE ( (itemsite_item_id=item_id)" " AND (itemsrc_item_id=item_id)" " AND (item_inv_uom_id=uom_id)" " AND (itemsite_active)" " AND (item_active)" " AND (itemsrc_active)" " AND (itemsrc_vend_id=%1) ) " "ORDER BY item_number;" ) .arg(vendid) ); item->setValidationQuery( QString("SELECT DISTINCT item_id, item_number, item_descrip1, item_descrip2," " uom_name, item_type, item_config " "FROM item, itemsite, itemsrc, uom " "WHERE ( (itemsite_item_id=item_id)" " AND (itemsrc_item_id=item_id)" " AND (item_inv_uom_id=uom_id)" " AND (itemsite_active)" " AND (item_active)" " AND (itemsrc_active)" " AND (itemsrc_vend_id=%1) " " AND (itemsite_item_id=:item_id) ) " "ORDER BY item_number;" ) .arg(vendid) ); } else item->setType(ItemLineEdit::cGeneralPurchased | ItemLineEdit::cActive); editor = item; break; } case WAREHOUS_CODE_COL: { int itemid = model->data(model->index(index.row(), ITEM_ID_COL)).toInt(); if (itemid <= 0) // probably non-inventory item so don't pick a whs break; WComboBox *whs = new WComboBox(parent); whs->setType(WComboBox::Supply); whs->findItemsites(itemid); editor = whs; break; } case POITEM_VEND_ITEM_NUMBER_COL: { editor = new QLineEdit(parent); editor->setObjectName("poitem_vend_item_number"); break; } case POITEM_QTY_ORDERED_COL: { QLineEdit *qty = new QLineEdit(parent); qty->setValidator(omfgThis->qtyVal()); editor = qty; break; } case POITEM_UNITPRICE_COL: case POITEM_FREIGHT_COL: { QLineEdit *price = new QLineEdit(parent); price->setValidator(omfgThis->priceVal()); editor = price; break; } case POITEM_DUEDATE_COL: { DLineEdit *duedate = new DLineEdit(parent); editor = duedate; editor->setObjectName("poitem_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 #ifdef QE_NONINVENTORY case EXPCAT_CODE_COL: { ExpenseLineEdit *expcat = new ExpenseLineEdit(parent); editor = expcat; 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<PoitemTableDelegate*>(this)); } return editor; }