summaryrefslogtreecommitdiff
path: root/interchange
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2022-09-25 10:55:36 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2022-09-25 10:55:36 +0800
commit18508ea004a66cc30c42c43d14afdc16b2267666 (patch)
tree1171e1d6c8259bb3446b229e298243bb33d47a04 /interchange
parent91bffad1e8afef36eedf51b50a80a7edf6400f7d (diff)
Rename project to qinterchange
Diffstat (limited to 'interchange')
-rw-r--r--interchange/admin.hxx64
-rw-r--r--interchange/catalog.hxx34
-rw-r--r--interchange/member.hxx159
-rw-r--r--interchange/ord.hxx71
-rw-r--r--interchange/product.hxx63
5 files changed, 391 insertions, 0 deletions
diff --git a/interchange/admin.hxx b/interchange/admin.hxx
new file mode 100644
index 0000000..3a800ac
--- /dev/null
+++ b/interchange/admin.hxx
@@ -0,0 +1,64 @@
+#ifndef INTERCHANGE_ADMIN_HXX
+#define INTERCHANGE_ADMIN_HXX
+
+#include <QObject>
+#include <interchange/admin.h>
+
+struct interchange_admin;
+
+namespace Interchange {
+
+ class Admin : public QObject
+ {
+ Q_OBJECT
+ Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged)
+ Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
+ Q_PROPERTY(bool super READ super WRITE setSuper NOTIFY superChanged)
+
+ public:
+ explicit Admin(QObject* parent = nullptr) :
+ QObject{parent},
+ m_userName{""},
+ m_password{""},
+ m_name{""},
+ m_super{false},
+ m_data{nullptr}
+ {}
+ ~Admin() {}
+ QString const& userName() const { return m_userName; }
+ QString const& password() const { return m_password; }
+ QString const& name() const { return m_name; }
+ bool super() { return m_super; }
+
+ void setUserName(QString const& userName);
+ void setPassword(QString const& password);
+ void setName(QString const& name);
+ void setSuper(bool super);
+
+ public slots:
+ void logIn(QString const& username, QString const& password);
+ void newAdmin(QString const& userName, QString const& password, QString const& name, bool super,
+ enum interchange_admin_group group);
+ void newItem(QString const& description, QString const& comment, QString const& price,
+ QString const& imagePath);
+ void logOut();
+
+ signals:
+ void userNameChanged();
+ void passwordChanged();
+ void nameChanged();
+ void superChanged();
+
+ private:
+ QString m_userName;
+ QString m_password;
+ QString m_name;
+ bool m_super;
+ interchange_admin* m_data;
+ inline void setData(interchange_admin* data);
+ };
+
+}
+
+#endif
diff --git a/interchange/catalog.hxx b/interchange/catalog.hxx
new file mode 100644
index 0000000..8946113
--- /dev/null
+++ b/interchange/catalog.hxx
@@ -0,0 +1,34 @@
+#ifndef INTERCHANGE_CATALOG_HXX
+#define INTERCHANGE_CATALOG_HXX
+
+#include <QAbstractListModel>
+#include "product.hxx"
+
+struct interchange_catalog;
+
+namespace Interchange {
+
+ class Catalog : public QAbstractListModel
+ {
+ Q_OBJECT
+
+ public:
+ Catalog(QObject* parent = nullptr) : QAbstractListModel{parent} {}
+ Catalog(struct interchange_catalog* catalog, QObject* parent = nullptr);
+ ~Catalog();
+ int rowCount(QModelIndex const& parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
+ struct interchange_catalog const* constData() const { return m_data; }
+
+ protected:
+ QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
+
+ private:
+ void addProduct(Product const& product);
+ QList<Product> products;
+ struct interchange_catalog* m_data;
+ };
+
+}
+
+#endif
diff --git a/interchange/member.hxx b/interchange/member.hxx
new file mode 100644
index 0000000..d4b1836
--- /dev/null
+++ b/interchange/member.hxx
@@ -0,0 +1,159 @@
+#ifndef INTERCHANGE_MEMBER_HXX
+#define INTERCHANGE_MEMBER_HXX
+
+#include <QObject>
+#include <interchange/member.h>
+
+struct interchange_member;
+
+namespace Interchange {
+
+ class Member : public QObject
+ {
+ Q_OBJECT
+ Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged)
+ Q_PROPERTY(QString userNick READ userNick WRITE setUserNick NOTIFY userNickChanged)
+ Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
+ Q_PROPERTY(QString expiration READ expiration WRITE setExpiration NOTIFY expirationChanged)
+ Q_PROPERTY(QString acl READ acl WRITE setAcl NOTIFY aclChanged)
+ Q_PROPERTY(QString modTime READ modTime WRITE setModTime NOTIFY modTimeChanged)
+ Q_PROPERTY(QString sNickName READ sNickName WRITE setSNickName NOTIFY sNickNameChanged)
+ Q_PROPERTY(QString company READ company WRITE setCompany NOTIFY companyChanged)
+ Q_PROPERTY(QString fName READ fName WRITE setFName NOTIFY fNameChanged)
+ Q_PROPERTY(QString lName READ lName WRITE setLName NOTIFY lNameChanged)
+ Q_PROPERTY(QString address1 READ address1 WRITE setAddress1 NOTIFY address1Changed)
+ Q_PROPERTY(QString address2 READ address2 WRITE setAddress2 NOTIFY address2Changed)
+ Q_PROPERTY(QString address3 READ address3 WRITE setAddress3 NOTIFY address3Changed)
+ Q_PROPERTY(QString city READ city WRITE setCity NOTIFY cityChanged)
+ Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged)
+ Q_PROPERTY(QString zip READ zip WRITE setZip NOTIFY zipChanged)
+ Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY countryChanged)
+ Q_PROPERTY(QString phoneDay READ phoneDay WRITE setPhoneDay NOTIFY phoneDayChanged)
+ Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged)
+
+ public:
+ explicit Member(QObject* parent = nullptr) :
+ QObject{parent},
+ m_userName{""},
+ m_userNick{""},
+ m_password{""},
+ m_expiration{""},
+ m_acl{""},
+ m_modTime{""},
+ m_sNickName{""},
+ m_company{""},
+ m_fName{""},
+ m_lName{""},
+ m_address1{""},
+ m_address2{""},
+ m_address3{""},
+ m_city{""},
+ m_state{""},
+ m_zip{""},
+ m_country{""},
+ m_phoneDay{""},
+ m_email{""},
+ m_data{nullptr}
+ {}
+ ~Member() {}
+
+ QString const& userName() const { return m_userName; }
+ QString const& userNick() const { return m_userNick; }
+ QString const& password() const { return m_password; }
+ QString const& expiration() const { return m_expiration; }
+ QString const& acl() const { return m_acl; }
+ QString const& modTime() const { return m_modTime; }
+ QString const& sNickName() const { return m_sNickName; }
+ QString const& company() const { return m_company; }
+ QString const& fName() const { return m_fName; }
+ QString const& lName() const { return m_lName; }
+ QString const& address1() const { return m_address1; }
+ QString const& address2() const { return m_address2; }
+ QString const& address3() const { return m_address3; }
+ QString const& city() const { return m_city; }
+ QString const& state() const { return m_state; }
+ QString const& zip() const { return m_zip; }
+ QString const& country() const { return m_country; }
+ QString const& phoneDay() const { return m_phoneDay; }
+ QString const& email() const { return m_email; }
+ interchange_member* data() { return m_data; }
+
+ void setUserName(QString const& userName);
+ void setUserNick(QString const& userNick);
+ void setPassword(QString const& password);
+ void setExpiration(QString const& expiration);
+ void setAcl(QString const& acl);
+ void setModTime(QString const& modTime);
+ void setSNickName(QString const& sNickName);
+ void setCompany(QString const& company);
+ void setFName(QString const& fName);
+ void setLName(QString const& lName);
+ void setAddress1(QString const& address1);
+ void setAddress2(QString const& address2);
+ void setAddress3(QString const& address3);
+ void setCity(QString const& city);
+ void setState(QString const& state);
+ void setZip(QString const& zip);
+ void setCountry(QString const& country);
+ void setPhoneDay(QString const& phoneDay);
+ void setEmail(QString const& email);
+
+ public slots:
+ void logIn(QString const& username, QString const& password);
+ void account(QString const& firstName, QString const& lastName,
+ QString const& address1, QString const& address2,
+ QString const& city, QString const& state,
+ QString const& zip, QString const& email,
+ QString const& phoneDay);
+ void changePassword(QString const& passwordOld,
+ QString const& password, QString const& verify);
+ void logOut();
+
+ signals:
+ void userNameChanged();
+ void userNickChanged();
+ void passwordChanged();
+ void expirationChanged();
+ void aclChanged();
+ void modTimeChanged();
+ void sNickNameChanged();
+ void companyChanged();
+ void fNameChanged();
+ void lNameChanged();
+ void address1Changed();
+ void address2Changed();
+ void address3Changed();
+ void cityChanged();
+ void stateChanged();
+ void zipChanged();
+ void countryChanged();
+ void phoneDayChanged();
+ void emailChanged();
+
+ private:
+ QString m_userName;
+ QString m_userNick;
+ QString m_password;
+ QString m_expiration;
+ QString m_acl;
+ QString m_modTime;
+ QString m_sNickName;
+ QString m_company;
+ QString m_fName;
+ QString m_lName;
+ QString m_address1;
+ QString m_address2;
+ QString m_address3;
+ QString m_city;
+ QString m_state;
+ QString m_zip;
+ QString m_country;
+ QString m_phoneDay;
+ QString m_email;
+ interchange_member* m_data;
+ inline void setData(interchange_member* data);
+ };
+
+}
+
+#endif
diff --git a/interchange/ord.hxx b/interchange/ord.hxx
new file mode 100644
index 0000000..afe77cc
--- /dev/null
+++ b/interchange/ord.hxx
@@ -0,0 +1,71 @@
+#ifndef INTERCHANGE_ORD_HXX
+#define INTERCHANGE_ORD_HXX
+
+#include <QAbstractListModel>
+#include <interchange/ord.h>
+#include "member.hxx"
+#include "product.hxx"
+
+namespace Interchange {
+
+ struct Item
+ {
+ enum ItemRoles {
+ QuantityRole = Product::PriceRole + 1
+ };
+ Item(interchange_ord_item* item) :
+ product{item->product},
+ quantity{item->quantity} {}
+ Product product;
+ unsigned int quantity;
+ bool operator==(Item const& item)
+ {
+ return product.sku == item.product.sku;
+ }
+ };
+
+ class Ord : public QAbstractListModel
+ {
+ Q_OBJECT
+ Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged)
+ Q_PROPERTY(double subtotal READ subtotal NOTIFY subtotalChanged)
+ Q_PROPERTY(double shipping READ shipping NOTIFY shippingChanged)
+ Q_PROPERTY(double totalCost READ totalCost NOTIFY totalCostChanged)
+
+ public:
+ explicit Ord(QObject* parent = nullptr) :
+ QAbstractListModel{parent},
+ m_data{nullptr},
+ m_subtotal{.0},
+ m_shipping{.0},
+ m_totalCost{.0} {}
+ int rowCount(QModelIndex const& parent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const
+ Q_DECL_OVERRIDE;
+ struct interchange_ord_order* data() { return m_data; }
+ void setData(struct interchange_ord_order* order);
+ double subtotal() const { return m_subtotal; }
+ double shipping() const { return m_shipping; }
+ double totalCost() const { return m_totalCost; }
+ public slots:
+// void remove(unsigned int const& indices);
+ void checkout(Member& member);
+ signals:
+ void rowCountChanged();
+ void subtotalChanged();
+ void shippingChanged();
+ void totalCostChanged();
+ protected:
+ QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
+ private:
+ void addItem(Item const& item);
+ QList<Item> items;
+ struct interchange_ord_order* m_data;
+ double m_subtotal;
+ double m_shipping;
+ double m_totalCost;
+ };
+
+}
+
+#endif
diff --git a/interchange/product.hxx b/interchange/product.hxx
new file mode 100644
index 0000000..a7f3587
--- /dev/null
+++ b/interchange/product.hxx
@@ -0,0 +1,63 @@
+#ifndef INTERCHANGE_PRODUCT_HXX
+#define INTERCHANGE_PRODUCT_HXX
+
+#include <interchange.h>
+
+namespace Interchange {
+
+ struct Product
+ {
+ enum ProductRoles {
+ SkuRole = Qt::UserRole + 1,
+ DescriptionRole,
+ CommentRole,
+ ThumbRole,
+ ImageRole,
+ PriceRole,
+ ProdGroupRole,
+ WeightRole,
+ AuthorRole,
+ CrossSellRole
+ };
+
+ Product() {}
+ Product(struct interchange_product* product) :
+ price{product->price},
+ weight{product->weight}
+ {
+ if (product->sku)
+ sku = QString{product->sku};
+ if (product->description)
+ description = QString{product->description};
+ if (product->comment)
+ comment = QString{product->comment};
+ if (product->thumb)
+ thumb = QString{product->thumb};
+ if (product->image)
+ image = QString{product->image};
+ if (product->prod_group)
+ prodGroup = QString{product->prod_group};
+ if (product->author)
+ author = QString{product->author};
+ if (product->crosssell) {
+ auto crosssell = product->crosssell;
+ for (size_t i = 0; i < crosssell->length; i++)
+ crossSell << QString{crosssell->skus[i]};
+ }
+ }
+
+ QString sku;
+ QString description;
+ QString comment;
+ QString thumb;
+ QString image;
+ double price;
+ QString prodGroup;
+ double weight;
+ QString author;
+ QStringList crossSell;
+ };
+
+}
+
+#endif