Models registry was added
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
#include "productsviewmodel.h"
|
||||
|
||||
#include "models/basemodel.h"
|
||||
#include "services/settingsservice.h"
|
||||
#include "models/ordersmodel.h"
|
||||
|
||||
ProductsViewModel::ProductsViewModel(QObject *parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
connect(&m_productsModel, &BaseModel::dataChanged, this, &ProductsViewModel::productsChanged);
|
||||
connect(m_productsModel, &BaseModel::dataChanged, this, &ProductsViewModel::productsChanged);
|
||||
}
|
||||
|
||||
QVariantList ProductsViewModel::products() const
|
||||
{
|
||||
return m_productsModel.items();
|
||||
return m_productsModel->items();
|
||||
}
|
||||
|
||||
QVariantList ProductsViewModel::order() const
|
||||
@@ -19,7 +19,7 @@ QVariantList ProductsViewModel::order() const
|
||||
QVariantList res;
|
||||
|
||||
for (auto it = m_order.constBegin(); it != m_order.constEnd(); ++it) {
|
||||
QVariantMap product = m_productsModel.item(it.key());
|
||||
QVariantMap product = m_productsModel->item(it.key());
|
||||
product["count"] = it.value().toMap().value("quantity").toDouble();
|
||||
res << product;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ float ProductsViewModel::orderSum() const
|
||||
float res = 0.0;
|
||||
|
||||
for (auto it = m_order.constBegin(); it != m_order.constEnd(); ++it) {
|
||||
QVariantMap product = m_productsModel.item(it.key());
|
||||
QVariantMap product = m_productsModel->item(it.key());
|
||||
float price = product.value("price", 0.0).toFloat();
|
||||
float quantity = it.value().toMap().value("quantity").toDouble();
|
||||
res += quantity * price;
|
||||
@@ -44,7 +44,7 @@ float ProductsViewModel::orderSum() const
|
||||
void ProductsViewModel::setOrderValue(const QString &productId, float value)
|
||||
{
|
||||
if (value) {
|
||||
float price = m_productsModel.itemProperty(productId, "price", 0.0).toFloat();
|
||||
float price = m_productsModel->itemProperty(productId, "price", 0.0).toFloat();
|
||||
m_order[productId] = QVariantMap {
|
||||
{ "productId", productId },
|
||||
{ "quantity", value},
|
||||
@@ -59,8 +59,8 @@ void ProductsViewModel::setOrderValue(const QString &productId, float value)
|
||||
|
||||
void ProductsViewModel::submitOrder()
|
||||
{
|
||||
OrdersModel model;
|
||||
model.submitOrder(QVariantMap {
|
||||
BaseModel *ordersModel = ModelsRegister::model("orders");
|
||||
ordersModel->addItem({
|
||||
{ "userId", settings()->selectedUserId() },
|
||||
{ "storeId", settings()->selectedStoreId() },
|
||||
{ "products", m_order.values() },
|
||||
|
||||
Reference in New Issue
Block a user