From 18508ea004a66cc30c42c43d14afdc16b2267666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Sun, 25 Sep 2022 10:55:36 +0800 Subject: Rename project to qinterchange --- interchange/ord.hxx | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 interchange/ord.hxx (limited to 'interchange/ord.hxx') diff --git a/interchange/ord.hxx b/interchange/ord.hxx new file mode 100644 index 0000000..afe77cc --- /dev/null +++ b/interchange/ord.hxx @@ -0,0 +1,71 @@ +#ifndef INTERCHANGE_ORD_HXX +#define INTERCHANGE_ORD_HXX + +#include +#include +#include "member.hxx" +#include "product.hxx" + +namespace Interchange { + + struct Item + { + enum ItemRoles { + QuantityRole = Product::PriceRole + 1 + }; + Item(interchange_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 interchange_ord_order* data() { return m_data; } + void setData(struct interchange_ord_order* order); + double subtotal() const { return m_subtotal; } + double shipping() const { return m_shipping; } + double totalCost() const { return m_totalCost; } + public slots: +// void remove(unsigned int const& indices); + void checkout(Member& member); + 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 interchange_ord_order* m_data; + double m_subtotal; + double m_shipping; + double m_totalCost; + }; + +} + +#endif -- cgit v1.2.3