diff options
-rw-r--r-- | basket.cxx | 18 | ||||
-rw-r--r-- | qicclient/basket.hxx | 5 |
2 files changed, 16 insertions, 7 deletions
@@ -47,13 +47,17 @@ namespace ICClient { , [&product](Item const& item) { return product.sku == item.product.sku; }); - if (iterator == items.end()) { - beginInsertRows(QModelIndex(), rowCount(), rowCount()); - items << item; - endInsertRows(); - emit rowCountChanged(); - } else - iterator->quantity++; + if (iterator != items.end()) { + auto index = items.indexOf(*iterator); + beginRemoveRows(QModelIndex(), index, index); + items.removeAt(index); + endRemoveRows(); + } + + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + items << item; + endInsertRows(); + emit rowCountChanged(); } void Basket::update(icclient_ord_order* order) diff --git a/qicclient/basket.hxx b/qicclient/basket.hxx index b3b5e11..7b3de2a 100644 --- a/qicclient/basket.hxx +++ b/qicclient/basket.hxx @@ -22,6 +22,11 @@ namespace ICClient { Product product; unsigned int quantity; + + bool operator==(Item const& item) + { + return product.sku == item.product.sku; + } }; class Basket : public QAbstractListModel |