diff options
-rw-r--r-- | interchange/ord.hxx | 11 | ||||
-rw-r--r-- | 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<int, QByteArray> roleNames() const Q_DECL_OVERRIDE; + void emitTransaction(QString const& response); + private: void addItem(Item const& item); QList<Item> items; @@ -1,9 +1,22 @@ #include <algorithm> #include <memory> +#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); } } |