From 2fbcfe27235a0852dce3d0ace748c639495d6092 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: Tue, 7 Feb 2023 15:32:40 +0800 Subject: Send signal carrying possible transaction info --- interchange/ord.hxx | 11 +++++------ ord.cxx | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/interchange/ord.hxx b/interchange/ord.hxx index 39f3282..f424d4d 100644 --- a/interchange/ord.hxx +++ b/interchange/ord.hxx @@ -33,12 +33,7 @@ namespace QInterchange { 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} {} + explicit Ord(QObject* parent = nullptr); ~Ord() { if (m_data) interchange_ord_free(m_data); @@ -60,8 +55,12 @@ namespace QInterchange { void subtotalChanged(); void shippingChanged(); void totalCostChanged(); + void gotTransaction(QString const& response); + protected: QHash roleNames() const Q_DECL_OVERRIDE; + void emitTransaction(QString const& response); + private: void addItem(Item const& item); QList items; diff --git a/ord.cxx b/ord.cxx index 35b496c..4b3577b 100644 --- a/ord.cxx +++ b/ord.cxx @@ -1,9 +1,22 @@ #include #include +#include "interchange.hxx" #include "interchange/ord.hxx" namespace QInterchange { + static Ord* ord; + + Ord::Ord(QObject* parent) : + QAbstractListModel{parent}, + m_data{nullptr}, + m_subtotal{.0}, + m_shipping{.0}, + m_totalCost{.0} + { + ord = this; + } + int Ord::rowCount(QModelIndex const& parent) const { Q_UNUSED(parent) @@ -81,6 +94,15 @@ namespace QInterchange { void Ord::checkout(Member& member) { - interchange_ord_checkout(m_data, member.data()); + interchange_ord_checkout(m_data, member.data(), + [](interchange_response* response) { + ord->emitTransaction(QString{response->data}); + interchange_free_response(response); + }); + } + + void Ord::emitTransaction(QString const& response) + { + emit gotTransaction(response); } } -- cgit v1.2.3