From e790f72bdbea00c353709dc5a9920527121eb57c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Thu, 16 Jul 2020 08:19:39 +0800 Subject: Rename basket to ord --- qicclient/basket.hxx | 79 ---------------------------------------------------- qicclient/client.hxx | 5 ++-- qicclient/ord.hxx | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 82 deletions(-) delete mode 100644 qicclient/basket.hxx create mode 100644 qicclient/ord.hxx (limited to 'qicclient') diff --git a/qicclient/basket.hxx b/qicclient/basket.hxx deleted file mode 100644 index 8930821..0000000 --- a/qicclient/basket.hxx +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef QICCLIENT_BASKET_HXX -#define QICCLIENT_BASKET_HXX - -#include -#include -#include "product.hxx" - -namespace QICClient { - - struct Item - { - enum ItemRoles { - QuantityRole = Product::PriceRole + 1 - }; - - Item(icclient_ord_item* item) - : product{item->product} - , quantity{item->quantity} - {} - - Product product; - unsigned int quantity; - - bool operator==(Item const& item) - { - return product.sku == item.product.sku; - } - }; - - class Basket : public QAbstractListModel - { - Q_OBJECT - Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged) - Q_PROPERTY(double subtotal READ subtotal NOTIFY subtotalChanged) - Q_PROPERTY(double shipping READ shipping NOTIFY shippingChanged) - Q_PROPERTY(double totalCost READ totalCost NOTIFY totalCostChanged) - - public: - explicit Basket(QObject* parent = nullptr) : - QAbstractListModel{parent}, - m_data{nullptr}, - 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; - - struct icclient_ord_order* data() { return m_data; } - void setData(struct icclient_ord_order* order); - double subtotal() const { return m_subtotal; } - double shipping() const { return m_shipping; } - double totalCost() const { return m_totalCost; } - - signals: - void rowCountChanged(); - void subtotalChanged(); - void shippingChanged(); - void totalCostChanged(); - - protected: - QHash roleNames() const Q_DECL_OVERRIDE; - - private: - void addItem(Item const& item); - QList items; - struct icclient_ord_order* m_data; - double m_subtotal; - double m_shipping; - double m_totalCost; - }; - -} - -#endif // QICCLIENT_BASKET_HXX diff --git a/qicclient/client.hxx b/qicclient/client.hxx index c554dab..984996c 100644 --- a/qicclient/client.hxx +++ b/qicclient/client.hxx @@ -8,7 +8,7 @@ namespace QICClient { using std::shared_ptr; class Catalog; class Product; - class Basket; + class Ord; class Client : public QObject { @@ -51,8 +51,7 @@ namespace QICClient { * \param catalog The catalog from which the item is. * \param order The order. */ - void order(QString const& sku, Catalog const& catalog, - Basket& order); + void order(QString const& sku, Catalog const& catalog, Ord& order); public slots: /* diff --git a/qicclient/ord.hxx b/qicclient/ord.hxx new file mode 100644 index 0000000..a3be840 --- /dev/null +++ b/qicclient/ord.hxx @@ -0,0 +1,79 @@ +#ifndef QICCLIENT_ORD_HXX +#define QICCLIENT_ORD_HXX + +#include +#include +#include "product.hxx" + +namespace QICClient { + + struct Item + { + enum ItemRoles { + QuantityRole = Product::PriceRole + 1 + }; + + Item(icclient_ord_item* item) + : product{item->product} + , quantity{item->quantity} + {} + + Product product; + unsigned int quantity; + + bool operator==(Item const& item) + { + return product.sku == item.product.sku; + } + }; + + class Ord : public QAbstractListModel + { + Q_OBJECT + Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged) + Q_PROPERTY(double subtotal READ subtotal NOTIFY subtotalChanged) + Q_PROPERTY(double shipping READ shipping NOTIFY shippingChanged) + Q_PROPERTY(double totalCost READ totalCost NOTIFY totalCostChanged) + + public: + explicit Ord(QObject* parent = nullptr) : + QAbstractListModel{parent}, + m_data{nullptr}, + 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; + + struct icclient_ord_order* data() { return m_data; } + void setData(struct icclient_ord_order* order); + double subtotal() const { return m_subtotal; } + double shipping() const { return m_shipping; } + double totalCost() const { return m_totalCost; } + + signals: + void rowCountChanged(); + void subtotalChanged(); + void shippingChanged(); + void totalCostChanged(); + + protected: + QHash roleNames() const Q_DECL_OVERRIDE; + + private: + void addItem(Item const& item); + QList items; + struct icclient_ord_order* m_data; + double m_subtotal; + double m_shipping; + double m_totalCost; + }; + +} + +#endif // QICCLIENT_ORD_HXX -- cgit v1.2.3