diff --git a/commodity/commodity.cpp b/commodity/commodity.cpp index cd0622f..68db393 100644 --- a/commodity/commodity.cpp +++ b/commodity/commodity.cpp @@ -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; + m_service = new CommodityService(); m_ui = grid; ((CommodityGrid *) m_ui)->setForm(form); m_settingsUi = new CommoditySettingsForm(); diff --git a/commodity/commodity.pro b/commodity/commodity.pro index 0ca4f0b..5fc1b92 100644 --- a/commodity/commodity.pro +++ b/commodity/commodity.pro @@ -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 diff --git a/commodity/commodityservice.cpp b/commodity/commodityservice.cpp new file mode 100644 index 0000000..adbfb82 --- /dev/null +++ b/commodity/commodityservice.cpp @@ -0,0 +1,19 @@ +#include "commodityservice.h" + +#include "commodity-odb.hxx" + +CommodityService::CommodityService() +{ + +} + +QList > CommodityService::shopItems() +{ + QList > ret; + + foreach (QSharedPointer data, all()) { + ret.append(qSharedPointerDynamicCast(data)); + } + + return ret; +} diff --git a/commodity/commodityservice.h b/commodity/commodityservice.h new file mode 100644 index 0000000..8527aef --- /dev/null +++ b/commodity/commodityservice.h @@ -0,0 +1,18 @@ +#ifndef COMMODITYSERVICE_H +#define COMMODITYSERVICE_H + +#include +#include +#include "data/commodity-data.h" + +class CommodityService : public Service, public ISellableService +{ +public: + CommodityService(); + + // ISellableService interface +public: + QList > shopItems() override; +}; + +#endif // COMMODITYSERVICE_H diff --git a/commodity/data/commoditydata.cpp b/commodity/data/commoditydata.cpp index b0b9769..5a12089 100644 --- a/commodity/data/commoditydata.cpp +++ b/commodity/data/commoditydata.cpp @@ -2,7 +2,7 @@ #include CommodityData::CommodityData(QObject *parent) - :QObject(parent) + :ShopItem(parent) { m_count = 0; m_price = 0; diff --git a/commodity/data/commoditydata.h b/commodity/data/commoditydata.h index 7ac5e48..3fb5c42 100644 --- a/commodity/data/commoditydata.h +++ b/commodity/data/commoditydata.h @@ -5,12 +5,13 @@ #include #include #include "commoditytypedata.h" +#include #include #include #include #pragma db object -class CommodityData : public QObject +class CommodityData : public ShopItem { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName) diff --git a/shop/isellableservice.cpp b/shop/isellableservice.cpp new file mode 100644 index 0000000..f8dad60 --- /dev/null +++ b/shop/isellableservice.cpp @@ -0,0 +1,5 @@ +#include "isellableservice.h" + +ISellableService::ISellableService() +{ +} diff --git a/shop/isellableservice.h b/shop/isellableservice.h index 717164e..8ce1372 100644 --- a/shop/isellableservice.h +++ b/shop/isellableservice.h @@ -2,14 +2,16 @@ #define ISELLABLESERVICE_H #include "shop_global.h" -#include "ishopitem.h" +#include "shopitem.h" #include #include class SHOPSHARED_EXPORT ISellableService { public: - QList > shopItems() = 0; + ISellableService(); + + virtual QList > shopItems() = 0; }; #endif // ISELLABLESERVICE_H diff --git a/shop/shop.pro b/shop/shop.pro index 3bcd021..8991736 100644 --- a/shop/shop.pro +++ b/shop/shop.pro @@ -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 diff --git a/shop/shopform.cpp b/shop/shopform.cpp index 0819eee..3b1cfc5 100644 --- a/shop/shopform.cpp +++ b/shop/shopform.cpp @@ -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(this); + ui->commodityTable->setModel(m_commodityModel); + } + + m_commodityModel->setData(srv.allSellableItems()); } void ShopForm::fillRaceiptCombo() diff --git a/shop/shopform.h b/shop/shopform.h index 36cb250..bb26645 100644 --- a/shop/shopform.h +++ b/shop/shopform.h @@ -6,6 +6,8 @@ #include "data/shop-data.h" #include +class ShopItem; + namespace Ui { class ShopForm; } @@ -41,6 +43,7 @@ private: Ui::ShopForm *ui; QSharedPointer m_voucher; AutoTableModel *m_itemsModel; + AutoTableModel *m_commodityModel; void createVoucher(); void doTempSave(bool comboChanged); diff --git a/shop/shopitem.cpp b/shop/shopitem.cpp new file mode 100644 index 0000000..541aaac --- /dev/null +++ b/shop/shopitem.cpp @@ -0,0 +1,6 @@ +#include "shopitem.h" + +ShopItem::ShopItem(QObject *parent) : QObject(parent) +{ + +} diff --git a/shop/shopitem.h b/shop/shopitem.h new file mode 100644 index 0000000..d23eac1 --- /dev/null +++ b/shop/shopitem.h @@ -0,0 +1,33 @@ +#ifndef SHOPITEM_H +#define SHOPITEM_H + +#include + +#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 diff --git a/shop/shopservice.cpp b/shop/shopservice.cpp index 15e52a4..6220085 100644 --- a/shop/shopservice.cpp +++ b/shop/shopservice.cpp @@ -1,5 +1,6 @@ #include "shopservice.h" #include "numberseriesservice.h" +#include "isellableservice.h" #include "shop-odb.hxx" ShopService::ShopService() @@ -120,6 +121,22 @@ QList > ShopService::paiedVouchers() return all(QString("status = %1").arg(QString::number(Voucher::PAID))); } +QList > ShopService::allSellableItems() +{ + QList > items; + foreach (IPlugin *plugin, Context::instance().plugins()) { + IService *srv = plugin->service(); + ISellableService *selSrv = dynamic_cast(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)); diff --git a/shop/shopservice.h b/shop/shopservice.h index 0c626d1..87eae88 100644 --- a/shop/shopservice.h +++ b/shop/shopservice.h @@ -7,7 +7,7 @@ #include #include "data/shop-data.h" -#include "ishopitem.h" +#include "shopitem.h" class ShopService : public Service { @@ -22,6 +22,7 @@ public: QList > savedVouchers(); QList > tempVouchers(); QList > paiedVouchers(); + QList > allSellableItems(); private: QDecDouble includeVat(QDecDouble price, Enums::VatType vatType);