Added seller interface for preparing shop items from other plugins.

This commit is contained in:
2017-05-31 16:11:15 +02:00
parent 1e785fd488
commit 397ec82d06
7 changed files with 68 additions and 8 deletions
+2
View File
@@ -3,6 +3,7 @@
#include "shop_global.h"
#include "shopitem.h"
#include "iseller.h"
#include <QList>
#include <QSharedPointer>
@@ -14,6 +15,7 @@ public:
virtual QList<ShopItemPtr> shopItems() = 0;
virtual ShopItemPtr shopItem(int itemId) = 0;
virtual void addedToVoucher(int itemId, int countAdded) = 0;
virtual ISeller *seller() = 0;
};
#endif // ISELLABLESERVICE_H
+9
View File
@@ -0,0 +1,9 @@
#include "iseller.h"
ISeller::ISeller(QObject *parent) : QObject(parent)
{
}
ISeller::~ISeller()
{
}
+22
View File
@@ -0,0 +1,22 @@
#ifndef ISELLER_H
#define ISELLER_H
#include <QObject>
#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<IShopItem> item, int count);
};
#endif // ISELLER_H
+4 -2
View File
@@ -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)
+25 -5
View File
@@ -370,11 +370,31 @@ void ShopForm::addItem(QSharedPointer<IShopItem> 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<IService>() : NULL);
ISellableService *selSrv = dynamic_cast<ISellableService*>(service);
auto addFunc = [this](QSharedPointer<IShopItem> 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();