From 228307e324190e760dc298ef84c3ffb29d4c8237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Mon, 29 Jun 2020 15:38:47 +0800 Subject: C++ instances keep a pointer to the C version --- basket.cxx | 16 +++++----------- catalog.cxx | 4 +++- client.cxx | 10 +++++----- libicclient | 2 +- qicclient/basket.hxx | 5 ++--- qicclient/catalog.hxx | 2 ++ qicclient/client.hxx | 8 +++----- 7 files changed, 21 insertions(+), 26 deletions(-) diff --git a/basket.cxx b/basket.cxx index 52dca83..7b3336a 100644 --- a/basket.cxx +++ b/basket.cxx @@ -1,4 +1,5 @@ #include +#include #include "qicclient/basket.hxx" namespace ICClient { @@ -58,18 +59,11 @@ namespace ICClient { items << item; endInsertRows(); emit rowCountChanged(); - } - void Basket::update(icclient_ord_order* order) - { - if (order) { - for (size_t i = 0; i < order->nitems; i++) - addItem(Item{order->items[i]}); - m_subtotal = order->subtotal; - m_totalCost = order->total_cost; - emit subtotalChanged(); - emit totalCostChanged(); - } + /* + m_subtotal = order->subtotal; + m_totalCost = order->total_cost; + */ } } diff --git a/catalog.cxx b/catalog.cxx index 0fe8a20..61fd0fd 100644 --- a/catalog.cxx +++ b/catalog.cxx @@ -6,6 +6,7 @@ namespace ICClient { Catalog::Catalog(icclient_catalog* catalog, QObject* parent) : + catalog{catalog}, QAbstractListModel{parent} { for (size_t i = 0; i < catalog->length; i++) @@ -90,8 +91,9 @@ namespace ICClient { product.author = catalog->data(index, Product::AuthorRole).toString(); product.crossSell = catalog->data(index, Product::CrossSellRole).toStringList(); addProduct(product); - emit updated(); } + this->catalog = const_cast(catalog->c_catalog()); + emit updated(); } } diff --git a/client.cxx b/client.cxx index 7f74127..5ca3ce6 100644 --- a/client.cxx +++ b/client.cxx @@ -4,6 +4,7 @@ #include #include #include "qicclient/catalog.hxx" +#include "qicclient/basket.hxx" #include "qicclient/client.hxx" namespace ICClient { @@ -43,12 +44,11 @@ namespace ICClient { if (product) emit gotFlyPage(shared_ptr{new Product{product}}); } - void Client::order(icclient_ord_order** orderPtr, QString const& sku - , icclient_catalog* catalog) + void Client::order(QString const& sku, Catalog const& catalog, Basket& order) { - icclient_order(orderPtr, sku.toLatin1().constData(), catalog); - icclient_ord_order* order = *orderPtr; - emit ordered(order); + auto c_order = order.c_order(); + icclient_order(sku.toLatin1().constData(), catalog.c_catalog(), + &c_order); } void Client::logIn(size_t (*handler)(void*, size_t, size_t, void*) diff --git a/libicclient b/libicclient index 3dd44e9..f9ccf11 160000 --- a/libicclient +++ b/libicclient @@ -1 +1 @@ -Subproject commit 3dd44e9bd785d14bd867fa9ca9f17365238578c7 +Subproject commit f9ccf11dab8e7ffef363c774c94c660c144f8efb diff --git a/qicclient/basket.hxx b/qicclient/basket.hxx index 019b165..f5665cd 100644 --- a/qicclient/basket.hxx +++ b/qicclient/basket.hxx @@ -54,9 +54,7 @@ namespace ICClient { double subtotal() const { return m_subtotal; } double shipping() const { return m_shipping; } double totalCost() const { return m_totalCost; } - - public slots: - void update(icclient_ord_order* order); + icclient_ord_order* c_order() { return order; } signals: void rowCountChanged(); @@ -73,6 +71,7 @@ namespace ICClient { double m_subtotal; double m_shipping; double m_totalCost; + icclient_ord_order* order; }; } diff --git a/qicclient/catalog.hxx b/qicclient/catalog.hxx index dfa7a7c..7f1dcfd 100644 --- a/qicclient/catalog.hxx +++ b/qicclient/catalog.hxx @@ -17,6 +17,7 @@ namespace ICClient { Catalog(QObject* parent = nullptr) : QAbstractListModel{parent} {} int rowCount(QModelIndex const& parent = QModelIndex()) const Q_DECL_OVERRIDE; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; + icclient_catalog const* c_catalog() const { return catalog; } public slots: void update(Catalog* catalog); @@ -30,6 +31,7 @@ namespace ICClient { private: void addProduct(Product const& product); QList products; + icclient_catalog* catalog; }; } diff --git a/qicclient/client.hxx b/qicclient/client.hxx index a87f83f..056b3f8 100644 --- a/qicclient/client.hxx +++ b/qicclient/client.hxx @@ -3,7 +3,6 @@ #include -struct icclient_ord_order; struct icclient_user; namespace ICClient { @@ -11,6 +10,7 @@ namespace ICClient { using std::shared_ptr; class Catalog; class Product; + class Basket; class Client : public QObject { @@ -31,9 +31,8 @@ namespace ICClient { size_t size, size_t nmemb, void* userdata), QString const& sku); - void order(icclient_ord_order** orderPtr, - QString const& sku, - icclient_catalog* catalog); + void order(QString const& sku, Catalog const& catalog, + Basket& order); void logIn(size_t (*handler)(void*, size_t, size_t, void*), icclient_user* user, QString const& username, @@ -72,7 +71,6 @@ namespace ICClient { signals: void gotResults(Catalog* catalog); void gotFlyPage(shared_ptr product); - void ordered(icclient_ord_order* order); void loggedIn(icclient_user* user); void loggedOut(); }; -- cgit v1.2.3