summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--catalog.cxx35
m---------libicclient12
-rw-r--r--qicclient.pro1
-rw-r--r--qicclient/catalog.hxx43
-rw-r--r--qicclient/client.hxx1
-rw-r--r--qicclient/product.hxx40
6 files changed, 67 insertions, 65 deletions
diff --git a/catalog.cxx b/catalog.cxx
index 03a90a1..ecc01a0 100644
--- a/catalog.cxx
+++ b/catalog.cxx
@@ -1,3 +1,6 @@
+#include <cstddef>
+#include <icclient/catalog.h>
+#include <icclient/client.h>
#include "qicclient/catalog.hxx"
namespace ICClient {
@@ -16,16 +19,16 @@ namespace ICClient {
auto product = products[row];
switch (role) {
- case SkuRole:
- return product.sku();
- case DescriptionRole:
- return product.description();
- case CommentRole:
- return product.comment();
- case ImageRole:
- return product.image();
- case PriceRole:
- return product.price();
+ case Product::SkuRole:
+ return product.sku;
+ case Product::DescriptionRole:
+ return product.description;
+ case Product::CommentRole:
+ return product.comment;
+ case Product::ImageRole:
+ return product.image;
+ case Product::PriceRole:
+ return product.price;
default:
return QVariant();
}
@@ -34,11 +37,11 @@ namespace ICClient {
QHash<int, QByteArray> Catalog::roleNames() const
{
return QHash<int, QByteArray>{
- {SkuRole, "sku"}
- , {DescriptionRole, "description"}
- , {CommentRole, "comment"}
- , {ImageRole, "image"}
- , {PriceRole, "price"}
+ {Product::SkuRole, "sku"}
+ , {Product::DescriptionRole, "description"}
+ , {Product::CommentRole, "comment"}
+ , {Product::ImageRole, "image"}
+ , {Product::PriceRole, "price"}
};
}
@@ -54,7 +57,7 @@ namespace ICClient {
if (catalog) {
for (size_t i = 0; i < catalog->length; i++)
addProduct(Product{catalog->products[i]});
- icclient_catalog_free(catalog);
+ icclient_freecatalog(catalog);
emit updated();
}
}
diff --git a/libicclient b/libicclient
-Subproject 7c2232c3af7edf93a6caa71ffc969916b4f88c4
+Subproject c2c89d376b0d80299ad0fe8228ecef427955716
diff --git a/qicclient.pro b/qicclient.pro
index 371bd20..623a0b8 100644
--- a/qicclient.pro
+++ b/qicclient.pro
@@ -4,6 +4,7 @@ CONFIG += staticlib
HEADERS += \
qicclient/user.hxx \
+ qicclient/product.hxx \
qicclient/catalog.hxx \
qicclient/client.hxx
SOURCES += \
diff --git a/qicclient/catalog.hxx b/qicclient/catalog.hxx
index 782c864..d539149 100644
--- a/qicclient/catalog.hxx
+++ b/qicclient/catalog.hxx
@@ -2,56 +2,17 @@
#define QICCLIENT_CATALOG_HXX
#include <QAbstractListModel>
-#include <icclient/product.h>
+#include <qicclient/product.hxx>
struct icclient_catalog;
namespace ICClient {
- class Product
- {
- public:
- Product(icclient_product* product) : m_sku{product->sku}
- {
- if (product->description)
- m_description
- = QString{product->description};
- if (product->comment)
- m_comment = QString{product->comment};
- if (product->image)
- m_image = QString{product->image};
- m_price = product->price;
- }
- QString const& sku() const { return m_sku; }
- QString const& description() const
- {
- return m_description;
- }
- QString const& comment() const { return m_comment; }
- QString const& image() const { return m_image; }
- double price() const { return m_price; }
-
- private:
- QString m_sku;
- QString m_description;
- QString m_comment;
- QString m_image;
- double m_price;
- };
-
class Catalog : public QAbstractListModel
{
Q_OBJECT
public:
- enum ProductRoles {
- SkuRole = Qt::UserRole + 1,
- DescriptionRole,
- CommentRole,
- ImageRole,
- PriceRole
- };
-
explicit Catalog(QObject* parent = nullptr)
: QAbstractListModel{parent} {}
@@ -71,8 +32,8 @@ namespace ICClient {
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
private:
- QList<Product> products;
void addProduct(Product const& product);
+ QList<Product> products;
};
}
diff --git a/qicclient/client.hxx b/qicclient/client.hxx
index bccd665..9af124d 100644
--- a/qicclient/client.hxx
+++ b/qicclient/client.hxx
@@ -2,7 +2,6 @@
#define QICCLIENT_CLIENT_HXX
#include <QObject>
-#include <icclient/product.h>
struct icclient_catalog;
struct icclient_order;
diff --git a/qicclient/product.hxx b/qicclient/product.hxx
new file mode 100644
index 0000000..7271fe9
--- /dev/null
+++ b/qicclient/product.hxx
@@ -0,0 +1,40 @@
+#ifndef QICCLIENT_PRODUCT_HXX
+#define QICCLIENT_PRODUCT_HXX
+
+#include <icclient/product.h>
+
+namespace ICClient {
+
+ struct Product
+ {
+ enum ProductRoles {
+ SkuRole = Qt::UserRole + 1,
+ DescriptionRole,
+ CommentRole,
+ ImageRole,
+ PriceRole
+ };
+
+ Product(icclient_product* product)
+ : sku{product->sku}
+ , price{product->price}
+ {
+ if (product->description)
+ description
+ = QString{product->description};
+ if (product->comment)
+ comment = QString{product->comment};
+ if (product->image)
+ image = QString{product->image};
+ }
+
+ QString sku;
+ QString description;
+ QString comment;
+ QString image;
+ double price;
+ };
+
+}
+
+#endif // QICCLIENT_PRODUCT_HXX