summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-03-13 08:32:29 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2023-03-13 08:32:29 +0800
commit3bb1e0c14ac7adccadfb71aba33cf2fb54e91850 (patch)
tree5d8279df601e41577921f791c89059cde9dbdd5d
parentc8ed6cbb4a3a9051fcc2536fd6e751da7a3264cf (diff)
Catalog constructor takes a copy of the C struct
-rw-r--r--catalog.cxx13
-rw-r--r--interchange/catalog.hxx7
2 files changed, 7 insertions, 13 deletions
diff --git a/catalog.cxx b/catalog.cxx
index 164811f..bb1f4dd 100644
--- a/catalog.cxx
+++ b/catalog.cxx
@@ -3,16 +3,11 @@
namespace QInterchange {
- Catalog::Catalog(struct interchange_catalog* catalog, QObject* parent) :
- QAbstractListModel{parent},
- m_data{catalog}
+ Catalog::Catalog(struct interchange_catalog catalog, QObject* parent) :
+ QAbstractListModel{parent}
{
- for (size_t i = 0; i < catalog->length; i++) addProduct(Product{catalog->products[i]});
- }
-
- Catalog::~Catalog()
- {
- interchange_free_catalog(m_data);
+ for (size_t i = 0; i < catalog.length; i++)
+ addProduct(Product{catalog.products[i]});
}
int Catalog::rowCount(QModelIndex const& parent) const
diff --git a/interchange/catalog.hxx b/interchange/catalog.hxx
index 9e96a3e..115c30a 100644
--- a/interchange/catalog.hxx
+++ b/interchange/catalog.hxx
@@ -14,11 +14,11 @@ namespace QInterchange {
public:
Catalog(QObject* parent = nullptr) : QAbstractListModel{parent} {}
- Catalog(struct interchange_catalog* catalog, QObject* parent = nullptr);
- ~Catalog();
+ 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; }
void addProduct(Product const& product);
protected:
@@ -26,7 +26,6 @@ namespace QInterchange {
private:
QList<Product> products;
- struct interchange_catalog* m_data;
};
}