From a1f92c9f40404bce38dc49eff9354795d52c0389 Mon Sep 17 00:00:00 2001 From: Zdenek Jonak Date: Wed, 2 Mar 2016 23:26:37 +0100 Subject: [PATCH] new plugin commodity implemented --- addressbook/addressbookform.h | 3 +- addressbook/data/addressbookdata.h | 4 +- commodity/commodity.cpp | 18 ++++++ commodity/commodity.h | 23 +++++++ commodity/commodity.json | 33 ++++++++++ commodity/commodity.pro | 68 +++++++++++++++++++++ commodity/commodity_global.h | 12 ++++ commodity/commodityform.cpp | 37 +++++++++++ commodity/commodityform.h | 29 +++++++++ commodity/commodityform.ui | 91 ++++++++++++++++++++++++++++ commodity/commoditygrid.cpp | 8 +++ commodity/commoditygrid.h | 15 +++++ commodity/commoditytablemodel.cpp | 6 ++ commodity/commoditytablemodel.h | 13 ++++ commodity/data/commodity-data.h | 6 ++ commodity/data/commoditydata.cpp | 89 +++++++++++++++++++++++++++ commodity/data/commoditydata.h | 64 +++++++++++++++++++ commodity/data/commoditytypedata.cpp | 38 ++++++++++++ commodity/data/commoditytypedata.h | 36 +++++++++++ core/core.h | 1 + core/settings/globalsettings.cpp | 2 +- prodejna.pro | 6 +- services/data/accservice.cpp | 3 +- services/data/accservice.h | 2 +- 24 files changed, 597 insertions(+), 10 deletions(-) create mode 100644 commodity/commodity.cpp create mode 100644 commodity/commodity.h create mode 100644 commodity/commodity.json create mode 100644 commodity/commodity.pro create mode 100644 commodity/commodity_global.h create mode 100644 commodity/commodityform.cpp create mode 100644 commodity/commodityform.h create mode 100644 commodity/commodityform.ui create mode 100644 commodity/commoditygrid.cpp create mode 100644 commodity/commoditygrid.h create mode 100644 commodity/commoditytablemodel.cpp create mode 100644 commodity/commoditytablemodel.h create mode 100644 commodity/data/commodity-data.h create mode 100644 commodity/data/commoditydata.cpp create mode 100644 commodity/data/commoditydata.h create mode 100644 commodity/data/commoditytypedata.cpp create mode 100644 commodity/data/commoditytypedata.h diff --git a/addressbook/addressbookform.h b/addressbook/addressbookform.h index 4c1a377..7888b7d 100644 --- a/addressbook/addressbookform.h +++ b/addressbook/addressbookform.h @@ -2,8 +2,7 @@ #define ADDRESSBOOKFORM_H #include -#include -#include "autoform.h" +#include #include "data/addressbookdata.h" #include "addressbook-odb.hxx" diff --git a/addressbook/data/addressbookdata.h b/addressbook/data/addressbookdata.h index 07fba57..cc0f2b8 100644 --- a/addressbook/data/addressbookdata.h +++ b/addressbook/data/addressbookdata.h @@ -4,7 +4,7 @@ #include #include #include -#include "odb/core.hxx" +#include #pragma db object class AddressbookData : public QObject @@ -58,7 +58,7 @@ public: private: friend class odb::access; -#pragma db id auto + #pragma db id auto int m_id; QString m_title; QString m_firstName; diff --git a/commodity/commodity.cpp b/commodity/commodity.cpp new file mode 100644 index 0000000..c1bf0f5 --- /dev/null +++ b/commodity/commodity.cpp @@ -0,0 +1,18 @@ +#include "commodity.h" +#include "data/commodity-data.h" +#include "commodityform.h" +#include "commoditygrid.h" + +Commodity::Commodity() +{ +} + +void Commodity::initServiceUi() +{ + CommodityGrid *grid = new CommodityGrid(); + CommodityForm *form = new CommodityForm(); + + m_service = new Service; + m_ui = grid; + ((CommodityGrid *) m_ui)->setForm(form); +} diff --git a/commodity/commodity.h b/commodity/commodity.h new file mode 100644 index 0000000..484cc77 --- /dev/null +++ b/commodity/commodity.h @@ -0,0 +1,23 @@ +#ifndef COMMODITY_H +#define COMMODITY_H + +#include "commodity_global.h" +#include +#include +#include + +class COMMODITYSHARED_EXPORT Commodity : public QObject, IMetaDataPlugin +{ + Q_OBJECT + + Q_PLUGIN_METADATA(IID PluginInterface_iid FILE "commodity.json") + Q_INTERFACES(IPlugin) + +public: + Commodity(); + +protected: + void initServiceUi() Q_DECL_OVERRIDE; +}; + +#endif // COMMODITY_H diff --git a/commodity/commodity.json b/commodity/commodity.json new file mode 100644 index 0000000..4c5ab93 --- /dev/null +++ b/commodity/commodity.json @@ -0,0 +1,33 @@ +{ + "id" : "COMMODITY", + "name" : { + "default" : "Commodity", + "CZ" : "Zboží" + }, + "descriptoin" : { + "default" : "", + "CZ" : "" + }, + "schemaVersion" : 1, + "sql" : [ + "CREATE TABLE \"CommodityTypeData\" ( + \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + \"name\" TEXT NULL); + +CREATE TABLE \"CommodityData\" ( + \"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + \"name\" TEXT NULL, + \"shortName\" TEXT NULL, + \"code\" TEXT NULL, + \"type\" INTEGER NULL, + \"price\" INTEGER NOT NULL, + \"vat\" INTEGER NOT NULL, + \"count\" INTEGER NOT NULL, + CONSTRAINT \"type_fk\" + FOREIGN KEY (\"type\") + REFERENCES \"CommodityTypeData\" (\"id\") + DEFERRABLE INITIALLY DEFERRED);" + + ], + "dependencies" : [] +} diff --git a/commodity/commodity.pro b/commodity/commodity.pro new file mode 100644 index 0000000..cb3fc46 --- /dev/null +++ b/commodity/commodity.pro @@ -0,0 +1,68 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2016-02-09T21:26:14 +# +#------------------------------------------------- + +QT += widgets sql + +QT -= gui + +TARGET = commodity +TEMPLATE = lib + +DEFINES += COMMODITY_LIBRARY\ + _GLIBCXX_USE_CXX11_ABI=1 + +SOURCES += commodity.cpp \ + data/commoditydata.cpp \ + data/commoditytypedata.cpp \ + commoditytablemodel.cpp \ + commodityform.cpp \ + commoditygrid.cpp + +HEADERS += commodity.h\ + commodity_global.h \ + data/commoditydata.h \ + data/commoditytypedata.h \ + data/commodity-data.h \ + commoditytablemodel.h \ + commodityform.h \ + commoditygrid.h + +unix { + target.path = /usr/lib + INSTALLS += target + QMAKE_CXXFLAGS += -std=c++11 + QMAKE_CXXFLAGS += -Wno-unknown-pragmas +} + +win32 { + QMAKE_CXXFLAGS += -wd4995 -wd4068 +} +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../core/release/ -lcore +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../core/debug/ -lcore +else:unix: LIBS += -L$$OUT_PWD/../core/ -lcore + +INCLUDEPATH += $$PWD/../core +DEPENDPATH += $$PWD/../core + +DESTDIR = ../plugins + +ODB_FILES = commodity/data/commodity-data.h +H_DIR = $$PWD/data/*.h +include(../odb.pri) + +win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber +else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber +else:unix: LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber + +INCLUDEPATH += $$PWD/../qdecimal/src +INCLUDEPATH += $$PWD/../qdecimal/decnumber +DEPENDPATH += $$PWD/../qdecimal/src + +OTHER_FILES += \ + commodity.json + +FORMS += \ + commodityform.ui diff --git a/commodity/commodity_global.h b/commodity/commodity_global.h new file mode 100644 index 0000000..4d422a0 --- /dev/null +++ b/commodity/commodity_global.h @@ -0,0 +1,12 @@ +#ifndef COMMODITY_GLOBAL_H +#define COMMODITY_GLOBAL_H + +#include + +#if defined(COMMODITY_LIBRARY) +# define COMMODITYSHARED_EXPORT Q_DECL_EXPORT +#else +# define COMMODITYSHARED_EXPORT Q_DECL_IMPORT +#endif + +#endif // COMMODITY_GLOBAL_H diff --git a/commodity/commodityform.cpp b/commodity/commodityform.cpp new file mode 100644 index 0000000..eac189c --- /dev/null +++ b/commodity/commodityform.cpp @@ -0,0 +1,37 @@ +#include "commodityform.h" +#include "ui_commodityform.h" +#include +#include +#include +#include "data/commoditytypedata.h" + +CommodityForm::CommodityForm(QWidget *parent) : + AutoForm(parent), + ui(new Ui::CommodityForm) +{ + ui->setupUi(this); + registerBinding(ui->name); + registerBinding(ui->shortName); + registerBinding(ui->code); + registerBinding(ui->price); + QList vt ; + vt << ComboData(Enums::HIGH,tr("High")) << ComboData(Enums::FIRST_LOWER,tr("First Lower")) << ComboData(Enums::SECOND_LOWER,tr("Second Lower")); + registerBinding(ui->vat,vt); + registerBinding(ui->count); +} + +CommodityForm::~CommodityForm() +{ + delete ui; +} + +void CommodityForm::registerCombos() +{ + QList ct; + Service cts; + foreach (QSharedPointer ctd , cts.all()) { + ComboData cd(ctd); + ct << cd; + } + registerBinding(ui->type,ct); +} diff --git a/commodity/commodityform.h b/commodity/commodityform.h new file mode 100644 index 0000000..8161ed6 --- /dev/null +++ b/commodity/commodityform.h @@ -0,0 +1,29 @@ +#ifndef COMMODITYFORM_H +#define COMMODITYFORM_H + +#include +#include +#include "data/commoditydata.h" +#include "commodity-odb.hxx" + +namespace Ui { +class CommodityForm; +} + +class CommodityForm : public AutoForm +{ + Q_OBJECT + +public: + explicit CommodityForm(QWidget *parent = 0); + ~CommodityForm(); + +private: + Ui::CommodityForm *ui; + + // FormBinder interface +protected: + void registerCombos(); +}; + +#endif // COMMODITYFORM_H diff --git a/commodity/commodityform.ui b/commodity/commodityform.ui new file mode 100644 index 0000000..e730f81 --- /dev/null +++ b/commodity/commodityform.ui @@ -0,0 +1,91 @@ + + + CommodityForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Name + + + + + + + + + + Short Name + + + + + + + + + + Code + + + + + + + + + + Type + + + + + + + Price + + + + + + + Vat + + + + + + + Count + + + + + + + + + + + + + + + + + + + + diff --git a/commodity/commoditygrid.cpp b/commodity/commoditygrid.cpp new file mode 100644 index 0000000..217b11e --- /dev/null +++ b/commodity/commoditygrid.cpp @@ -0,0 +1,8 @@ +#include "commoditygrid.h" +#include "commoditytablemodel.h" + +CommodityGrid::CommodityGrid(QWidget *parent) + :GridForm(parent) +{ + setTableModel(new CommodityTableModel()); +} diff --git a/commodity/commoditygrid.h b/commodity/commoditygrid.h new file mode 100644 index 0000000..f29b6cd --- /dev/null +++ b/commodity/commoditygrid.h @@ -0,0 +1,15 @@ +#ifndef COMMODITYGRID_H +#define COMMODITYGRID_H + +#include +#include "data/commoditydata.h" +#include "commodity-odb.hxx" + +class CommodityGrid : public GridForm +{ + Q_OBJECT +public: + CommodityGrid(QWidget *parent = NULL); +}; + +#endif // COMMODITYGRID_H diff --git a/commodity/commoditytablemodel.cpp b/commodity/commoditytablemodel.cpp new file mode 100644 index 0000000..fb4af00 --- /dev/null +++ b/commodity/commoditytablemodel.cpp @@ -0,0 +1,6 @@ +#include "commoditytablemodel.h" + +CommodityTableModel::CommodityTableModel(QObject *parent) + :AutoTableModel(parent) +{ +} diff --git a/commodity/commoditytablemodel.h b/commodity/commoditytablemodel.h new file mode 100644 index 0000000..9d33c2e --- /dev/null +++ b/commodity/commoditytablemodel.h @@ -0,0 +1,13 @@ +#ifndef COMMODITYTABLEMODEL_H +#define COMMODITYTABLEMODEL_H +#include +#include "data/commoditydata.h" + +class CommodityTableModel : public AutoTableModel +{ + Q_OBJECT +public: + CommodityTableModel(QObject *parent= NULL); +}; + +#endif // COMMODITYTABLEMODEL_H diff --git a/commodity/data/commodity-data.h b/commodity/data/commodity-data.h new file mode 100644 index 0000000..2f2b967 --- /dev/null +++ b/commodity/data/commodity-data.h @@ -0,0 +1,6 @@ +#ifndef COMMODITY_DATA_H +#define COMMODITY_DATA_H +#include "commoditydata.h" +#include "commoditytypedata.h" + +#endif // COMMODITY_DATA_H diff --git a/commodity/data/commoditydata.cpp b/commodity/data/commoditydata.cpp new file mode 100644 index 0000000..fe2b6ff --- /dev/null +++ b/commodity/data/commoditydata.cpp @@ -0,0 +1,89 @@ +#include "commoditydata.h" +#include + +CommodityData::CommodityData(QObject *parent) + :QObject(parent) +{ +} +int CommodityData::id() const +{ + return m_id; +} + +void CommodityData::setId(int id) +{ + m_id = id; +} +QString CommodityData::name() const +{ + return m_name; +} + +void CommodityData::setName(const QString &name) +{ + m_name = name; +} +QString CommodityData::shortName() const +{ + return m_shortName; +} + +void CommodityData::setShortName(const QString &shortName) +{ + m_shortName = shortName; +} +QString CommodityData::code() const +{ + return m_code; +} + +void CommodityData::setCode(const QString &code) +{ + m_code = code; +} +QSharedPointer CommodityData::type() const +{ + return m_type; +} + +void CommodityData::setType(const QSharedPointer &type) +{ + if (qobject_cast(type.data()) != NULL) { + m_type = qSharedPointerDynamicCast(type); + } +} +QDecDouble CommodityData::price() const +{ + return QDecDouble((double)m_price / DEC_MULTIPLE); +} + +void CommodityData::setPrice(const QDecDouble &price) +{ + m_price = price.toDouble() * DEC_MULTIPLE; +} +Enums::VatType CommodityData::vat() const +{ + return m_vat; +} + +void CommodityData::setVat(const Enums::VatType &vat) +{ + m_vat = vat; +} +int CommodityData::count() const +{ + return m_count; +} + +void CommodityData::setCount(int count) +{ + m_count = count; +} + + + + + + + + diff --git a/commodity/data/commoditydata.h b/commodity/data/commoditydata.h new file mode 100644 index 0000000..7ac5e48 --- /dev/null +++ b/commodity/data/commoditydata.h @@ -0,0 +1,64 @@ +#ifndef COMMODITYDATA_H +#define COMMODITYDATA_H + +#include +#include +#include +#include "commoditytypedata.h" +#include +#include +#include + +#pragma db object +class CommodityData : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString shortName READ shortName WRITE setShortName) + Q_PROPERTY(QString code READ code WRITE setCode) + Q_PROPERTY(QSharedPointer type READ type WRITE setType) + Q_PROPERTY(QDecDouble price READ price WRITE setPrice) + Q_PROPERTY(Enums::VatType vat READ vat WRITE setVat) + Q_PROPERTY(int count READ count WRITE setCount) + +public: + CommodityData(QObject *parent = 0); + + int id() const; + void setId(int id); + + QString name() const; + void setName(const QString &name); + + QString shortName() const; + void setShortName(const QString &shortName); + + QString code() const; + void setCode(const QString &code); + + QSharedPointer type() const; + void setType(const QSharedPointer &type); + + QDecDouble price() const; + void setPrice(const QDecDouble &price); + + Enums::VatType vat() const; + void setVat(const Enums::VatType &vat); + + int count() const; + void setCount(int count); + +private: + friend class odb::access; +#pragma db id auto + int m_id; + QString m_name; + QString m_shortName; + QString m_code; + QSharedPointer m_type; + int m_price; + Enums::VatType m_vat; + int m_count; +}; + +#endif // COMMODITYDATA_H diff --git a/commodity/data/commoditytypedata.cpp b/commodity/data/commoditytypedata.cpp new file mode 100644 index 0000000..cd4d9f2 --- /dev/null +++ b/commodity/data/commoditytypedata.cpp @@ -0,0 +1,38 @@ +#include "commoditytypedata.h" + +CommodityTypeData::CommodityTypeData(QObject *parent) + :ComboItem(parent) +{ +} +int CommodityTypeData::id() const +{ + return m_id; +} + +void CommodityTypeData::setId(int id) +{ + m_id = id; +} +QString CommodityTypeData::name() const +{ + return m_name; +} + +void CommodityTypeData::setName(const QString &name) +{ + m_name = name; +} + +bool CommodityTypeData::eq(ComboItem *other) +{ + CommodityTypeData* ct = qobject_cast (other); + + return ct != NULL && this->id() == ct->id() ; +} + +QString CommodityTypeData::toString() +{ + return this->name(); +} + + diff --git a/commodity/data/commoditytypedata.h b/commodity/data/commoditytypedata.h new file mode 100644 index 0000000..95aed64 --- /dev/null +++ b/commodity/data/commoditytypedata.h @@ -0,0 +1,36 @@ +#ifndef COMMODITYTYPEDATA_H +#define COMMODITYTYPEDATA_H + +#include +#include +#include +#include + +#pragma db object +class CommodityTypeData :public ComboItem +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName) + +public: + CommodityTypeData(QObject *parent = 0); + + int id() const; + void setId(int id); + + QString name() const; + void setName(const QString &name); + +private: + friend class odb::access; + #pragma db id auto + int m_id; + QString m_name; + + // ComboItem interface +public: + bool eq(ComboItem *other); + QString toString(); +}; + +#endif // COMMODITYTYPEDATA_H diff --git a/core/core.h b/core/core.h index cc8ae69..7b5f590 100644 --- a/core/core.h +++ b/core/core.h @@ -11,5 +11,6 @@ #include "combodata.h" #include "settingsservice.h" #include "settingsform.h" +#include "enums.h" #endif // CORE_H diff --git a/core/settings/globalsettings.cpp b/core/settings/globalsettings.cpp index 1e66133..c2cf97d 100644 --- a/core/settings/globalsettings.cpp +++ b/core/settings/globalsettings.cpp @@ -2,7 +2,7 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent) { - + m_ic = 0; } QString GlobalSettings::firmName() const diff --git a/prodejna.pro b/prodejna.pro index 67c41f1..f297667 100644 --- a/prodejna.pro +++ b/prodejna.pro @@ -5,7 +5,7 @@ SUBDIRS += \ core \ application \ accommodation \ - services - #commodity \ - #addressbook + services \ + commodity \ + addressbook diff --git a/services/data/accservice.cpp b/services/data/accservice.cpp index b3aa13c..d6c0a65 100644 --- a/services/data/accservice.cpp +++ b/services/data/accservice.cpp @@ -1,7 +1,8 @@ #include "accservice.h" #include -AccService::AccService() +AccService::AccService(QObject *parent) + :QObject(parent) { m_price = 0; m_active = 1; diff --git a/services/data/accservice.h b/services/data/accservice.h index af512ba..cda12f9 100644 --- a/services/data/accservice.h +++ b/services/data/accservice.h @@ -24,7 +24,7 @@ class AccService : public QObject Q_PROPERTY(Enums::VatType vatType READ vatType WRITE setVatType) public: - AccService(); + AccService(QObject *parent = 0);