From 13d90445ccf57539fd46851ffd66b719a182a273 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Wed, 31 May 2017 16:16:22 +0200 Subject: [PATCH] Camp wizard is now able to open from shop plugin --- camp/camp.cpp | 3 ++- camp/camp.pro | 8 ++++++-- camp/campseller.cpp | 28 +++++++++++++++++++++++++ camp/campseller.h | 17 +++++++++++++++ camp/campservice.cpp | 33 +++++++++++++++++++++++++++-- camp/campservice.h | 12 ++++++++++- camp/campshopitem.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++ camp/campshopitem.h | 34 ++++++++++++++++++++++++++++++ 8 files changed, 177 insertions(+), 6 deletions(-) create mode 100644 camp/campseller.cpp create mode 100644 camp/campseller.h create mode 100644 camp/campshopitem.cpp create mode 100644 camp/campshopitem.h diff --git a/camp/camp.cpp b/camp/camp.cpp index 94e3e2e..7c11e23 100644 --- a/camp/camp.cpp +++ b/camp/camp.cpp @@ -2,6 +2,7 @@ #include "campgrid.h" #include "campform.h" +#include "campservice.h" #include "settings/campsettingsform.h" Camp::Camp() @@ -10,7 +11,7 @@ Camp::Camp() void Camp::initServiceUi() { - m_service = new Service(); + m_service = new CampService(); m_ui = new CampGrid(); ((CampGrid*)m_ui)->setForm(new CampForm()); m_settingsUi = new CampSettingsForm(); diff --git a/camp/camp.pro b/camp/camp.pro index 3cae173..8e2c548 100644 --- a/camp/camp.pro +++ b/camp/camp.pro @@ -34,7 +34,9 @@ SOURCES += camp.cpp \ settings/campsettings.cpp \ campwizard.cpp \ campservice.cpp \ - addservicedialog.cpp + addservicedialog.cpp \ + campshopitem.cpp \ + campseller.cpp HEADERS += camp.h\ camp_global.h \ @@ -50,7 +52,9 @@ HEADERS += camp.h\ settings/campsettings.h \ campwizard.h \ campservice.h \ - addservicedialog.h + addservicedialog.h \ + campshopitem.h \ + campseller.h include(../config_plugin.pri) diff --git a/camp/campseller.cpp b/camp/campseller.cpp new file mode 100644 index 0000000..17f9eb9 --- /dev/null +++ b/camp/campseller.cpp @@ -0,0 +1,28 @@ +#include "campseller.h" + +#include "campwizard.h" +#include "campservice.h" +#include "data/camp-data.h" +#include "campshopitem.h" + +CampSeller::CampSeller(QObject *parent) + :ISeller(parent) +{ +} + +void CampSeller::prepareItem() +{ + CampWizard *wizard = new CampWizard(); + wizard->setAttribute(Qt::WA_DeleteOnClose); + + CampService srv; + CampDataPtr data = srv.create(); + wizard->setData(data); + wizard->show(); + + connect(wizard, &QDialog::accepted, [this, data](){ + CampShopItemPtr item(new CampShopItem); + item->setUnitPrice(data->totalPrice()); + emit itemPrepared(item, 1); + }); +} diff --git a/camp/campseller.h b/camp/campseller.h new file mode 100644 index 0000000..dac681e --- /dev/null +++ b/camp/campseller.h @@ -0,0 +1,17 @@ +#ifndef CAMPSELLER_H +#define CAMPSELLER_H + +#include + +class CampSeller : public ISeller +{ + Q_OBJECT +public: + explicit CampSeller(QObject *parent = 0); + + // ISeller interface +public: + void prepareItem(); +}; + +#endif // CAMPSELLER_H diff --git a/camp/campservice.cpp b/camp/campservice.cpp index 323cd7d..4aed30e 100644 --- a/camp/campservice.cpp +++ b/camp/campservice.cpp @@ -2,13 +2,14 @@ #include #include #include +#include "campshopitem.h" +#include "campseller.h" #include CampService::CampService() { - SettingsService srv("CAMP"); - m_settings = srv.loadSettings(); m_pluginId = "CAMP"; + m_seller = new CampSeller(this); } void CampService::addPerson(CampDataPtr data, AddressbookDataPtr address) @@ -73,6 +74,9 @@ CampDataPtr CampService::create() void CampService::calculate(CampDataPtr data) { + SettingsService srv("CAMP"); + m_settings = srv.loadSettings(); + calcServices(data); calcPeople(data); calcPrice(data); @@ -268,6 +272,31 @@ void CampService::addAccFee(CampDataPtr data, AddressItemPtr item, int startAge, } } +QList CampService::shopItems() +{ + CampShopItemPtr item(new CampShopItem); + + QList items; + items.append(item); + + return items; +} + +ShopItemPtr CampService::shopItem(int ) +{ + return CampShopItemPtr(new CampShopItem); +} + +void CampService::addedToVoucher(int , int ) +{ + +} + +ISeller *CampService::seller() +{ + return m_seller; +} + ServiceItemPtr CampService::addServiceInt(CampDataPtr data, AccServicePtr service) { ServiceItemPtr serviceItem(new ServiceItem); diff --git a/camp/campservice.h b/camp/campservice.h index f58b07a..4097836 100644 --- a/camp/campservice.h +++ b/camp/campservice.h @@ -4,14 +4,16 @@ #include #include #include +#include #include "data/camp-data.h" #include "settings/campsettings.h" #include "camp-odb.hxx" -class CampService : public Service +class CampService : public Service, public ISellableService { public: CampService(); + void addPerson(CampDataPtr data, AddressbookDataPtr address); void addService(CampDataPtr data, AccServicePtr service); void addService(CampDataPtr data, AccServicePtr service, QDecDouble price, QString description); @@ -27,6 +29,14 @@ private: void calcPrice(CampDataPtr data); void addAccFee(CampDataPtr data, AddressItemPtr item, int startAge, int endAge, int days); CampSettingsPtr m_settings; + ISeller *m_seller; + + // ISellableService interface +public: + QList shopItems(); + ShopItemPtr shopItem(int itemId); + void addedToVoucher(int itemId, int countAdded); + ISeller *seller(); }; #endif // CAMPSERVICE_H diff --git a/camp/campshopitem.cpp b/camp/campshopitem.cpp new file mode 100644 index 0000000..8c2547d --- /dev/null +++ b/camp/campshopitem.cpp @@ -0,0 +1,48 @@ +#include "campshopitem.h" + +CampShopItem::CampShopItem(QObject *parent) + :ShopItem(parent) +{ + m_unitPrice = QDecDouble(0); + m_vatType = Enums::NONE; +} + +QString CampShopItem::name() +{ + return "Camp"; +} + +QString CampShopItem::shortName() +{ + return "Camp"; +} + +QDecDouble CampShopItem::unitPrice() +{ + return m_unitPrice; +} + +Enums::VatType CampShopItem::vatType() +{ + return m_vatType; +} + +QString CampShopItem::pluginId() +{ + return "CAMP"; +} + +QString CampShopItem::code() +{ + return "Camp"; +} + +void CampShopItem::setUnitPrice(const QDecDouble &unitPrice) +{ + m_unitPrice = unitPrice; +} + +void CampShopItem::setVatType(const Enums::VatType &vatType) +{ + m_vatType = vatType; +} diff --git a/camp/campshopitem.h b/camp/campshopitem.h new file mode 100644 index 0000000..60a4767 --- /dev/null +++ b/camp/campshopitem.h @@ -0,0 +1,34 @@ +#ifndef CAMPSHOPITEM_H +#define CAMPSHOPITEM_H + +#include + +class CampShopItem : public ShopItem +{ +public: + CampShopItem(QObject *parent = 0); + + // IShopItem interface +public: + QString name(); + QString shortName(); + QDecDouble unitPrice(); + Enums::VatType vatType(); + QString pluginId(); + + // ShopItem interface +public: + QString code(); + + void setUnitPrice(const QDecDouble &unitPrice); + + void setVatType(const Enums::VatType &vatType); + +private: + QDecDouble m_unitPrice; + Enums::VatType m_vatType; +}; + +typedef QSharedPointer CampShopItemPtr; + +#endif // CAMPSHOPITEM_H