From c8ed6cbb4a3a9051fcc2536fd6e751da7a3264cf 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, 12 Mar 2023 18:57:01 +0800 Subject: Item & Ord are with constructed with copies, not pointers --- interchange/ord.hxx | 14 ++++++-------- ord.cxx | 24 +++++++----------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/interchange/ord.hxx b/interchange/ord.hxx index 56bb7d3..4ec06b4 100644 --- a/interchange/ord.hxx +++ b/interchange/ord.hxx @@ -13,9 +13,9 @@ namespace QInterchange { enum ItemRoles { QuantityRole = Product::PriceRole + 1 }; - Item(interchange_ord_item* item) : - product{item->product}, - quantity{item->quantity} {} + Item(interchange_ord_item item) : + product{item.product}, + quantity{item.quantity} {} Product product; unsigned int quantity; bool operator==(Item const& item) @@ -33,13 +33,12 @@ namespace QInterchange { Q_PROPERTY(double totalCost READ totalCost NOTIFY totalCostChanged) public: - explicit Ord(struct interchange_ord_order* order - = nullptr, QObject* parent = nullptr); - ~Ord(); + explicit Ord(struct interchange_ord_order order, + QObject* parent = nullptr); + ~Ord() {} 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; } double subtotal() const { return m_subtotal; } double shipping() const { return m_shipping; } double totalCost() const { return m_totalCost; } @@ -61,7 +60,6 @@ namespace QInterchange { private: void addItem(Item const& item); QList items; - struct interchange_ord_order* m_data; QString profile; double m_subtotal; double m_shipping; diff --git a/ord.cxx b/ord.cxx index f7e2161..7cf1e52 100644 --- a/ord.cxx +++ b/ord.cxx @@ -8,25 +8,15 @@ namespace QInterchange { static Ord* ord; static char* order_profile; - Ord::Ord(struct interchange_ord_order *order, QObject* parent) : - QAbstractListModel{parent}, - m_data{nullptr}, - m_subtotal{.0}, - m_shipping{.0}, - m_totalCost{.0} + Ord::Ord(struct interchange_ord_order order, QObject* parent) : + QAbstractListModel{parent} { ord = this; - if (!order) return; - for (size_t i = 0; i < order->nitems; i++) - addItem(Item{order->items[i]}); - m_subtotal = order->subtotal; - m_totalCost = order->total_cost; - m_data = order; - } - - Ord::~Ord() - { - if (m_data) interchange_ord_free_order(m_data); + for (size_t i = 0; i < order.nitems; i++) + addItem(Item{order.items[i]}); + m_subtotal = order.subtotal; + m_shipping = order.shipping; + m_totalCost = order.total_cost; } int Ord::rowCount(QModelIndex const& parent) const -- cgit v1.2.3