コード例 #1
0
void PoitemTableView::setModel(QAbstractItemModel* model)
{

  QTableView::setModel(model);

  setColumnWidth(ITEM_NUMBER_COL,		_itemColumn);
  setColumnWidth(WAREHOUS_CODE_COL,		100); //_whsColumn too small
  setColumnWidth(POITEM_QTY_ORDERED_COL,	_qtyColumn);
  setColumnWidth(POITEM_UNITPRICE_COL,		_priceColumn);
  setColumnWidth(EXTPRICE_COL,			_moneyColumn);
  setColumnWidth(POITEM_FREIGHT_COL,		_priceColumn);
  setColumnWidth(POITEM_DUEDATE_COL,		_dateColumn);
#ifdef QE_PROJECT
  setColumnWidth(PRJ_NUMBER_COL,		100);
#endif
#ifdef QE_NONINVENTORY
  setColumnWidth(EXPCAT_CODE_COL,		100);
#endif
  setColumnWidth(POITEM_VEND_ITEM_NUMBER_COL,	_itemColumn);

  QHeaderView *header = horizontalHeader();

  int dest = 0;
  header->moveSection(header->visualIndex(ITEM_NUMBER_COL),	 	dest++);
  header->moveSection(header->visualIndex(WAREHOUS_CODE_COL),		dest++);
  header->moveSection(header->visualIndex(POITEM_VEND_ITEM_NUMBER_COL),	dest++);
#ifdef QE_NONINVENTORY
  header->moveSection(header->visualIndex(EXPCAT_CODE_COL),		dest++);
#endif
  header->moveSection(header->visualIndex(POITEM_QTY_ORDERED_COL),	dest++);
  header->moveSection(header->visualIndex(POITEM_UNITPRICE_COL),	dest++);
  header->moveSection(header->visualIndex(EXTPRICE_COL),		dest++);
  header->moveSection(header->visualIndex(POITEM_FREIGHT_COL),		dest++);
  header->moveSection(header->visualIndex(POITEM_DUEDATE_COL),		dest++);
#ifdef QE_PROJECT
  header->moveSection(header->visualIndex(PRJ_NUMBER_COL),		dest++);
#endif

  // if we didn't explicitly place the logical section, hide it
  for (int i = dest; i < header->count(); i++)
    header->hideSection(header->logicalIndex(i));

#ifdef QE_PROJECT
  if (! _metrics->boolean("UseProjects"))
    header->hideSection(header->visualIndex(PRJ_NUMBER_COL));
#endif

  //header->setStretchLastSection(true);
}
コード例 #2
0
ファイル: portstatswindow.cpp プロジェクト: Raman325/ostinato
void PortStatsWindow::on_tbFilter_clicked()
{
    bool ok;
    QList<uint>    currentColumns, newColumns;
    PortStatsFilterDialog    dialog;

    // create the input list for the filter dialog -
    // list of logical-indexes ordered by their current visual indexes
    for(int vi = 0; vi < model->columnCount(); vi++) {
        int li = tvPortStats->horizontalHeader()->logicalIndex(vi);
        if (!tvPortStats->isColumnHidden(li)) {
            currentColumns.append(li);
        }
    }

    // return list from the filter dialog -
    // list of logical-indexes ordered by their new visual indexes
    newColumns = dialog.getItemList(&ok, model, Qt::Horizontal, currentColumns);

    if (ok)
    {
        QHeaderView *hv = tvPortStats->horizontalHeader();

        // hide/show sections first ...
        for(int li = 0; li < model->columnCount(); li++)
            tvPortStats->setColumnHidden(li, !newColumns.contains(li));

        // ... then for the 'shown' columns, set the visual index
        for(int vi = 0; vi < newColumns.size(); vi++)
            hv->moveSection(hv->visualIndex(newColumns.at(vi)), vi);
    }
}
コード例 #3
0
//-------------------------------------------------------------------------------------------------
void
BachFolderBrowserTreeView::setupColumns( IniConfig & ini, const BachFolderBrowserTreeView::ColumnStructEx columns [] )
{
	QHeaderView * hdr = header();
	int cnt = 0;
	QStringList labels;
	for( cnt=0; columns[cnt].name; ++cnt );
	QVector<int> indexVec(cnt);
	for( int i=0; i<cnt; i++ ) {
		labels << QString::fromLatin1(columns[i].name);
		indexVec[i] = ini.readInt( columns[i].iniName + QString("Index"), columns[i].defaultPos );
	}
	hdr->setStretchLastSection(false);
	for( int n=0; n<cnt; n++ ) {
		for( int i=0; i<cnt; i++ )
			if( indexVec[i] == n )
				hdr->moveSection( hdr->visualIndex(i), n );
	}
	hdr->resizeSections(QHeaderView::Stretch);
	for( int n=0; n<cnt; n++ ) {
		int size = ini.readInt( columns[n].iniName + QString("Size"), columns[n].defaultSize );
		hdr->resizeSection( n, size==0?columns[n].defaultSize:size );
	}
	for( int n=0; n<cnt; n++ ) {
		bool hidden = ini.readBool( columns[n].iniName + QString("Hidden"), columns[n].defaultHidden );
		hdr->setSectionHidden( n, hidden );
	}
	hdr->setResizeMode( QHeaderView::Interactive );
}
コード例 #4
0
ファイル: folderview.cpp プロジェクト: rbazaud/pcmanfm-qt
// the default list mode of QListView handles column widths
// very badly (worse than gtk+) and it's not very flexible.
// so, let's handle column widths outselves.
void FolderViewTreeView::layoutColumns() {
  // qDebug("layoutColumns");
  if(!model())
    return;
  doingLayout_ = true;
  QHeaderView* headerView = header();
  // the width that's available for showing the columns.
  int availWidth = viewport()->contentsRect().width();
  int desiredWidth = 0;

  // get the width that every column want
  int numCols = headerView->count();
  if(numCols > 0) {
    int* widths = new int[numCols]; // array to store the widths every column needs
    int column;
    for(column = 0; column < numCols; ++column) {
      int columnId = headerView->logicalIndex(column);
      // get the size that the column needs
      widths[column] = sizeHintForColumn(columnId);
      // compute the total width needed
      desiredWidth += widths[column];
    }

    int filenameColumn = headerView->visualIndex(FolderModel::ColumnFileName);
    // if the total witdh we want exceeds the available space
    if(desiredWidth > availWidth) {
      // Compute the width available for the filename column
      int filenameAvailWidth = availWidth - desiredWidth + widths[filenameColumn];

      // Compute the minimum acceptable width for the filename column
      int filenameMinWidth = qMin(200, sizeHintForColumn(filenameColumn));

      if (filenameAvailWidth > filenameMinWidth) {
        // Shrink the filename column to the available width
        widths[filenameColumn] = filenameAvailWidth;
      }
      else {
        // Set the filename column to its minimum width
        widths[filenameColumn] = filenameMinWidth;
      }
    }
    else {
      // Fill the extra available space with the filename column
      widths[filenameColumn] += availWidth - desiredWidth;
    }

    // really do the resizing for every column
    for(int column = 0; column < numCols; ++column) {
      headerView->resizeSection(column, widths[column]);
    }
    delete []widths;
  }
  doingLayout_ = false;

  if(layoutTimer_) {
    delete layoutTimer_;
    layoutTimer_ = nullptr;
  }
}
コード例 #5
0
ファイル: folderview.cpp プロジェクト: crashd/pcmanfm-qt
// the default list mode of QListView handles column widths
// very badly (worse than gtk+) and it's not very flexible.
// so, let's handle column widths outselves.
void FolderViewTreeView::layoutColumns() {
  // qDebug("layoutColumns");
  if(!model())
    return;
  doingLayout_ = true;
  QHeaderView* headerView = header();
  // the width that's available for showing the columns.
  int availWidth = viewport()->contentsRect().width();
  int desiredWidth = 0;

  // get the width that every column want
  int numCols = headerView->count();
  int* widths = new int[numCols]; // array to store the widths every column needs
  int column;
  for(column = 0; column < numCols; ++column) {
    int columnId = headerView->logicalIndex(column);
    // get the size that the column needs
    widths[column] = sizeHintForColumn(columnId);
  }

  // the best case is every column can get its full width
  for(column = 0; column < numCols; ++column) {
    desiredWidth += widths[column];
  }

  // if the total witdh we want exceeds the available space
  if(desiredWidth > availWidth) {
    // we don't have that much space for every column
    int filenameColumn = headerView->visualIndex(FolderModel::ColumnFileName);
    // shrink the filename column first
    desiredWidth -= widths[filenameColumn]; // total width of all other columns

    // see if setting the width of the filename column to 200 solve the problem
    if(desiredWidth + 200 > availWidth) {
      // even when we reduce the width of the filename column to 200,
      // the available space is not enough. So we give up trying.
      widths[filenameColumn] = 200;
      desiredWidth += 200;
    }
    else { // we still have more space, so the width of filename column can be increased
      // expand the filename column to fill all available space.
      widths[filenameColumn] = availWidth - desiredWidth;
      desiredWidth = availWidth;
    }
  }

  // really do the resizing for every column
  for(int column = 0; column < numCols; ++column) {
    headerView->resizeSection(column, widths[column]);
  }

  delete []widths;
  doingLayout_ = false;
  
  if(layoutTimer_) {
    delete layoutTimer_;
    layoutTimer_ = NULL;
  }
}
コード例 #6
0
ファイル: playlistview.cpp プロジェクト: Gu1/Clementine
QModelIndex PlaylistView::PrevEditableIndex(const QModelIndex& current) {
  QList<int> columns = GetEditableColumns();
  QHeaderView* h = header();
  int index = columns.indexOf(h->visualIndex(current.column()));

  if (index - 1 < 0)
    return model()->index(current.row() - 1, h->logicalIndex(columns.last()));

  return model()->index(current.row(), h->logicalIndex(columns[index - 1]));
}
コード例 #7
0
ファイル: playlistview.cpp プロジェクト: Gu1/Clementine
QModelIndex PlaylistView::NextEditableIndex(const QModelIndex& current) {
  QList<int> columns = GetEditableColumns();
  QHeaderView* h = header();
  int index = columns.indexOf(h->visualIndex(current.column()));

  if (index + 1 >= columns.size())
    return model()->index(current.row() + 1, h->logicalIndex(columns.first()));

  return model()->index(current.row(), h->logicalIndex(columns[index + 1]));
}
コード例 #8
0
void PoitemTableView::setModel(QAbstractItemModel* model)
{
  if (DEBUG) qDebug("PoitemTableView::setModel(%p)", model);
  QTableView::setModel(model);

  setColumnWidth(ITEM_NUMBER_COL,		_itemColumn);
  setColumnWidth(WAREHOUS_CODE_COL,		100); //_whsColumn too small
  setColumnWidth(POITEM_VEND_ITEM_DESCRIP_COL, 200);
  setColumnWidth(POITEM_QTY_ORDERED_COL,	_qtyColumn);
  setColumnWidth(POITEM_UNITPRICE_COL,		_priceColumn);
  setColumnWidth(EXTPRICE_COL,			_moneyColumn);
  setColumnWidth(POITEM_FREIGHT_COL,		_priceColumn);
  setColumnWidth(POITEM_DUEDATE_COL,		_dateColumn);
#ifdef QE_NONINVENTORY
  setColumnWidth(EXPCAT_CODE_COL,		100);
#endif
  setColumnWidth(POITEM_VEND_ITEM_NUMBER_COL,	_itemColumn);

  QHeaderView *header = horizontalHeader();

  int dest = 0;
  header->moveSection(header->visualIndex(ITEM_NUMBER_COL),	 	dest++);
  if (_metrics->boolean("MultiWhs"))
  {
  header->moveSection(header->visualIndex(WAREHOUS_CODE_COL),		dest++);
  }
  header->moveSection(header->visualIndex(POITEM_VEND_ITEM_NUMBER_COL),	dest++);
  header->moveSection(header->visualIndex(POITEM_VEND_ITEM_DESCRIP_COL),	dest++);
#ifdef QE_NONINVENTORY
  header->moveSection(header->visualIndex(EXPCAT_CODE_COL),		dest++);
#endif
  header->moveSection(header->visualIndex(POITEM_QTY_ORDERED_COL),	dest++);
  header->moveSection(header->visualIndex(POITEM_UNITPRICE_COL),	dest++);
  header->moveSection(header->visualIndex(EXTPRICE_COL),		dest++);
  header->moveSection(header->visualIndex(POITEM_FREIGHT_COL),		dest++);
  header->moveSection(header->visualIndex(POITEM_DUEDATE_COL),		dest++);

  // if we didn't explicitly place the logical section, hide it
  for (int i = dest; i < header->count(); i++)
    header->hideSection(header->logicalIndex(i));

  connect(model, SIGNAL(headerDataChanged(Qt::Orientation, int, int)),
          this,  SLOT(sHeaderDataChanged(Qt::Orientation, int, int)));

  //header->setStretchLastSection(true);
  if (DEBUG) qDebug("PoitemTableView::setModel returning");
}
コード例 #9
0
//-------------------------------------------------------------------------------------------------
void
BachFolderBrowserTreeView::saveColumns( IniConfig & ini, const BachFolderBrowserTreeView::ColumnStructEx columns [] )
{
	QHeaderView * hdr = header();
	for( int i=0; columns[i].name; i++ )
		ini.writeInt( columns[i].iniName + QString("Size"), hdr->sectionSize( i ) );
	for( int i=0; columns[i].name; i++ )
		ini.writeInt( columns[i].iniName + QString("Index"), hdr->visualIndex( i ) );
	for( int i=0; columns[i].name; i++ )
		ini.writeBool( columns[i].iniName + QString("Hidden"), hdr->isSectionHidden( i ) );
}
コード例 #10
0
ファイル: playlistview.cpp プロジェクト: Gu1/Clementine
QList<int> PlaylistView::GetEditableColumns() {
  QList<int> columns;
  QHeaderView* h = header();
  for (int col = 0; col < h->count(); col++) {
    if (h->isSectionHidden(col)) continue;
    QModelIndex index = model()->index(0, col);
    if (index.flags() & Qt::ItemIsEditable) columns << h->visualIndex(col);
  }
  qSort(columns);
  return columns;
}
コード例 #11
0
void FilmsViewList::RestoreColumnsOrder()
{
    DebugPrintFunc( "FilmsViewList::RestoreColumnsOrder" );
    QHeaderView* header = horizontalHeader();

    for( int i = 0; i < model()->columnCount(); ++i )
    {
        header->moveSection( header->visualIndex(i), i );
    }

    DebugPrintFuncDone( "FilmsViewList::RestoreColumnsOrder" );
}
コード例 #12
0
void TreeLog::loadConfig()
{
	QList<int> colWidths = Config::treeLogColumnWidths();
	QList<int> colPositions = Config::treeLogColumnPositions();
	QList<int> colVisible = Config::treeLogColumnVisible();
	QHeaderView* header = treeLog().header();

	for (int i = 0; i < treeLog().columnCount(); i++)
	{
		if (colPositions[0] != -1 && colPositions.size() > i)
			header->moveSection(header->visualIndex(i), colPositions[i]);

		if (colVisible[0] != -1 && colVisible.size() > i)
			treeLog().setColumnHidden(i, colVisible[i] == 0);

		if (colWidths[0] != -1 && colWidths.size() > i)
			treeLog().setColumnWidth(i, colWidths[i]);
	}
}
コード例 #13
0
ファイル: TreeWidget.cpp プロジェクト: kindsenior/choreonoid
void TreeWidget::paintEvent(QPaintEvent* event)
{
    QTreeWidget::paintEvent(event);

    if(isVerticalGridLineShown && topLevelItemCount()){
        QHeaderView* hv = header();
        QPainter painter(viewport());
        QPen oldPen = painter.pen();
        painter.setPen(QPen(QColor::fromRgb(gridColorRGB)));
    
        for(int i = 0; i < hv->count(); ++i){
            // draw only visible sections starting from second column
            if(hv->isSectionHidden(i) || hv->visualIndex(i) <= 0){
                continue;
            }
            // position mapped to viewport
            int pos = hv->sectionViewportPosition(i) - 1;
            if(pos > 0){
                painter.drawLine(QPoint(pos, 0), QPoint(pos, height()));
            }
        }
        painter.setPen(oldPen);
    }
}
コード例 #14
0
void ToitemTableView::setModel(QAbstractItemModel* model)
{

  QTableView::setModel(model);

  setColumnWidth(ITEM_NUMBER_COL,		_itemColumn);
  setColumnWidth(TOITEM_QTY_ORDERED_COL,	_qtyColumn);
  setColumnWidth(TOITEM_STDCOST_COL,		_priceColumn);
  setColumnWidth(TOITEM_FREIGHT_COL,		_priceColumn);
  setColumnWidth(TOITEM_DUEDATE_COL,		_dateColumn);
#ifdef QE_PROJECT
  setColumnWidth(PRJ_NUMBER_COL,		100);
#endif

  QHeaderView *header = horizontalHeader();

  int dest = 0;
  header->moveSection(header->visualIndex(ITEM_NUMBER_COL),	 	dest++);
  header->moveSection(header->visualIndex(TOITEM_QTY_ORDERED_COL),	dest++);
  header->moveSection(header->visualIndex(TOITEM_STDCOST_COL),		dest++);
  header->moveSection(header->visualIndex(TOITEM_FREIGHT_COL),		dest++);
  header->moveSection(header->visualIndex(TOITEM_DUEDATE_COL),		dest++);
#ifdef QE_PROJECT
  header->moveSection(header->visualIndex(PRJ_NUMBER_COL),		dest++);
#endif

  // if we didn't explicitly place the logical section, hide it
  for (int i = dest; i < header->count(); i++)
    header->hideSection(header->logicalIndex(i));

#ifdef QE_PROJECT
  if (! _metrics->boolean("UseProjects"))
    header->hideSection(header->visualIndex(PRJ_NUMBER_COL));
#endif

  //header->setStretchLastSection(true);
}
コード例 #15
0
void ToitemTableDelegate::setModelData(QWidget *editor, QAbstractItemModel *pModel, const QModelIndex &index) const
{
  bool hitError = false;
  QVariant oldval = pModel->data(index);
  ToitemTableModel *model = static_cast<ToitemTableModel*>(pModel);

  switch (index.column())
  {
    case ITEM_NUMBER_COL:
    {
      ItemLineEdit *item = static_cast<ItemLineEdit*>(editor);
      if (oldval.isNull() || item->itemNumber() != oldval.toString())
      {
	if (! item->itemNumber().isEmpty() && item->isValid())
	{
	  XSqlQuery itemq;
	  itemq.prepare("SELECT *, stdCost(item_id) AS stdcost, uom_name "
			"FROM item JOIN uom ON (item_inv_uom_id=uom_id) "
			"WHERE (item_id=:item_id);");
	  itemq.bindValue(":item_id", item->id());
	  itemq.exec();
	  if (itemq.first())
	  {
	    if (itemq.value("stdcost").toDouble() == 0.0)
	    {
	      QMessageBox::critical(0, tr("No Standard Cost"),
		      tr("<p>The selected item has no Standard "
			 "Costing information. Please see your "
			 "controller to correct this situation "
			 "before continuing."));
	      hitError = true;
	      break;
	    }
	    model->setData(index, item->itemNumber());
	    model->setData(model->index(index.row(), TOITEM_ITEM_ID_COL), itemq.value("item_id").toInt());
	    model->setData(model->index(index.row(), TOITEM_UOM_COL), itemq.value("uom_name"));
	    model->setData(model->index(index.row(), TOITEM_STDCOST_COL),
			   formatPurchPrice(itemq.value("stdcost").toDouble()));
	  }
	  else if (itemq.lastError().type() != QSqlError::NoError)
	  {
	    systemError(0, itemq.lastError().databaseText(), __FILE__, __LINE__);
	    hitError = true;
	    break;
	  }
	}
	if (hitError)
	{
	  model->setData(index, QVariant(QVariant::String));
	  model->setData(model->index(index.row(), TOITEM_ITEM_ID_COL), QVariant(QVariant::Int));
	  model->setData(model->index(index.row(), TOITEM_STDCOST_COL), QVariant(QVariant::Double));
	}
      }
      break;
    }

    case TOITEM_FREIGHT_COL:
    {
      QLineEdit *lineedit = static_cast<QLineEdit*>(editor);
      if (lineedit->text().toDouble() != oldval.toDouble())
	model->setData(index, formatPurchPrice(lineedit->text().toDouble()));
      break;
    }

    case TOITEM_QTY_ORDERED_COL:
    {
      QLineEdit *lineedit = static_cast<QLineEdit*>(editor);
      if (lineedit->text().isEmpty())
	model->setData(index, QVariant());
      else
	model->setData(index, lineedit->text().toDouble());
      break;
    }
    
    case TOITEM_DUEDATE_COL:
    {
      DLineEdit *duedate = static_cast<DLineEdit*>(editor);
      if (duedate->date() != oldval.toDate())
      {
	model->setData(index, duedate->date());
      }

      break;
    }

#ifdef QE_PROJECT
    case PRJ_NUMBER_COL:
    {
      ProjectLineEdit *prj = static_cast<ProjectLineEdit*>(editor);
      if (prj->id() != oldval.toInt())
      {
	model->setData(model->index(index.row(), TOITEM_PRJ_ID_COL), prj->id());
	model->setData(index, prj->text());
      }
      break;
    }
#endif

    default:
      break;
  }

  QTableView *view = qobject_cast<QTableView*>(parent());
  if (view)
  {
    if (hitError)
      view->setCurrentIndex(index);
    else if (index.row() >= (model->rowCount() - 1))
    {
      QHeaderView* header = view->horizontalHeader();
      if (header->visualIndex(index.column()) >=
	  (header->count() - header->hiddenSectionCount() - 1))
      {
	model->insertRow(model->rowCount());
      }
    }
  }

  return;
}
コード例 #16
0
void PoitemTableDelegate::setModelData(QWidget *editor, QAbstractItemModel *pModel, const QModelIndex &index) const
{
  bool hitError = false;
  QVariant oldval = pModel->data(index);
  PoitemTableModel *model = static_cast<PoitemTableModel*>(pModel);

  switch (index.column())
  {
    case ITEM_NUMBER_COL:
    {
      ItemLineEdit *item = static_cast<ItemLineEdit*>(editor);
      if (item->itemNumber() != oldval.toString())
      {
	if (item->itemNumber().isEmpty())
	{
	  model->setData(index, new QVariant());
	  model->setData(model->index(index.row(), ITEM_ID_COL), new QVariant());
	  model->setData(model->index(index.row(), POITEM_ITEMSITE_ID_COL), new QVariant());
	  model->setData(model->index(index.row(), WAREHOUS_ID_COL), new QVariant());
	  model->setData(model->index(index.row(), WAREHOUS_CODE_COL), new QVariant());
	  model->setData(model->index(index.row(), POITEM_ITEMSRC_ID_COL), new QVariant());
	  model->setData(model->index(index.row(), POITEM_VEND_ITEM_NUMBER_COL), new QVariant());
	  model->setData(model->index(index.row(), POITEM_VEND_ITEM_DESCRIP_COL), new QVariant());
	  model->setData(model->index(index.row(), POITEM_VEND_UOM_COL), new QVariant());
	  model->setData(model->index(index.row(), ITEMSRC_MINORDQTY_COL), new QVariant());
	  model->setData(model->index(index.row(), ITEMSRC_MULTORDQTY_COL), new QVariant());
	  model->setData(model->index(index.row(), ITEMSRC_INVVENDORUOMRATIO_COL), new QVariant());
	  model->setData(model->index(index.row(), POITEM_INVVENDUOMRATIO_COL), new QVariant());
	  model->setData(model->index(index.row(), EARLIESTDATE_COL), new QVariant());
	}
	else
	{
	  model->setData(index, item->itemNumber());
	  model->setData(model->index(index.row(), ITEM_ID_COL), item->id());

	  if (item->isValid())
	  {
	    XSqlQuery itemq;
	    itemq.prepare("SELECT (warehous_id=:preferred) AS preferred, "
			  "       itemsite_id, warehous_id, warehous_code "
			  "FROM itemsite, whsinfo "
			  "WHERE ((itemsite_item_id=:item_id)"
			  "   AND (itemsite_warehous_id=warehous_id)) "
			  "ORDER BY preferred DESC, warehous_code "
			  "LIMIT 1;");
	    itemq.bindValue(":item_id", item->id());
	    itemq.bindValue(":preferred",
			   _x_preferences->value("PreferredWarehouse").toInt());
	    itemq.exec();
	    if (itemq.first())
	    {
	      model->setData(model->index(index.row(), POITEM_ITEMSITE_ID_COL), itemq.value("itemsite_id").toInt());
	      model->setData(model->index(index.row(), WAREHOUS_ID_COL), itemq.value("warehous_id").toInt());
	      model->setData(model->index(index.row(), WAREHOUS_CODE_COL), itemq.value("warehous_code").toString());
	    }
	    else if (itemq.lastError().type() != QSqlError::None)
	    {
	      systemError(0, itemq.lastError().databaseText(), __FILE__, __LINE__);
	      hitError = true;
	      break;
	    }
	    else
	    {
	      systemError(0, QString("Could not find Item Site for %1 (%2).")
			      .arg(item->itemNumber()).arg(item->id()));
	      hitError = true;
	      break;
	    }

	    if (_metrics->boolean("RequireStdCostForPOItem"))
	    {
	      XSqlQuery stdcostq;
	      stdcostq.prepare("SELECT stdCost(:item_id) AS result");
	      stdcostq.bindValue(":item_id", item->id());
	      stdcostq.exec();
	      if(stdcostq.first() && stdcostq.value("result").toDouble() == 0.0)
	      {
		QMessageBox::critical(0, tr("Selected Item Missing Cost"),
			tr("<p>The selected item has no Std. Costing information. "
			   "Please see your controller to correct this situation "
			   "before continuing."));
		model->setData(index, new QString());
		model->setData(model->index(index.row(), POITEM_ITEMSITE_ID_COL), new QVariant());
		model->setData(model->index(index.row(), WAREHOUS_ID_COL), new QVariant());
		model->setData(model->index(index.row(), WAREHOUS_CODE_COL), new QString());
		model->setData(index, new QString());
		hitError = true;
		break;
	      }
	      else if (stdcostq.lastError().type() != QSqlError::None)
	      {
		systemError(0, stdcostq.lastError().databaseText(), __FILE__, __LINE__);
		hitError = true;
		break;
	      }
	    }

	    XSqlQuery itemsrcq;
	    itemsrcq.prepare( "SELECT itemsrc_id, itemsrc_vend_item_number,"
		       "       itemsrc_vend_item_descrip, itemsrc_vend_uom,"
		       "       itemsrc_minordqty,"
		       "       itemsrc_multordqty,"
		       "       itemsrc_invvendoruomratio,"
		       "       (CURRENT_DATE + itemsrc_leadtime) AS earliestdate "
		       "FROM pohead, itemsrc "
		       "WHERE ( (itemsrc_vend_id=pohead_vend_id)"
		       " AND (itemsrc_item_id=:item_id)"
		       " AND (pohead_id=:pohead_id) );" );
	    itemsrcq.bindValue(":item_id", item->id());
	    itemsrcq.bindValue(":pohead_id", model->headId());
	    itemsrcq.exec();
	    if (itemsrcq.first())
	    {
	      model->setData(model->index(index.row(), POITEM_ITEMSRC_ID_COL), itemsrcq.value("itemsrc_id").toInt());
	      model->setData(model->index(index.row(), POITEM_VEND_ITEM_NUMBER_COL), itemsrcq.value("itemsrc_vend_item_number").toString());
	      model->setData(model->index(index.row(), POITEM_VEND_ITEM_DESCRIP_COL), itemsrcq.value("itemsrc_vend_item_descrip").toString());
	      model->setData(model->index(index.row(), POITEM_VEND_UOM_COL), itemsrcq.value("itemsrc_vend_uom").toString());
	      model->setData(model->index(index.row(), ITEMSRC_MINORDQTY_COL), itemsrcq.value("itemsrc_minordqty").toDouble());
	      model->setData(model->index(index.row(), ITEMSRC_MULTORDQTY_COL), itemsrcq.value("itemsrc_multordqty").toDouble());
	      model->setData(model->index(index.row(), ITEMSRC_INVVENDORUOMRATIO_COL), itemsrcq.value("itemsrc_invvendoruomratio").toDouble());
	      model->setData(model->index(index.row(), POITEM_INVVENDUOMRATIO_COL), itemsrcq.value("itemsrc_invvendoruomratio").toDouble());
	      model->setData(model->index(index.row(), EARLIESTDATE_COL), itemsrcq.value("earliestdate").toDate());

	      if (_metrics->boolean("UseEarliestAvailDateOnPOItem"))
		model->setData(model->index(index.row(), POITEM_DUEDATE_COL), itemsrcq.value("earliestdate").toDate());
	    }
	    else if (itemsrcq.lastError().type() != QSqlError::None)
	    {
	      systemError(0, itemsrcq.lastError().databaseText(), __FILE__, __LINE__);
	      hitError = true;
	      break;
	    }
	  }
	}
      }
      break;
    }

    case WAREHOUS_CODE_COL:
    {
      WComboBox *whs = static_cast<WComboBox*>(editor);
      if (whs->id() < 0)
      {
	model->setData(model->index(index.row(), WAREHOUS_ID_COL), QVariant());
	model->setData(index, QVariant());
      }
      else if (whs->id() != oldval.toInt())
      {
	model->setData(model->index(index.row(), WAREHOUS_ID_COL), whs->id());
	model->setData(index, whs->currentText());

	if (whs->isValid())
	{
	  XSqlQuery itemq;
	  itemq.prepare("SELECT itemsite_id "
			"FROM itemsite "
			"WHERE ((itemsite_item_id=:item_id)"
			"   AND (itemsite_warehous_id=:whs_id)) "
			"LIMIT 1;");
	  itemq.bindValue(":item_id", model->index(index.row(), ITEM_ID_COL).data());
	  itemq.bindValue(":whs_id",  whs->id());
	  itemq.exec();
	  if (itemq.first())
	  {
	    model->setData(model->index(index.row(), POITEM_ITEMSITE_ID_COL), itemq.value("itemsite_id").toInt());
	  }
	  else if (itemq.lastError().type() != QSqlError::None)
	  {
	    systemError(0, itemq.lastError().databaseText(), __FILE__, __LINE__);
	    hitError = true;
	    break;
	  }
	  else
	  {
	    systemError(0, QString("Could not find Item Site for %1 in %2.")
			    .arg(model->index(index.row(), ITEM_NUMBER_COL).data().toString())
			    .arg(whs->currentText()));
	    hitError = true;
	    break;
	  }
	}
      }
      break;
    }

    case POITEM_VEND_ITEM_NUMBER_COL:
    {
      QLineEdit *lineedit = static_cast<QLineEdit*>(editor);
      if (lineedit->text() != oldval.toString())
	model->setData(index, lineedit->text());
      break;
    }
    
    case POITEM_FREIGHT_COL:
    {
      QLineEdit *lineedit = static_cast<QLineEdit*>(editor);
      if (lineedit->text().toDouble() != oldval.toDouble())
	model->setData(index, formatPurchPrice(lineedit->text().toDouble()));
      break;
    }


    case POITEM_QTY_ORDERED_COL:
    {
      QLineEdit *lineedit = static_cast<QLineEdit*>(editor);
      if (lineedit->text().isEmpty())
      {
	model->setData(index, QVariant());
	model->setData(model->index(index.row(), EXTPRICE_COL), QVariant());
	break;
      }
      double qty = lineedit->text().toDouble();
      if (qty != oldval.toDouble())
      {
	model->setData(index, formatQty(qty));
	if (model->data(model->index(index.row(), POITEM_QTY_ORDERED_COL)).toDouble() > 0 &&
	  model->data(model->index(index.row(), POITEM_ITEMSRC_ID_COL)).toInt() > 0)
	{
	  q.prepare( "SELECT ROUND(currToCurr(itemsrcp_curr_id, :curr_id, itemsrcp_price, :effective), :prec) "
		      "AS new_itemsrcp_price "
		     "FROM itemsrcp "
		     "WHERE ( (itemsrcp_itemsrc_id=:itemsrc_id)"
		     " AND (itemsrcp_qtybreak <= :qty) ) "
		     "ORDER BY itemsrcp_qtybreak DESC "
		     "LIMIT 1;" );
	  q.bindValue(":itemsrc_id", model->data(model->index(index.row(), POITEM_ITEMSRC_ID_COL)).toInt());
	  q.bindValue(":qty", model->data(model->index(index.row(), POITEM_QTY_ORDERED_COL)).toDouble());
	  q.bindValue(":curr_id", model->currId());
	  q.bindValue(":effective", model->transDate().toString());
	  q.bindValue(":prec", omfgThis->priceVal()->decimals());
	  q.exec();
	  if (q.first())
	  {
	    model->setData(model->index(index.row(), POITEM_UNITPRICE_COL), q.value("new_itemsrcp_price").toDouble());
	  }
	  else if (q.lastError().type() != QSqlError::None)
	  {
	    systemError(0, q.lastError().databaseText(), __FILE__, __LINE__);
	    hitError = true;
	    break;
	  }
	  else
	    model->setData(model->index(index.row(), POITEM_UNITPRICE_COL), 0);
	}

	double prc = model->data(model->index(index.row(), POITEM_UNITPRICE_COL)).toDouble();
	model->setData(model->index(index.row(), EXTPRICE_COL), formatPurchPrice(qty * prc));
      }
      break;
    }
    
    case POITEM_UNITPRICE_COL:
    {
      QLineEdit *lineedit = static_cast<QLineEdit*>(editor);
      if (lineedit->text().isEmpty())
      {
	model->setData(index, QVariant());
	model->setData(model->index(index.row(), EXTPRICE_COL), QVariant());
	break;
      }
      double prc = lineedit->text().toDouble();
      if (prc != oldval.toDouble())
      {
	model->setData(index, prc);
	double qty = model->data(model->index(index.row(),POITEM_QTY_ORDERED_COL)).toDouble();
	model->setData(model->index(index.row(), EXTPRICE_COL), formatPurchPrice(qty * prc));
      }
      break;
    }

    case POITEM_DUEDATE_COL:
    {
      DLineEdit *duedate = static_cast<DLineEdit*>(editor);
      if (duedate->date() != oldval.toDate())
      {
	model->setData(index, duedate->date());
      }

      break;
    }

#ifdef QE_PROJECT
    case PRJ_NUMBER_COL:
    {
      ProjectLineEdit *prj = static_cast<ProjectLineEdit*>(editor);
      if (prj->id() != oldval.toInt())
      {
	model->setData(model->index(index.row(), POITEM_PRJ_ID_COL), prj->id());
	model->setData(index, prj->text());
      }
      break;
    }
#endif

#ifdef QE_NONINVENTORY
    case EXPCAT_CODE_COL:
    {
      ExpenseLineEdit *exp = static_cast<ExpenseLineEdit*>(editor);
      if (exp->id() != oldval.toInt())
      {
	model->setData(model->index(index.row(), POITEM_EXPCAT_ID_COL), exp->id());
	model->setData(index, exp->text());
      }
      break;
    }
#endif

    default:
      break;
  }

  QTableView *view = qobject_cast<QTableView*>(parent());
  if (view)
  {
    if (hitError)
      view->setCurrentIndex(index);
    else if (index.row() >= (model->rowCount() - 1))
    {
      QHeaderView* header = view->horizontalHeader();
      if (header->visualIndex(index.column()) >=
	  (header->count() - header->hiddenSectionCount() - 1))
      {
	model->insertRow(model->rowCount());
      }
    }
  }

  return;
}
コード例 #17
0
ファイル: QtlHeaderView.cpp プロジェクト: Wushaowei001/NAF
int HeaderView::visualIndex(lua_State * L) // ( int logicalIndex ) const : int
{
    QHeaderView* obj = QtObject<QHeaderView>::check( L, 1);
	Util::push( L, obj->visualIndex( Util::toInt( L, 2) ) );
	return 1;
}
コード例 #18
0
void PoitemTableDelegate::setModelData(QWidget *editor, QAbstractItemModel *pModel, const QModelIndex &index) const
{
  XSqlQuery PoitemetModelData;
  if (DEBUG)
    qDebug("PoitemTableDelegate::setModelData() entered");
  bool hitError = false;
  QVariant oldval = pModel->data(index);
  PoitemTableModel *model = static_cast<PoitemTableModel*>(pModel);

  switch (index.column())
  {
    case ITEM_NUMBER_COL:
    {
      ItemLineEdit *item = static_cast<ItemLineEdit*>(editor);
      if (item->itemNumber() != oldval.toString())
      {
	if (item->itemNumber().isEmpty())
	{
	  model->setData(index, QVariant());
	  model->setData(model->index(index.row(), ITEM_ID_COL), QVariant());
	  model->setData(model->index(index.row(), POITEM_ITEMSITE_ID_COL), QVariant());
	  model->setData(model->index(index.row(), WAREHOUS_ID_COL), QVariant());
	  model->setData(model->index(index.row(), WAREHOUS_CODE_COL), QVariant());
	  model->setData(model->index(index.row(), POITEM_ITEMSRC_ID_COL), QVariant());
	  model->setData(model->index(index.row(), POITEM_VEND_ITEM_NUMBER_COL), QVariant());
	  model->setData(model->index(index.row(), POITEM_VEND_ITEM_DESCRIP_COL), QVariant());
	  model->setData(model->index(index.row(), POITEM_VEND_UOM_COL), QVariant());
	  model->setData(model->index(index.row(), ITEMSRC_MINORDQTY_COL), QVariant());
	  model->setData(model->index(index.row(), ITEMSRC_MULTORDQTY_COL), QVariant());
	  model->setData(model->index(index.row(), ITEMSRC_INVVENDORUOMRATIO_COL), QVariant());
	  model->setData(model->index(index.row(), POITEM_INVVENDUOMRATIO_COL), QVariant());
	  model->setData(model->index(index.row(), EARLIESTDATE_COL), QVariant());
	}
	else
	{
	  model->setData(index, item->itemNumber());
	  model->setData(model->index(index.row(), ITEM_ID_COL), item->id());

	  if (item->isValid())
	  {
	    XSqlQuery itemq;
	    itemq.prepare("SELECT (warehous_id=:preferred) AS preferred, "
			  "       itemsite_id, warehous_id, warehous_code "
			  "FROM itemsite, whsinfo "
			  "WHERE ((itemsite_item_id=:item_id)"
			  "   AND (itemsite_warehous_id=warehous_id)) "
			  "ORDER BY preferred DESC, warehous_code "
			  "LIMIT 1;");
	    itemq.bindValue(":item_id", item->id());
	    itemq.bindValue(":preferred",
			   _x_preferences->value("PreferredWarehouse").toInt());
	    itemq.exec();
	    if (itemq.first())
	    {
	      model->setData(model->index(index.row(), POITEM_ITEMSITE_ID_COL), itemq.value("itemsite_id").toInt());
	      model->setData(model->index(index.row(), WAREHOUS_ID_COL), itemq.value("warehous_id").toInt());
	      model->setData(model->index(index.row(), WAREHOUS_CODE_COL), itemq.value("warehous_code").toString());
	    }
        else if (ErrorReporter::error(QtCriticalMsg, 0, tr("Error Retrieving PO Information"),
                                      itemq, __FILE__, __LINE__))
        {
          hitError = true;
          break;
        }
	    else
	    {
          ErrorReporter::error(QtCriticalMsg, 0, tr("Error Occurred"),
                               tr("Could not find Item Site for %1 (%2).")
                               .arg(item->itemNumber())
                               .arg(item->id()),__FILE__,__LINE__);
	      hitError = true;
	      break;
	    }

	    if (_metrics->boolean("RequireStdCostForPOItem"))
	    {
	      XSqlQuery stdcostq;
	      stdcostq.prepare("SELECT stdCost(:item_id) AS result");
	      stdcostq.bindValue(":item_id", item->id());
	      stdcostq.exec();
	      if(stdcostq.first() && stdcostq.value("result").toDouble() == 0.0)
	      {
		QMessageBox::critical(0, tr("Selected Item Missing Cost"),
			tr("<p>The selected item has no Std. Costing information. "
			   "Please see your controller to correct this situation "
			   "before continuing."));
		model->setData(index, QString());
		model->setData(model->index(index.row(), POITEM_ITEMSITE_ID_COL), QVariant());
		model->setData(model->index(index.row(), WAREHOUS_ID_COL), QVariant());
		model->setData(model->index(index.row(), WAREHOUS_CODE_COL), QString());
		model->setData(index, QString());
		hitError = true;
		break;
	      }
          else if (ErrorReporter::error(QtCriticalMsg, 0, tr("Error Retrieving Standard Cost Information"),
                                        stdcostq, __FILE__, __LINE__))
          {
            hitError = true;
            break;
          }
	    }

	    XSqlQuery itemsrcq;
	    itemsrcq.prepare( "SELECT pohead_vend_id, itemsrc_id, itemsrc_vend_item_number,"
		       "       itemsrc_vend_item_descrip, itemsrc_vend_uom,"
		       "       itemsrc_minordqty,"
		       "       itemsrc_multordqty,"
		       "       itemsrc_invvendoruomratio,"
                       "       itemsrc_manuf_name,"
                       "       itemsrc_manuf_item_number,"
                       "       itemsrc_manuf_item_descrip,"
		       "       (CURRENT_DATE + itemsrc_leadtime) AS earliestdate "
		       "FROM pohead, itemsrc "
		       "WHERE ( (itemsrc_vend_id=pohead_vend_id)"
		       " AND (itemsrc_item_id=:item_id)"
		       " AND (pohead_id=:pohead_id) );" );
	    itemsrcq.bindValue(":item_id", item->id());
	    itemsrcq.bindValue(":pohead_id", model->headId());
	    itemsrcq.exec();
            if (itemsrcq.size() > 1)
            {
              itemsrcq.first();
              ParameterList params;
              params.append("vend_id",  itemsrcq.value("pohead_vend_id").toInt());
              params.append("search", item->itemNumber());
              itemSourceSearch newdlg(0, "", true);
              newdlg.set(params);
              if(newdlg.exec() == XDialog::Accepted)
              {
                int itemsrcid = newdlg.itemsrcId();
                if(itemsrcid != -1)
                {
                  itemsrcq.prepare( "SELECT itemsrc_id, itemsrc_vend_item_number,"
                             "       itemsrc_vend_item_descrip, itemsrc_vend_uom,"
                             "       itemsrc_minordqty,"
                             "       itemsrc_multordqty,"
                             "       itemsrc_invvendoruomratio,"
                             "       itemsrc_manuf_name,"
                             "       itemsrc_manuf_item_number,"
                             "       itemsrc_manuf_item_descrip,"
                             "       (CURRENT_DATE + itemsrc_leadtime) AS earliestdate "
                             "FROM pohead, itemsrc "
                             "WHERE (itemsrc_id=:itemsrc_id);" );
                  itemsrcq.bindValue(":itemsrc_id", itemsrcid);
                  itemsrcq.exec();
                }
              }
              else
                itemsrcq.clear();
            }
	    if (itemsrcq.first())
	    {
	      model->setData(model->index(index.row(), POITEM_ITEMSRC_ID_COL), itemsrcq.value("itemsrc_id").toInt());
	      model->setData(model->index(index.row(), POITEM_VEND_ITEM_NUMBER_COL), itemsrcq.value("itemsrc_vend_item_number").toString());
	      model->setData(model->index(index.row(), POITEM_VEND_ITEM_DESCRIP_COL), itemsrcq.value("itemsrc_vend_item_descrip").toString());
	      model->setData(model->index(index.row(), POITEM_VEND_UOM_COL), itemsrcq.value("itemsrc_vend_uom").toString());
	      model->setData(model->index(index.row(), ITEMSRC_MINORDQTY_COL), itemsrcq.value("itemsrc_minordqty").toDouble());
	      model->setData(model->index(index.row(), ITEMSRC_MULTORDQTY_COL), itemsrcq.value("itemsrc_multordqty").toDouble());
	      model->setData(model->index(index.row(), ITEMSRC_INVVENDORUOMRATIO_COL), itemsrcq.value("itemsrc_invvendoruomratio").toDouble());
	      model->setData(model->index(index.row(), POITEM_INVVENDUOMRATIO_COL), itemsrcq.value("itemsrc_invvendoruomratio").toDouble());
          model->setData(model->index(index.row(), POITEM_MANUF_NAME_COL), itemsrcq.value("itemsrc_manuf_name").toString());
          model->setData(model->index(index.row(), POITEM_MANUF_ITEM_NUMBER_COL), itemsrcq.value("itemsrc_manuf_item_number").toString());
          model->setData(model->index(index.row(), POITEM_MANUF_ITEM_DESCRIP_COL), itemsrcq.value("itemsrc_manuf_item_descrip").toString());
	      model->setData(model->index(index.row(), EARLIESTDATE_COL), itemsrcq.value("earliestdate").toDate());

	      if (_metrics->boolean("UseEarliestAvailDateOnPOItem"))
		model->setData(model->index(index.row(), POITEM_DUEDATE_COL), itemsrcq.value("earliestdate").toDate());
	    }
        else if (ErrorReporter::error(QtCriticalMsg, 0, tr("Error Retrieving Item Information"),
                                      itemsrcq, __FILE__, __LINE__))
        {
          hitError = true;
          break;
        }
	  }
	}
      }
      break;
    }

    case WAREHOUS_CODE_COL:
    {
      WComboBox *whs = static_cast<WComboBox*>(editor);
      if (whs->id() < 0)
      {
	model->setData(model->index(index.row(), WAREHOUS_ID_COL), QVariant());
	model->setData(index, QVariant());
      }
      else if (whs->id() != oldval.toInt())
      {
	model->setData(model->index(index.row(), WAREHOUS_ID_COL), whs->id());
	model->setData(index, whs->currentText());

	if (whs->isValid())
	{
	  XSqlQuery itemq;
	  itemq.prepare("SELECT itemsite_id "
			"FROM itemsite "
			"WHERE ((itemsite_item_id=:item_id)"
			"   AND (itemsite_warehous_id=:whs_id)) "
			"LIMIT 1;");
	  itemq.bindValue(":item_id", model->index(index.row(), ITEM_ID_COL).data());
	  itemq.bindValue(":whs_id",  whs->id());
	  itemq.exec();
	  if (itemq.first())
	  {
	    model->setData(model->index(index.row(), POITEM_ITEMSITE_ID_COL), itemq.value("itemsite_id").toInt());
	  }
      else if (ErrorReporter::error(QtCriticalMsg, 0, tr("Error Retrieving Item Site Information"),
                                    itemq, __FILE__, __LINE__))
      {
        hitError = true;
        break;
      }
	  else
	  {
        ErrorReporter::error(QtCriticalMsg, 0, tr("Error Occurred"),
                             tr("%1: Could not find Item Site for %1 in %2.")
                             .arg(model->index(index.row(), ITEM_NUMBER_COL).data().toString())
                             .arg(whs->currentText())
                             ,__FILE__,__LINE__);
	    hitError = true;
	    break;
	  }
	}
      }
      break;
    }

    case POITEM_VEND_ITEM_DESCRIP_COL:
    {
      XLineEdit *lineedit = static_cast<XLineEdit*>(editor);
      if (lineedit->text() != oldval.toString())
	model->setData(index, lineedit->text());
      break;
    }

    case POITEM_VEND_ITEM_NUMBER_COL:
    {
      XLineEdit *lineedit = static_cast<XLineEdit*>(editor);
      if (lineedit->text() != oldval.toString())
	model->setData(index, lineedit->text());
      break;
    }

    case POITEM_FREIGHT_COL:
    {
      XLineEdit *lineedit = static_cast<XLineEdit*>(editor);
      if (lineedit->toDouble() != oldval.toDouble())
	model->setData(index, lineedit->toDouble());
      break;
    }


    case POITEM_QTY_ORDERED_COL:
    {
      XLineEdit *lineedit = static_cast<XLineEdit*>(editor);
      if (lineedit->text().isEmpty())
      {
	model->setData(index, QVariant());
	model->setData(model->index(index.row(), EXTPRICE_COL), QVariant());
	break;
      }
      double qty = lineedit->toDouble();
      if (qty != oldval.toDouble())
      {
	model->setData(index, qty);
	if (model->data(model->index(index.row(), POITEM_QTY_ORDERED_COL)).toDouble() > 0 &&
	  model->data(model->index(index.row(), POITEM_ITEMSRC_ID_COL)).toInt() > 0)
	{
	  PoitemetModelData.prepare( "SELECT ROUND(currToCurr(itemsrcp_curr_id, :curr_id, itemsrcp_price, :effective), :prec) "
		      "AS new_itemsrcp_price "
		     "FROM itemsrcp "
		     "WHERE ( (itemsrcp_itemsrc_id=:itemsrc_id)"
		     " AND (itemsrcp_qtybreak <= :qty) ) "
		     "ORDER BY itemsrcp_qtybreak DESC "
		     "LIMIT 1;" );
	  PoitemetModelData.bindValue(":itemsrc_id", model->data(model->index(index.row(), POITEM_ITEMSRC_ID_COL)).toInt());
	  PoitemetModelData.bindValue(":qty", model->data(model->index(index.row(), POITEM_QTY_ORDERED_COL)).toDouble());
	  PoitemetModelData.bindValue(":curr_id", model->currId());
	  PoitemetModelData.bindValue(":effective", model->transDate().toString());
	  PoitemetModelData.bindValue(":prec", omfgThis->priceVal()->decimals());
	  PoitemetModelData.exec();
	  if (PoitemetModelData.first())
	  {
	    model->setData(model->index(index.row(), POITEM_UNITPRICE_COL), PoitemetModelData.value("new_itemsrcp_price").toDouble());
	  }
      else if (ErrorReporter::error(QtCriticalMsg, 0, tr("Error Retrieving Item Information"),
                                    PoitemetModelData, __FILE__, __LINE__))
      {
        hitError = true;
        break;
      }
	  else
	    model->setData(model->index(index.row(), POITEM_UNITPRICE_COL), 0);
	}

	double prc = model->data(model->index(index.row(), POITEM_UNITPRICE_COL)).toDouble();
	model->setData(model->index(index.row(), EXTPRICE_COL), (qty * prc));
      }
      break;
    }

    case POITEM_UNITPRICE_COL:
    {
      XLineEdit *lineedit = static_cast<XLineEdit*>(editor);
      if (lineedit->text().isEmpty())
      {
	model->setData(index, QVariant());
	model->setData(model->index(index.row(), EXTPRICE_COL), QVariant());
	break;
      }
      double prc = lineedit->text().toDouble();
      if (prc != oldval.toDouble())
      {
	model->setData(index, prc);
	double qty = model->data(model->index(index.row(),POITEM_QTY_ORDERED_COL)).toDouble();
	model->setData(model->index(index.row(), EXTPRICE_COL), (qty * prc));
      }
      break;
    }

    case POITEM_DUEDATE_COL:
    {
      XDateEdit *duedate = static_cast<XDateEdit*>(editor);
      duedate->parseDate();
      if (duedate->date() != oldval.toDate())
      {
        if (DEBUG)
          qDebug("PoitemTableDelegate::setModelData() setting duedate to %s with null %d, valid %d",
                 qPrintable(duedate->date().toString()), duedate->isNull(),
                 duedate->isValid());
	model->setData(index, duedate->date());
      }

      break;
    }

#ifdef QE_NONINVENTORY
    case EXPCAT_CODE_COL:
    {
      ExpenseLineEdit *exp = static_cast<ExpenseLineEdit*>(editor);
      if (exp->id() != oldval.toInt())
      {
	model->setData(model->index(index.row(), POITEM_EXPCAT_ID_COL), exp->id());
	model->setData(index, exp->text());
      }
      break;
    }
#endif

    default:
      break;
  }

  QTableView *view = qobject_cast<QTableView*>(parent());
  if (view)
  {
    if (hitError)
      view->setCurrentIndex(index);
    else if (index.row() >= (model->rowCount() - 1))
    {
      QHeaderView* header = view->horizontalHeader();
      if (header->visualIndex(index.column()) >=
	  (header->count() - header->hiddenSectionCount() - 1))
      {
	model->insertRow(model->rowCount());
      }
    }
  }

  return;
}