diff options
-rw-r--r-- | interchange/ord.hxx | 21 | ||||
-rw-r--r-- | ord.cxx | 7 |
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; @@ -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; |