From a6cfa494405bef00571ef676ac153c21622946f9 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: Sat, 17 Jun 2023 08:08:58 +0800 Subject: Necessary changes for making Ord & Item derivable Also make use of superclass Product initialisations for Item. --- interchange/ord.hxx | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'interchange') diff --git a/interchange/ord.hxx b/interchange/ord.hxx index 514c480..302e6db 100644 --- a/interchange/ord.hxx +++ b/interchange/ord.hxx @@ -14,12 +14,20 @@ namespace QInterchange { QuantityRole = Product::OptionTypeRole + 1, NameRole }; - Item(interchange_ord_item *item) : - quantity{item->quantity}, - name{item->name} + + Item() {} + Item(interchange_ord_item *item) { - init((struct interchange_product *)item); + init(item); } + + void init(interchange_ord_item *item) + { + Product::init((struct interchange_product *)item); + quantity = item->quantity; + name = QString{item->name}; + } + unsigned int quantity; QString name; bool operator==(Item const& item) @@ -37,6 +45,7 @@ namespace QInterchange { Q_PROPERTY(double totalCost READ totalCost NOTIFY totalCostChanged) public: + Ord() {} explicit Ord(struct interchange_ord_order *order, QObject* parent = nullptr); ~Ord() {} @@ -66,11 +75,13 @@ namespace QInterchange { protected: QHash roleNames() const Q_DECL_OVERRIDE; + void init(struct interchange_ord_order *order); + void addItem(Item const &item); + const Item &itemAt(int row) const { return items[row]; } void emitUpdate(const QString &response); void emitTransaction(QString const& response); private: - void addItem(Item const& item); QList items; QString profile; double m_subtotal; -- cgit v1.2.3