From 9d6608227a46e62f81b0bad78f12406ba29819cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Mon, 19 Jun 2023 10:58:31 +0800 Subject: Ord items list now contain pointers to the Items so that it can contain subclasses of Item, since the ones contained are just the pointers. The space reserved for an Item wouldn't be enough for a subclass' additional members. The space reserved for *a pointer to* an Item, on the other hand, should be enough for a later casted pointer to something derived from an Item. --- interchange/ord.hxx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'interchange') diff --git a/interchange/ord.hxx b/interchange/ord.hxx index 302e6db..390d415 100644 --- a/interchange/ord.hxx +++ b/interchange/ord.hxx @@ -48,7 +48,7 @@ namespace QInterchange { Ord() {} explicit Ord(struct interchange_ord_order *order, QObject* parent = nullptr); - ~Ord() {} + virtual ~Ord() { for (auto item : items) delete item; } int rowCount(QModelIndex const& parent = QModelIndex()) const Q_DECL_OVERRIDE; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; @@ -76,13 +76,16 @@ namespace QInterchange { protected: QHash 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 addItem(Item *item); + const Item *itemAt(int row) const + { + return items.at(row); + } void emitUpdate(const QString &response); void emitTransaction(QString const& response); private: - QList items; + QList items; QString profile; double m_subtotal; double m_shipping; -- cgit v1.2.3