Added seller interface for preparing shop items from other plugins.

master
Josef Rokos 8 years ago
parent 1e785fd488
commit 397ec82d06

@ -35,3 +35,8 @@ ShopItemPtr CommodityService::shopItem(int itemId)
CommodityDataPtr item = this->loadById(itemId);
return qSharedPointerDynamicCast<ShopItem, CommodityData>(item);
}
ISeller *CommodityService::seller()
{
return NULL;
}

@ -15,7 +15,7 @@ public:
QList<ShopItemPtr> shopItems() override;
void addedToVoucher(int itemId, int countAdded) override;
virtual ShopItemPtr shopItem(int itemId) override;
ISeller *seller() override;
};
#endif // COMMODITYSERVICE_H

@ -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

@ -0,0 +1,9 @@
#include "iseller.h"
ISeller::ISeller(QObject *parent) : QObject(parent)
{
}
ISeller::~ISeller()
{
}

@ -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

@ -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)

@ -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();

Loading…
Cancel
Save