Hi to all, especialy nearly divine entities like jacek, jpn, marcel, wysota and others!
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 +
+========================+
+========================+
+ Coca Cola +
+ 1,00 1x 1.00 +
+------------------------+
+ Sprite +
+ 2.44 1x 2.44 +
+========================+
To copy to clipboard, switch view to plain text mode
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 +
+========================+
+========================+
+ Coca Cola +
+ 1,00 1x 1.00 +
+------------------------+
+ Sprite +
+ 2.44 1x 2.44 +
+------------------------+
+ Sprite +
+ 2.44 1x 2.44 +
+========================+
To copy to clipboard, switch view to plain text mode
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 +
+========================+
+========================+
+ Coca Cola +
+ 1,00 1x 1.00 +
+------------------------+
+ Sprite +
+ 2.44 2x 4.88 +
+========================+
To copy to clipboard, switch view to plain text mode
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.iMerchandizeQuantity*updatedOrderStruct.rMerchandizePrice; // updates subtotal
pUpdatedOrder->setMerchandizeQuantity(updatedOrderStruct.iMerchandizeQuantity);
pUpdatedOrder->setSubtotal(updatedOrderStruct.rSubtotal);
pUpdatedOrder->setDisplayString(updatedOrderStruct);
m_pShoppingCartModel->orders().replace(iRememberedIndex, pUpdatedOrder);
shoppingCartModel()->setData(index,
pUpdatedOrder->orderValues().strDisplayString,
Qt::EditRole);
emit dataChanged(index, index);
}
// TODO: update grand total field
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.iMerchandizeQuantity*updatedOrderStruct.rMerchandizePrice; // updates subtotal
pUpdatedOrder->setMerchandizeQuantity(updatedOrderStruct.iMerchandizeQuantity);
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
To copy to clipboard, switch view to plain text mode
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?!
Bookmarks