summaryrefslogtreecommitdiff
path: root/catalog.cxx
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 /catalog.cxx
parent0d2a18b15d45d612f3b9ba92d7b7af23be7d444f (diff)
Catalog updates from fellow C++ catalog
Diffstat (limited to 'catalog.cxx')
-rw-r--r--catalog.cxx26
1 files changed, 22 insertions, 4 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();
}
}