| 1234567891011121314151617181920212223242526272829303132333435363738 |
- #include "restsviewmodel.h"
- #include "services/settingsservice.h"
- RestsViewModel::RestsViewModel(QObject *parent)
- : QObject{parent}
- {
- 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();
- }
|