From e790f72bdbea00c353709dc5a9920527121eb57c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?=
 =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?=
 =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= <erik@darapsa.co.id>
Date: Thu, 16 Jul 2020 08:19:39 +0800
Subject: Rename basket to ord

---
 CMakeLists.txt       |  6 ++--
 basket.cxx           | 77 --------------------------------------------------
 client.cxx           |  4 +--
 ord.cxx              | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++
 qicclient/basket.hxx | 79 ----------------------------------------------------
 qicclient/client.hxx |  5 ++--
 qicclient/ord.hxx    | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 163 insertions(+), 164 deletions(-)
 delete mode 100644 basket.cxx
 create mode 100644 ord.cxx
 delete mode 100644 qicclient/basket.hxx
 create mode 100644 qicclient/ord.hxx

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a0aa505..2e4741a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,11 +9,11 @@ find_package(Qt5Core)
 add_library(${PROJECT_NAME} SHARED
 	${PROJECT_NAME}/member.hxx
 	${PROJECT_NAME}/catalog.hxx
-	${PROJECT_NAME}/basket.hxx
+	${PROJECT_NAME}/ord.hxx
 	${PROJECT_NAME}/client.hxx
 	member.cxx
 	catalog.cxx
-	basket.cxx
+	ord.cxx
 	client.cxx
 	)
 
@@ -29,7 +29,7 @@ install(FILES
 	${PROJECT_NAME}/member.hxx
 	${PROJECT_NAME}/product.hxx
 	${PROJECT_NAME}/catalog.hxx
-	${PROJECT_NAME}/basket.hxx
+	${PROJECT_NAME}/ord.hxx
 	${PROJECT_NAME}/client.hxx
 	DESTINATION include/${PROJECT_NAME}
 	)
diff --git a/basket.cxx b/basket.cxx
deleted file mode 100644
index ffbecf4..0000000
--- a/basket.cxx
+++ /dev/null
@@ -1,77 +0,0 @@
-#include <algorithm>
-#include <icclient/ord.h>
-#include "qicclient/basket.hxx"
-
-namespace QICClient {
-
-	int Basket::rowCount(QModelIndex const& parent) const
-	{
-		Q_UNUSED(parent)
-		return items.count();
-	}
-
-	QVariant Basket::data(QModelIndex const& index, int role) const
-	{
-		auto row = index.row();
-
-		if (row < 0 || row >= items.count()) return QVariant();
-
-		auto item = items[row];
-		switch (role) {
-			case Product::SkuRole:
-				return item.product.sku;
-			case Product::DescriptionRole:
-				return item.product.description;
-			case Product::PriceRole:
-				return item.product.price;
-			case Item::QuantityRole:
-				return item.quantity;
-			default:
-				return QVariant();
-		}
-	}
-
-	QHash<int, QByteArray> Basket::roleNames() const
-	{
-		return QHash<int, QByteArray>{
-			{Product::SkuRole, "sku"}
-			, {Product::DescriptionRole, "description"}
-			, {Product::PriceRole, "price"}
-			, {Item::QuantityRole, "quantity"}
-		};
-	}
-
-	void Basket::addItem(Item const& item)
-	{
-		auto product = item.product;
-		auto iterator = std::find_if(items.begin(), items.end()
-				, [&product](Item const& item) {
-				return product.sku == item.product.sku;
-				});
-		if (iterator != items.end()) {
-			auto index = items.indexOf(*iterator);
-			beginRemoveRows(QModelIndex(), index, index);
-			items.removeAt(index);
-			endRemoveRows();
-		}
-
-		beginInsertRows(QModelIndex(), rowCount(), rowCount());
-		items << item;
-		endInsertRows();
-		emit rowCountChanged();
-	}
-
-	void Basket::setData(struct icclient_ord_order* order)
-	{
-		if (order) {
-			this->m_data = order;
-			for (size_t i = 0; i < order->nitems; i++)
-				addItem(Item{order->items[i]});
-			m_subtotal = order->subtotal;
-			emit subtotalChanged();
-			m_totalCost = order->total_cost;
-			emit totalCostChanged();
-		}
-	}
-
-}
diff --git a/client.cxx b/client.cxx
index 26d8ad9..edb1c84 100644
--- a/client.cxx
+++ b/client.cxx
@@ -4,7 +4,7 @@
 #include <icclient/client.h>
 #include <icclient/member.h>
 #include "qicclient/catalog.hxx"
-#include "qicclient/basket.hxx"
+#include "qicclient/ord.hxx"
 #include "qicclient/client.hxx"
 
 namespace QICClient {
@@ -42,7 +42,7 @@ namespace QICClient {
 		if (product) emit gotFlyPage(shared_ptr<Product>{new Product{product}});
 	}
 
-	void Client::order(QString const& sku, Catalog const& catalog, Basket& order)
+	void Client::order(QString const& sku, Catalog const& catalog, Ord& order)
 	{
 		auto c_order = order.data();
 		icclient_ord_order(sku.toLatin1().constData(), catalog.constData(),
diff --git a/ord.cxx b/ord.cxx
new file mode 100644
index 0000000..70ef812
--- /dev/null
+++ b/ord.cxx
@@ -0,0 +1,77 @@
+#include <algorithm>
+#include <icclient/ord.h>
+#include "qicclient/ord.hxx"
+
+namespace QICClient {
+
+	int Ord::rowCount(QModelIndex const& parent) const
+	{
+		Q_UNUSED(parent)
+		return items.count();
+	}
+
+	QVariant Ord::data(QModelIndex const& index, int role) const
+	{
+		auto row = index.row();
+
+		if (row < 0 || row >= items.count()) return QVariant();
+
+		auto item = items[row];
+		switch (role) {
+			case Product::SkuRole:
+				return item.product.sku;
+			case Product::DescriptionRole:
+				return item.product.description;
+			case Product::PriceRole:
+				return item.product.price;
+			case Item::QuantityRole:
+				return item.quantity;
+			default:
+				return QVariant();
+		}
+	}
+
+	QHash<int, QByteArray> Ord::roleNames() const
+	{
+		return QHash<int, QByteArray>{
+			{Product::SkuRole, "sku"}
+			, {Product::DescriptionRole, "description"}
+			, {Product::PriceRole, "price"}
+			, {Item::QuantityRole, "quantity"}
+		};
+	}
+
+	void Ord::addItem(Item const& item)
+	{
+		auto product = item.product;
+		auto iterator = std::find_if(items.begin(), items.end()
+				, [&product](Item const& item) {
+				return product.sku == item.product.sku;
+				});
+		if (iterator != items.end()) {
+			auto index = items.indexOf(*iterator);
+			beginRemoveRows(QModelIndex(), index, index);
+			items.removeAt(index);
+			endRemoveRows();
+		}
+
+		beginInsertRows(QModelIndex(), rowCount(), rowCount());
+		items << item;
+		endInsertRows();
+		emit rowCountChanged();
+	}
+
+	void Ord::setData(struct icclient_ord_order* order)
+	{
+		if (order) {
+			this->m_data = order;
+			for (size_t i = 0; i < order->nitems; i++)
+				addItem(Item{order->items[i]});
+			m_subtotal = order->subtotal;
+			emit subtotalChanged();
+			m_totalCost = order->total_cost;
+			emit totalCostChanged();
+		}
+	}
+
+}
diff --git a/qicclient/basket.hxx b/qicclient/basket.hxx
deleted file mode 100644
index 8930821..0000000
--- a/qicclient/basket.hxx
+++ /dev/null
@@ -1,79 +0,0 @@
-#ifndef QICCLIENT_BASKET_HXX
-#define QICCLIENT_BASKET_HXX
-
-#include <QAbstractListModel>
-#include <icclient/ord.h>
-#include "product.hxx"
-
-namespace QICClient {
-
-	struct Item
-	{
-		enum ItemRoles {
-			QuantityRole = Product::PriceRole + 1
-		};
-
-		Item(icclient_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 Basket : 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 Basket(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 icclient_ord_order* data() { return m_data; }
-			void setData(struct icclient_ord_order* order);
-			double subtotal() const { return m_subtotal; }
-			double shipping() const { return m_shipping; }
-			double totalCost() const { return m_totalCost; }
-
-		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 icclient_ord_order* m_data;
-			double m_subtotal;
-			double m_shipping;
-			double m_totalCost;
-	};
-
-}
-
-#endif // QICCLIENT_BASKET_HXX
diff --git a/qicclient/client.hxx b/qicclient/client.hxx
index c554dab..984996c 100644
--- a/qicclient/client.hxx
+++ b/qicclient/client.hxx
@@ -8,7 +8,7 @@ namespace QICClient {
 	using std::shared_ptr;
 	class Catalog;
 	class Product;
-	class Basket;
+	class Ord;
 
 	class Client : public QObject
 	{
@@ -51,8 +51,7 @@ namespace QICClient {
 			 * \param catalog The catalog from which the item is.
 			 * \param order The order.
 			 */
-			void order(QString const& sku, Catalog const& catalog,
-					Basket& order);
+			void order(QString const& sku, Catalog const& catalog, Ord& order);
 
 		public slots:
 			/*
diff --git a/qicclient/ord.hxx b/qicclient/ord.hxx
new file mode 100644
index 0000000..a3be840
--- /dev/null
+++ b/qicclient/ord.hxx
@@ -0,0 +1,79 @@
+#ifndef QICCLIENT_ORD_HXX
+#define QICCLIENT_ORD_HXX
+
+#include <QAbstractListModel>
+#include <icclient/ord.h>
+#include "product.hxx"
+
+namespace QICClient {
+
+	struct Item
+	{
+		enum ItemRoles {
+			QuantityRole = Product::PriceRole + 1
+		};
+
+		Item(icclient_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 icclient_ord_order* data() { return m_data; }
+			void setData(struct icclient_ord_order* order);
+			double subtotal() const { return m_subtotal; }
+			double shipping() const { return m_shipping; }
+			double totalCost() const { return m_totalCost; }
+
+		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 icclient_ord_order* m_data;
+			double m_subtotal;
+			double m_shipping;
+			double m_totalCost;
+	};
+
+}
+
+#endif // QICCLIENT_ORD_HXX
-- 
cgit v1.2.3