summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2020-06-28 09:32:04 +0800
committerꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2020-06-28 09:32:04 +0800
commit5d4ca393157362cb9e82022c1f66c61a66ad9077 (patch)
treeb5f1cf586c3e3d9a3fba45631e80fe543139428c
parent0d2a18b15d45d612f3b9ba92d7b7af23be7d444f (diff)
Catalog updates from fellow C++ catalog
-rw-r--r--catalog.cxx26
-rw-r--r--client.cxx9
-rw-r--r--qicclient/catalog.hxx14
-rw-r--r--qicclient/client.hxx8
-rw-r--r--qicclient/product.hxx1
5 files changed, 37 insertions, 21 deletions
diff --git a/catalog.cxx b/catalog.cxx
index 6ddbe1b..0fe8a20 100644
--- a/catalog.cxx
+++ b/catalog.cxx
@@ -5,6 +5,13 @@
namespace ICClient {
+ Catalog::Catalog(icclient_catalog* catalog, QObject* parent) :
+ QAbstractListModel{parent}
+ {
+ for (size_t i = 0; i < catalog->length; i++)
+ addProduct(Product{catalog->products[i]});
+ }
+
int Catalog::rowCount(QModelIndex const& parent) const
{
Q_UNUSED(parent)
@@ -67,11 +74,22 @@ namespace ICClient {
endInsertRows();
}
- void Catalog::update(icclient_catalog* catalog)
+ void Catalog::update(Catalog* catalog)
{
- if (catalog) {
- for (size_t i = 0; i < catalog->length; i++)
- addProduct(Product{catalog->products[i]});
+ for (int i = 0; i < catalog->rowCount(); i++) {
+ auto index = catalog->index(i, 0);
+ Product product;
+ product.sku = catalog->data(index, Product::SkuRole).toString();
+ product.description = catalog->data(index, Product::DescriptionRole).toString();
+ product.comment = catalog->data(index, Product::CommentRole).toString();
+ product.thumb = catalog->data(index, Product::ThumbRole).toString();
+ product.image = catalog->data(index, Product::ImageRole).toString();
+ product.price = catalog->data(index, Product::PriceRole).toDouble();
+ product.prodGroup = catalog->data(index, Product::ProdGroupRole).toString();
+ product.weight = catalog->data(index, Product::WeightRole).toDouble();
+ product.author = catalog->data(index, Product::AuthorRole).toString();
+ product.crossSell = catalog->data(index, Product::CrossSellRole).toStringList();
+ addProduct(product);
emit updated();
}
}
diff --git a/client.cxx b/client.cxx
index 44fcea6..7f74127 100644
--- a/client.cxx
+++ b/client.cxx
@@ -1,8 +1,9 @@
#include <cstddef>
+#include <memory>
#include <QObject>
#include <icclient/client.h>
#include <icclient/member.h>
-#include "qicclient/product.hxx"
+#include "qicclient/catalog.hxx"
#include "qicclient/client.hxx"
namespace ICClient {
@@ -23,14 +24,14 @@ namespace ICClient {
{
icclient_catalog* catalog = nullptr;
icclient_results(handler, &catalog, prodGroup.toLatin1().constData());
- emit gotResults(catalog);
+ if (catalog) emit gotResults(new Catalog{catalog});
}
void Client::allProducts(size_t (*handler)(void*, size_t, size_t, void*))
{
icclient_catalog* catalog = nullptr;
icclient_allproducts(handler, &catalog);
- emit gotResults(catalog);
+ if (catalog) emit gotResults(new Catalog{catalog});
}
void Client::flyPage(size_t (*handler)(void* contents, size_t size,
@@ -39,7 +40,7 @@ namespace ICClient {
{
icclient_product* product = nullptr;
icclient_flypage(handler, &product, sku.toLatin1().constData());
- if (product) emit gotFlyPage(std::shared_ptr<Product>{new Product{product}});
+ if (product) emit gotFlyPage(shared_ptr<Product>{new Product{product}});
}
void Client::order(icclient_ord_order** orderPtr, QString const& sku
diff --git a/qicclient/catalog.hxx b/qicclient/catalog.hxx
index 317ea91..dfa7a7c 100644
--- a/qicclient/catalog.hxx
+++ b/qicclient/catalog.hxx
@@ -13,17 +13,13 @@ namespace ICClient {
Q_OBJECT
public:
- explicit 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;
+ Catalog(icclient_catalog* catalog, QObject* parent = nullptr);
+ 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;
public slots:
- void update(icclient_catalog* catalog);
+ void update(Catalog* catalog);
signals:
void updated();
diff --git a/qicclient/client.hxx b/qicclient/client.hxx
index b73c6a2..a87f83f 100644
--- a/qicclient/client.hxx
+++ b/qicclient/client.hxx
@@ -1,15 +1,15 @@
#ifndef QICCLIENT_CLIENT_HXX
#define QICCLIENT_CLIENT_HXX
-#include <memory>
#include <QObject>
-struct icclient_catalog;
struct icclient_ord_order;
struct icclient_user;
namespace ICClient {
+ using std::shared_ptr;
+ class Catalog;
class Product;
class Client : public QObject
@@ -70,8 +70,8 @@ namespace ICClient {
*/
signals:
- void gotResults(icclient_catalog* catalog);
- void gotFlyPage(std::shared_ptr<Product> product);
+ void gotResults(Catalog* catalog);
+ void gotFlyPage(shared_ptr<Product> product);
void ordered(icclient_ord_order* order);
void loggedIn(icclient_user* user);
void loggedOut();
diff --git a/qicclient/product.hxx b/qicclient/product.hxx
index 79584c7..ae23459 100644
--- a/qicclient/product.hxx
+++ b/qicclient/product.hxx
@@ -20,6 +20,7 @@ namespace ICClient {
CrossSellRole
};
+ Product() {}
Product(icclient_product* product) :
price{product->price},
weight{product->weight}