diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2023-03-12 10:47:50 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2023-03-12 10:47:50 +0800 |
commit | 82f3e8426f4092831d25a97e05a91ce3663bc3c6 (patch) | |
tree | a57c4f93f447d67a82c2abe60b0dbaa319ebd6ef | |
parent | 4b8ef74da93c6ef4661c77373ea6818397e8d798 (diff) |
Jenis parameter konstruksi Interchange berubah
-rw-r--r-- | interchange.cxx | 5 | ||||
-rw-r--r-- | interchange/ord.hxx | 4 | ||||
-rw-r--r-- | ord.cxx | 19 |
3 files changed, 11 insertions, 17 deletions
diff --git a/interchange.cxx b/interchange.cxx index 4806865..9833b1d 100644 --- a/interchange.cxx +++ b/interchange.cxx @@ -85,13 +85,12 @@ namespace QInterchange { void Interchange::order(QString const& sku, Catalog const& catalog, Ord& order) { - auto c_order = order.data(); + auto data = order.data(); interchange_ord_order(sku.toLatin1().constData(), - catalog.constData(), &c_order, + catalog.constData(), &data, [](interchange_response* response) { interchange->emitOrder(QString{response->data}); interchange_free_response(response); }); - order.setData(c_order); } } diff --git a/interchange/ord.hxx b/interchange/ord.hxx index af06d52..2d18891 100644 --- a/interchange/ord.hxx +++ b/interchange/ord.hxx @@ -33,13 +33,13 @@ namespace QInterchange { Q_PROPERTY(double totalCost READ totalCost NOTIFY totalCostChanged) public: - explicit Ord(QObject* parent = nullptr); + explicit Ord(struct interchange_ord_order* order + = nullptr, 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; } - 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; } @@ -7,7 +7,7 @@ namespace QInterchange { static Ord* ord; - Ord::Ord(QObject* parent) : + Ord::Ord(struct interchange_ord_order *order, QObject* parent) : QAbstractListModel{parent}, m_data{nullptr}, m_subtotal{.0}, @@ -15,6 +15,12 @@ namespace QInterchange { m_totalCost{.0} { 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; + this->m_data = order; } Ord::~Ord() @@ -81,17 +87,6 @@ namespace QInterchange { emit rowCountChanged(); } - void Ord::setData(struct interchange_ord_order* order) - { - if (!order) return; - this->m_data = order; - for (size_t i = 0; i < order->nitems; i++) addItem(Item{order->items[i]}); - m_subtotal = order->subtotal; - emit subtotalChanged(); - m_totalCost = order->total_cost; - emit totalCostChanged(); - } - void Ord::setProfile(QString const& profile) { auto orderProfile = profile.toLatin1().data(); |