40 lines
1.2 KiB
C++
40 lines
1.2 KiB
C++
#include "restsviewmodel.h"
|
|
|
|
#include "services/settingsservice.h"
|
|
|
|
RestsViewModel::RestsViewModel(QObject *parent)
|
|
: QObject{parent}
|
|
{
|
|
connect(m_restsModel, &BaseModel::dataChanged, this, &RestsViewModel::productsChanged);
|
|
connect(m_productsModel, &BaseModel::dataChanged, this, &RestsViewModel::productsChanged);
|
|
connect(settings(), &SettingsService::selectedStoreIdChanged, this, &RestsViewModel::productsChanged);
|
|
}
|
|
|
|
QVariantList RestsViewModel::products() const
|
|
{
|
|
QVariantList res;
|
|
|
|
const QString storeId = settings()->selectedStoreId();
|
|
const QVariantList products = m_productsModel->items();
|
|
for (const QVariant &product : products) {
|
|
QString productId = product.toMap().value("id").toString();
|
|
res << QVariantMap {
|
|
{ "productId", productId },
|
|
{ "title", m_productsModel->itemProperty(productId, "name").toString() },
|
|
{ "rest", m_restsModel->productRest(storeId, productId) }
|
|
};
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
void RestsViewModel::setProductRest(const QString &productId, float rest)
|
|
{
|
|
m_restsModel->submitRest(settings()->selectedStoreId(), productId, rest);
|
|
}
|
|
|
|
SettingsService *RestsViewModel::settings() const
|
|
{
|
|
return SettingsService::instance();
|
|
}
|