From 397ec82d060853f89393192e65501b07447adfeb Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Wed, 31 May 2017 16:11:15 +0200 Subject: [PATCH] Added seller interface for preparing shop items from other plugins. --- commodity/commodityservice.cpp | 5 +++++ commodity/commodityservice.h | 2 +- shop/isellableservice.h | 2 ++ shop/iseller.cpp | 9 +++++++++ shop/iseller.h | 22 ++++++++++++++++++++++ shop/shop.pro | 6 ++++-- shop/shopform.cpp | 30 +++++++++++++++++++++++++----- 7 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 shop/iseller.cpp create mode 100644 shop/iseller.h diff --git a/commodity/commodityservice.cpp b/commodity/commodityservice.cpp index 941292d..507d6db 100644 --- a/commodity/commodityservice.cpp +++ b/commodity/commodityservice.cpp @@ -35,3 +35,8 @@ ShopItemPtr CommodityService::shopItem(int itemId) CommodityDataPtr item = this->loadById(itemId); return qSharedPointerDynamicCast(item); } + +ISeller *CommodityService::seller() +{ + return NULL; +} diff --git a/commodity/commodityservice.h b/commodity/commodityservice.h index 0e10d97..028e98b 100644 --- a/commodity/commodityservice.h +++ b/commodity/commodityservice.h @@ -15,7 +15,7 @@ public: QList shopItems() override; void addedToVoucher(int itemId, int countAdded) override; virtual ShopItemPtr shopItem(int itemId) override; - + ISeller *seller() override; }; #endif // COMMODITYSERVICE_H diff --git a/shop/isellableservice.h b/shop/isellableservice.h index f1b3020..1125009 100644 --- a/shop/isellableservice.h +++ b/shop/isellableservice.h @@ -3,6 +3,7 @@ #include "shop_global.h" #include "shopitem.h" +#include "iseller.h" #include #include @@ -14,6 +15,7 @@ public: virtual QList shopItems() = 0; virtual ShopItemPtr shopItem(int itemId) = 0; virtual void addedToVoucher(int itemId, int countAdded) = 0; + virtual ISeller *seller() = 0; }; #endif // ISELLABLESERVICE_H diff --git a/shop/iseller.cpp b/shop/iseller.cpp new file mode 100644 index 0000000..6d75caa --- /dev/null +++ b/shop/iseller.cpp @@ -0,0 +1,9 @@ +#include "iseller.h" + +ISeller::ISeller(QObject *parent) : QObject(parent) +{ +} + +ISeller::~ISeller() +{ +} diff --git a/shop/iseller.h b/shop/iseller.h new file mode 100644 index 0000000..de3aa59 --- /dev/null +++ b/shop/iseller.h @@ -0,0 +1,22 @@ +#ifndef ISELLER_H +#define ISELLER_H + +#include + +#include "ishopitem.h" +#include "shop_global.h" + +class SHOPSHARED_EXPORT ISeller : public QObject +{ + Q_OBJECT +public: + explicit ISeller(QObject *parent = 0); + virtual ~ISeller(); + + virtual void prepareItem() = 0; + +signals: + void itemPrepared(QSharedPointer item, int count); +}; + +#endif // ISELLER_H diff --git a/shop/shop.pro b/shop/shop.pro index 84869c4..99f3424 100644 --- a/shop/shop.pro +++ b/shop/shop.pro @@ -31,7 +31,8 @@ SOURCES += shop.cpp \ shopitem.cpp \ isellableservice.cpp \ data/favorititem.cpp \ - eetbatchdialog.cpp + eetbatchdialog.cpp \ + iseller.cpp HEADERS += shop.h\ shop_global.h \ @@ -55,7 +56,8 @@ HEADERS += shop.h\ shopitem.h \ data/favorititem.h \ eetbatchdialog.h \ - favbutton.h + favbutton.h \ + iseller.h include(../config_plugin.pri) diff --git a/shop/shopform.cpp b/shop/shopform.cpp index cee9a9c..ac7be7e 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -370,11 +370,31 @@ void ShopForm::addItem(QSharedPointer item, int count) createVoucher(); } - ShopService srv; - srv.addShopItem(m_voucher, item, count); - this->m_itemsModel->addRow(m_voucher->items()[m_voucher->items().count() - 1]); - connect(m_voucher->items()[m_voucher->items().count() - 1].data(), SIGNAL(countChanged(int)), this, SLOT(onCountChanged(int))); - onCountChanged(); + IPlugin *plugin = Context::instance().plugin(item->pluginId()); + IService *service = (plugin != NULL ? plugin->service() : NULL); + ISellableService *selSrv = dynamic_cast(service); + + auto addFunc = [this](QSharedPointer shopItem, int itemCount){ + ShopService srv; + srv.addShopItem(m_voucher, shopItem, itemCount); + this->m_itemsModel->addRow(m_voucher->items()[m_voucher->items().count() - 1]); + connect(m_voucher->items()[m_voucher->items().count() - 1].data(), SIGNAL(countChanged(int)), this, SLOT(onCountChanged(int))); + onCountChanged(); + }; + + if (selSrv != NULL && selSrv->seller() != NULL) + { + ISeller *seller = selSrv->seller(); + + seller->disconnect(); + connect(seller, &ISeller::itemPrepared, addFunc); + + seller->prepareItem(); + } + else + { + addFunc(item, count); + } ui->actualReceipt->scrollToBottom(); ui->commoditySearch->setFocus();