diff options
-rw-r--r-- | catalog.cxx | 26 | ||||
-rw-r--r-- | client.cxx | 9 | ||||
-rw-r--r-- | qicclient/catalog.hxx | 14 | ||||
-rw-r--r-- | qicclient/client.hxx | 8 | ||||
-rw-r--r-- | qicclient/product.hxx | 1 |
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(); } } @@ -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} |