I've changed the code in addEntry() to:
void CShoppingCartWidget::addEntry(structOrder& order)
{
// debug block
qDebug() << "order.iMerchandizeID=" << order.iMerchandizeID;
qDebug() << "order.iMerchandizeQuantity=" << order.iMerchandizeQuantity;
qDebug() << "order.rMerchandizePrice=" << order.rMerchandizePrice;
qDebug() << "order.rSubtotal=" << order.rSubtotal;
qDebug() << "order.strDisplayString=" << order.strDisplayString;
qDebug() << "order.strMerchandizeName=" << order.strMerchandizeName;
// **** END of debug block
QList<CMerchandizeOrder*> orders=shoppingCartModel()->orders();
//CMerchandizeOrder* tempOrder=new CMerchandizeOrder(order);
//Q_CHECK_PTR(tempOrder);
CMerchandizeOrder tempOrder(order);
/*
tempOrder.iMerchandizeID=order.iMerchandizeID;
tempOrder.iMerchandizeQuantity=order.iMerchandizeQuantity;
tempOrder.rMerchandizePrice=order.rMerchandizePrice;
tempOrder.rSubtotal=order.rSubtotal;
tempOrder.strDisplayString=order.strDisplayString;
tempOrder.strMerchandizeName=order.strMerchandizeName;
*/
if (!orders.contains(&tempOrder))
{
// new merchandize
shoppingCartModel()->setData(index,
tempOrder.orderValues().strDisplayString,
//tempOrder->orderValues().strDisplayString,
Qt::EditRole);
}
else
{
// merchandize exists, update quantity and subtotal
}
}
void CShoppingCartWidget::addEntry(structOrder& order)
{
// debug block
qDebug() << "order.iMerchandizeID=" << order.iMerchandizeID;
qDebug() << "order.iMerchandizeQuantity=" << order.iMerchandizeQuantity;
qDebug() << "order.rMerchandizePrice=" << order.rMerchandizePrice;
qDebug() << "order.rSubtotal=" << order.rSubtotal;
qDebug() << "order.strDisplayString=" << order.strDisplayString;
qDebug() << "order.strMerchandizeName=" << order.strMerchandizeName;
// **** END of debug block
QList<CMerchandizeOrder*> orders=shoppingCartModel()->orders();
//CMerchandizeOrder* tempOrder=new CMerchandizeOrder(order);
//Q_CHECK_PTR(tempOrder);
CMerchandizeOrder tempOrder(order);
/*
tempOrder.iMerchandizeID=order.iMerchandizeID;
tempOrder.iMerchandizeQuantity=order.iMerchandizeQuantity;
tempOrder.rMerchandizePrice=order.rMerchandizePrice;
tempOrder.rSubtotal=order.rSubtotal;
tempOrder.strDisplayString=order.strDisplayString;
tempOrder.strMerchandizeName=order.strMerchandizeName;
*/
if (!orders.contains(&tempOrder))
{
// new merchandize
shoppingCartModel()->insertRows(0, 1, QModelIndex());
QModelIndex index=shoppingCartModel()->index(0, 0, QModelIndex());
shoppingCartModel()->setData(index,
tempOrder.orderValues().strDisplayString,
//tempOrder->orderValues().strDisplayString,
Qt::EditRole);
}
else
{
// merchandize exists, update quantity and subtotal
}
}
To copy to clipboard, switch view to plain text mode
and I get same result.
Bookmarks