Implemented base functionality for commodity grid on shop form.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "commodityform.h"
|
||||
#include "commoditygrid.h"
|
||||
#include "commoditysettingsform.h"
|
||||
#include "commodityservice.h"
|
||||
|
||||
Commodity::Commodity()
|
||||
{
|
||||
@@ -13,7 +14,7 @@ void Commodity::initServiceUi()
|
||||
CommodityGrid *grid = new CommodityGrid();
|
||||
CommodityForm *form = new CommodityForm();
|
||||
|
||||
m_service = new Service<CommodityData>;
|
||||
m_service = new CommodityService();
|
||||
m_ui = grid;
|
||||
((CommodityGrid *) m_ui)->setForm(form);
|
||||
m_settingsUi = new CommoditySettingsForm();
|
||||
|
||||
+12
-2
@@ -20,7 +20,8 @@ SOURCES += commodity.cpp \
|
||||
commoditytablemodel.cpp \
|
||||
commodityform.cpp \
|
||||
commoditygrid.cpp \
|
||||
commoditysettingsform.cpp
|
||||
commoditysettingsform.cpp \
|
||||
commodityservice.cpp
|
||||
|
||||
HEADERS += commodity.h\
|
||||
commodity_global.h \
|
||||
@@ -30,7 +31,8 @@ HEADERS += commodity.h\
|
||||
commoditytablemodel.h \
|
||||
commodityform.h \
|
||||
commoditygrid.h \
|
||||
commoditysettingsform.h
|
||||
commoditysettingsform.h \
|
||||
commodityservice.h
|
||||
|
||||
unix {
|
||||
target.path = /usr/lib
|
||||
@@ -53,6 +55,7 @@ DESTDIR = ../plugins
|
||||
|
||||
ODB_FILES = commodity/data/commodity-data.h
|
||||
H_DIR = $$PWD/data/*.h
|
||||
ODB_OTHER_INCLUDES = -I $$PWD/../shop
|
||||
include(../odb.pri)
|
||||
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber
|
||||
@@ -73,3 +76,10 @@ FORMS += \
|
||||
RESOURCES += \
|
||||
commodityrc.qrc
|
||||
TRANSLATIONS = translations/commodity_cs_CZ.ts
|
||||
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lshop
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -lshop
|
||||
else:unix: LIBS += -L$$OUT_PWD/../plugins/ -lshop
|
||||
|
||||
INCLUDEPATH += $$PWD/../shop
|
||||
DEPENDPATH += $$PWD/../shop
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "commodityservice.h"
|
||||
|
||||
#include "commodity-odb.hxx"
|
||||
|
||||
CommodityService::CommodityService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QList<QSharedPointer<ShopItem> > CommodityService::shopItems()
|
||||
{
|
||||
QList<QSharedPointer<ShopItem> > ret;
|
||||
|
||||
foreach (QSharedPointer<CommodityData> data, all()) {
|
||||
ret.append(qSharedPointerDynamicCast<ShopItem, CommodityData>(data));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef COMMODITYSERVICE_H
|
||||
#define COMMODITYSERVICE_H
|
||||
|
||||
#include <service.h>
|
||||
#include <isellableservice.h>
|
||||
#include "data/commodity-data.h"
|
||||
|
||||
class CommodityService : public Service<CommodityData>, public ISellableService
|
||||
{
|
||||
public:
|
||||
CommodityService();
|
||||
|
||||
// ISellableService interface
|
||||
public:
|
||||
QList<QSharedPointer<ShopItem> > shopItems() override;
|
||||
};
|
||||
|
||||
#endif // COMMODITYSERVICE_H
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <define.h>
|
||||
|
||||
CommodityData::CommodityData(QObject *parent)
|
||||
:QObject(parent)
|
||||
:ShopItem(parent)
|
||||
{
|
||||
m_count = 0;
|
||||
m_price = 0;
|
||||
|
||||
@@ -5,12 +5,13 @@
|
||||
#include <QString>
|
||||
#include <odb/core.hxx>
|
||||
#include "commoditytypedata.h"
|
||||
#include <shopitem.h>
|
||||
#include <QDecDouble.hh>
|
||||
#include <QSharedDataPointer>
|
||||
#include <enums.h>
|
||||
|
||||
#pragma db object
|
||||
class CommodityData : public QObject
|
||||
class CommodityData : public ShopItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "isellableservice.h"
|
||||
|
||||
ISellableService::ISellableService()
|
||||
{
|
||||
}
|
||||
@@ -2,14 +2,16 @@
|
||||
#define ISELLABLESERVICE_H
|
||||
|
||||
#include "shop_global.h"
|
||||
#include "ishopitem.h"
|
||||
#include "shopitem.h"
|
||||
#include <QList>
|
||||
#include <QSharedPointer>
|
||||
|
||||
class SHOPSHARED_EXPORT ISellableService
|
||||
{
|
||||
public:
|
||||
QList<QSharedPointer<IShopItem> > shopItems() = 0;
|
||||
ISellableService();
|
||||
|
||||
virtual QList<QSharedPointer<ShopItem> > shopItems() = 0;
|
||||
};
|
||||
|
||||
#endif // ISELLABLESERVICE_H
|
||||
|
||||
+5
-2
@@ -26,7 +26,9 @@ SOURCES += shop.cpp \
|
||||
settings/shopsettings.cpp \
|
||||
settings/shopsettingsform.cpp \
|
||||
paydialog.cpp \
|
||||
paydvouchersdialog.cpp
|
||||
paydvouchersdialog.cpp \
|
||||
shopitem.cpp \
|
||||
isellableservice.cpp
|
||||
|
||||
HEADERS += shop.h\
|
||||
shop_global.h \
|
||||
@@ -46,7 +48,8 @@ HEADERS += shop.h\
|
||||
settings/shopsettings.h \
|
||||
settings/shopsettingsform.h \
|
||||
paydialog.h \
|
||||
paydvouchersdialog.h
|
||||
paydvouchersdialog.h \
|
||||
shopitem.h
|
||||
|
||||
unix {
|
||||
target.path = /usr/lib
|
||||
|
||||
@@ -18,6 +18,7 @@ ShopForm::ShopForm(QWidget *parent) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
m_itemsModel = NULL;
|
||||
m_commodityModel = NULL;
|
||||
|
||||
ui->temporarySaveButton->setEnabled(false);
|
||||
ui->saveButton->setEnabled(false);
|
||||
@@ -54,6 +55,14 @@ void ShopForm::loadLast()
|
||||
ui->saveButton->setEnabled(true);
|
||||
ui->payButton->setEnabled(true);
|
||||
}
|
||||
|
||||
if (m_commodityModel == NULL)
|
||||
{
|
||||
m_commodityModel = new AutoTableModel<ShopItem>(this);
|
||||
ui->commodityTable->setModel(m_commodityModel);
|
||||
}
|
||||
|
||||
m_commodityModel->setData(srv.allSellableItems());
|
||||
}
|
||||
|
||||
void ShopForm::fillRaceiptCombo()
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include "data/shop-data.h"
|
||||
#include <autotablemodel.h>
|
||||
|
||||
class ShopItem;
|
||||
|
||||
namespace Ui {
|
||||
class ShopForm;
|
||||
}
|
||||
@@ -41,6 +43,7 @@ private:
|
||||
Ui::ShopForm *ui;
|
||||
QSharedPointer<Voucher> m_voucher;
|
||||
AutoTableModel<VoucherItem> *m_itemsModel;
|
||||
AutoTableModel<ShopItem> *m_commodityModel;
|
||||
|
||||
void createVoucher();
|
||||
void doTempSave(bool comboChanged);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "shopitem.h"
|
||||
|
||||
ShopItem::ShopItem(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef SHOPITEM_H
|
||||
#define SHOPITEM_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "shop_global.h"
|
||||
#include "ishopitem.h"
|
||||
|
||||
class SHOPSHARED_EXPORT ShopItem : public QObject, public IShopItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QString name READ name)
|
||||
Q_PROPERTY(QDecDouble unitPrice READ unitPrice)
|
||||
Q_PROPERTY(Enums::VatType vatType READ vatType)
|
||||
|
||||
public:
|
||||
explicit ShopItem(QObject *parent = 0);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
// IShopItem interface
|
||||
public:
|
||||
virtual int id() override { return 0; }
|
||||
virtual QString name() override { return ""; }
|
||||
virtual QDecDouble unitPrice() override { return QDecDouble(); }
|
||||
virtual Enums::VatType vatType() override { return Enums::NONE; }
|
||||
virtual QString pluginId() override { return ""; }
|
||||
};
|
||||
|
||||
#endif // SHOPITEM_H
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "shopservice.h"
|
||||
#include "numberseriesservice.h"
|
||||
#include "isellableservice.h"
|
||||
#include "shop-odb.hxx"
|
||||
|
||||
ShopService::ShopService()
|
||||
@@ -120,6 +121,22 @@ QList<QSharedPointer<Voucher> > ShopService::paiedVouchers()
|
||||
return all(QString("status = %1").arg(QString::number(Voucher::PAID)));
|
||||
}
|
||||
|
||||
QList<QSharedPointer<ShopItem> > ShopService::allSellableItems()
|
||||
{
|
||||
QList<QSharedPointer<ShopItem> > items;
|
||||
foreach (IPlugin *plugin, Context::instance().plugins()) {
|
||||
IService *srv = plugin->service<IService>();
|
||||
ISellableService *selSrv = dynamic_cast<ISellableService*>(srv);
|
||||
|
||||
if (selSrv != NULL)
|
||||
{
|
||||
items.append(selSrv->shopItems());
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
QDecDouble ShopService::includeVat(QDecDouble price, Enums::VatType vatType)
|
||||
{
|
||||
return price * ((vatRate(vatType) / 100) + QDecDouble(1));
|
||||
|
||||
+2
-1
@@ -7,7 +7,7 @@
|
||||
#include <settings/globalsettings.h>
|
||||
|
||||
#include "data/shop-data.h"
|
||||
#include "ishopitem.h"
|
||||
#include "shopitem.h"
|
||||
|
||||
class ShopService : public Service<Voucher>
|
||||
{
|
||||
@@ -22,6 +22,7 @@ public:
|
||||
QList<QSharedPointer<Voucher> > savedVouchers();
|
||||
QList<QSharedPointer<Voucher> > tempVouchers();
|
||||
QList<QSharedPointer<Voucher> > paiedVouchers();
|
||||
QList<QSharedPointer<ShopItem> > allSellableItems();
|
||||
|
||||
private:
|
||||
QDecDouble includeVat(QDecDouble price, Enums::VatType vatType);
|
||||
|
||||
Reference in New Issue
Block a user