MarkoSan
28th May 2008, 21:16
Hi to all, especialy nearly divine entities like jacek, jpn, marcel, wysota and others! :D:D
So, like I said, I have a shopping cart of merchandize in QTableView. Record are now added as they should, but I bumped into following problem. Let's say the shopping cart contains:
+========================+
+ Coca Cola +
+ 1,00 1x 1.00 +
+------------------------+
+ Sprite +
+ 2.44 1x 2.44 +
+========================+Now, the user chooses another sprite and instead of:
+========================+
+ Coca Cola +
+ 1,00 1x 1.00 +
+------------------------+
+ Sprite +
+ 2.44 1x 2.44 +
+------------------------+
+ Sprite +
+ 2.44 1x 2.44 +
+========================+ I would like updated quantity and subtotal (second line, second number is quantity, third number is subtotal) like this:
+========================+
+ Coca Cola +
+ 1,00 1x 1.00 +
+------------------------+
+ Sprite +
+ 2.44 2x 4.88 +
+========================+Now, here is a code chunck that should do this:
else
{
// merchandize found, update quantity and subtotal
qDebug() << "iRemberedMerchandizeID:" << iRemberedMerchandizeID; // debug output
CMerchandizeOrder* pUpdatedOrder=new CMerchandizeOrder(order); // gets order to update
Q_CHECK_PTR(pUpdatedOrder); // checks creation
structOrder updatedOrderStruct=pUpdatedOrder->orderValues(); // gets order's struct
updatedOrderStruct.iMerchandizeQuantity++; // increase quantity
updatedOrderStruct.rSubtotal=updatedOrderStruct.iM erchandizeQuantity*updatedOrderStruct.rMerchandize Price; // updates subtotal
pUpdatedOrder->setMerchandizeQuantity(updatedOrderStruct.iMerchan dizeQuantity);
pUpdatedOrder->setSubtotal(updatedOrderStruct.rSubtotal);
pUpdatedOrder->setDisplayString(updatedOrderStruct);
m_pShoppingCartModel->orders().replace(iRememberedIndex, pUpdatedOrder);
QModelIndex index=shoppingCartModel()->index(0, 0, QModelIndex());
shoppingCartModel()->setData(index,
pUpdatedOrder->orderValues().strDisplayString,
Qt::EditRole);
emit dataChanged(index, index);
}
// TODO: update grand total field but the cell is not updated, i.e., nothing happens. The code is a part of bigger if clause, and I've set breakpoint in the begining of this code chunk to check if the IF clause works ok. It does. I've checked with debugger, data are recalculated correctly (quantity and subtotal), but the contenst of QTableView are not updatet. Why?!
So, like I said, I have a shopping cart of merchandize in QTableView. Record are now added as they should, but I bumped into following problem. Let's say the shopping cart contains:
+========================+
+ Coca Cola +
+ 1,00 1x 1.00 +
+------------------------+
+ Sprite +
+ 2.44 1x 2.44 +
+========================+Now, the user chooses another sprite and instead of:
+========================+
+ Coca Cola +
+ 1,00 1x 1.00 +
+------------------------+
+ Sprite +
+ 2.44 1x 2.44 +
+------------------------+
+ Sprite +
+ 2.44 1x 2.44 +
+========================+ I would like updated quantity and subtotal (second line, second number is quantity, third number is subtotal) like this:
+========================+
+ Coca Cola +
+ 1,00 1x 1.00 +
+------------------------+
+ Sprite +
+ 2.44 2x 4.88 +
+========================+Now, here is a code chunck that should do this:
else
{
// merchandize found, update quantity and subtotal
qDebug() << "iRemberedMerchandizeID:" << iRemberedMerchandizeID; // debug output
CMerchandizeOrder* pUpdatedOrder=new CMerchandizeOrder(order); // gets order to update
Q_CHECK_PTR(pUpdatedOrder); // checks creation
structOrder updatedOrderStruct=pUpdatedOrder->orderValues(); // gets order's struct
updatedOrderStruct.iMerchandizeQuantity++; // increase quantity
updatedOrderStruct.rSubtotal=updatedOrderStruct.iM erchandizeQuantity*updatedOrderStruct.rMerchandize Price; // updates subtotal
pUpdatedOrder->setMerchandizeQuantity(updatedOrderStruct.iMerchan dizeQuantity);
pUpdatedOrder->setSubtotal(updatedOrderStruct.rSubtotal);
pUpdatedOrder->setDisplayString(updatedOrderStruct);
m_pShoppingCartModel->orders().replace(iRememberedIndex, pUpdatedOrder);
QModelIndex index=shoppingCartModel()->index(0, 0, QModelIndex());
shoppingCartModel()->setData(index,
pUpdatedOrder->orderValues().strDisplayString,
Qt::EditRole);
emit dataChanged(index, index);
}
// TODO: update grand total field but the cell is not updated, i.e., nothing happens. The code is a part of bigger if clause, and I've set breakpoint in the begining of this code chunk to check if the IF clause works ok. It does. I've checked with debugger, data are recalculated correctly (quantity and subtotal), but the contenst of QTableView are not updatet. Why?!