diff options
| author | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-10-07 10:19:35 +0800 |
|---|---|---|
| committer | ꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id> | 2019-10-07 10:19:35 +0800 |
| commit | a68fc492cf86a14cf9cf95d9f9a764cdf5b01007 (patch) | |
| tree | 3f309d8be302266d4590862112549bc310cb79f0 /qicclient/basket.hxx | |
| parent | d82340151ce274930f42701f5a9a0c4db702cba4 (diff) | |
| parent | 9fef837e6275697f4562f60c2546c5e025ec5435 (diff) | |
Merge branch 'master' into cmake
# Conflicts:
# qicclient.pro
Diffstat (limited to 'qicclient/basket.hxx')
| -rw-r--r-- | qicclient/basket.hxx | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/qicclient/basket.hxx b/qicclient/basket.hxx new file mode 100644 index 0000000..b3b5e11 --- /dev/null +++ b/qicclient/basket.hxx @@ -0,0 +1,76 @@ +#ifndef QICCLIENT_BASKET_HXX +#define QICCLIENT_BASKET_HXX + +#include <QAbstractListModel> +#include <icclient/ord.h> +#include "product.hxx" + +struct icclient_ord_order; + +namespace ICClient { + + struct Item + { + enum ItemRoles { + QuantityRole = Product::PriceRole + 1 + }; + + Item(icclient_ord_item* item) + : product{item->product} + , quantity{item->quantity} + {} + + Product product; + unsigned int quantity; + }; + + class Basket : public QAbstractListModel + { + Q_OBJECT + Q_PROPERTY(double subtotal READ subtotal NOTIFY subtotalChanged) + Q_PROPERTY(double shipping READ shipping NOTIFY shippingChanged) + Q_PROPERTY(double totalCost READ totalCost NOTIFY totalCostChanged) + Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged) + + public: + explicit Basket(QObject* parent = nullptr) + : QAbstractListModel{parent} + , m_subtotal{.0} + , m_shipping{.0} + , m_totalCost{.0} + {} + + int rowCount(QModelIndex const& parent + = QModelIndex()) const Q_DECL_OVERRIDE; + QVariant data(const QModelIndex& index + , int role = Qt::DisplayRole + ) const Q_DECL_OVERRIDE; + + double subtotal() const { return m_subtotal; } + double shipping() const { return m_shipping; } + double totalCost() const { return m_totalCost; } + + public slots: + void update(icclient_ord_order* order); + + protected: + QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE; + + signals: + void updated(); + void subtotalChanged(); + void shippingChanged(); + void totalCostChanged(); + void rowCountChanged(); + + private: + void addItem(Item const& item); + QList<Item> items; + double m_subtotal; + double m_shipping; + double m_totalCost; + }; + +} + +#endif // QICCLIENT_BASKET_HXX |