summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-06-17 08:08:58 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-06-17 08:08:58 +0800
commita6cfa494405bef00571ef676ac153c21622946f9 (patch)
tree8e6982254b9c425c6d3ad7d7ec6852aafdd39555
parentb93bcd224f57458fb9e2c309db0aa26ca55c37df (diff)
Necessary changes for making Ord & Item derivable
Also make use of superclass Product initialisations for Item.
-rw-r--r--interchange/ord.hxx21
-rw-r--r--ord.cxx7
2 files changed, 22 insertions, 6 deletions
diff --git a/interchange/ord.hxx b/interchange/ord.hxx
index 514c480..302e6db 100644
--- a/interchange/ord.hxx
+++ b/interchange/ord.hxx
@@ -14,12 +14,20 @@ namespace QInterchange {
QuantityRole = Product::OptionTypeRole + 1,
NameRole
};
- Item(interchange_ord_item *item) :
- quantity{item->quantity},
- name{item->name}
+
+ Item() {}
+ Item(interchange_ord_item *item)
{
- init((struct interchange_product *)item);
+ init(item);
}
+
+ void init(interchange_ord_item *item)
+ {
+ Product::init((struct interchange_product *)item);
+ quantity = item->quantity;
+ name = QString{item->name};
+ }
+
unsigned int quantity;
QString name;
bool operator==(Item const& item)
@@ -37,6 +45,7 @@ namespace QInterchange {
Q_PROPERTY(double totalCost READ totalCost NOTIFY totalCostChanged)
public:
+ Ord() {}
explicit Ord(struct interchange_ord_order *order,
QObject* parent = nullptr);
~Ord() {}
@@ -66,11 +75,13 @@ namespace QInterchange {
protected:
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
+ void init(struct interchange_ord_order *order);
+ void addItem(Item const &item);
+ const Item &itemAt(int row) const { return items[row]; }
void emitUpdate(const QString &response);
void emitTransaction(QString const& response);
private:
- void addItem(Item const& item);
QList<Item> items;
QString profile;
double m_subtotal;
diff --git a/ord.cxx b/ord.cxx
index 9dfd846..8472361 100644
--- a/ord.cxx
+++ b/ord.cxx
@@ -12,9 +12,14 @@ namespace QInterchange {
Ord::Ord(struct interchange_ord_order *order, QObject *parent) :
QAbstractListModel{parent}
{
- ord = this;
+ init(order);
for (size_t i = 0; i < order->nitems; i++)
addItem(Item{&order->items[i]});
+ }
+
+ void Ord::init(struct interchange_ord_order *order)
+ {
+ ord = this;
m_subtotal = order->subtotal;
m_shipping = order->shipping;
m_totalCost = order->total_cost;