new plugin commodity implemented

print
Zdenek Jonak 9 years ago
parent 4b8d790ea8
commit a1f92c9f40

@ -2,8 +2,7 @@
#define ADDRESSBOOKFORM_H
#include <QWidget>
#include <QWidget>
#include "autoform.h"
#include <autoform.h>
#include "data/addressbookdata.h"
#include "addressbook-odb.hxx"

@ -4,7 +4,7 @@
#include <QObject>
#include <QString>
#include <QDate>
#include "odb/core.hxx"
#include <odb/core.hxx>
#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;

@ -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<CommodityData>;
m_ui = grid;
((CommodityGrid *) m_ui)->setForm(form);
}

@ -0,0 +1,23 @@
#ifndef COMMODITY_H
#define COMMODITY_H
#include "commodity_global.h"
#include <core.h>
#include <QObject>
#include <QtPlugin>
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

@ -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" : []
}

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

@ -0,0 +1,12 @@
#ifndef COMMODITY_GLOBAL_H
#define COMMODITY_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(COMMODITY_LIBRARY)
# define COMMODITYSHARED_EXPORT Q_DECL_EXPORT
#else
# define COMMODITYSHARED_EXPORT Q_DECL_IMPORT
#endif
#endif // COMMODITY_GLOBAL_H

@ -0,0 +1,37 @@
#include "commodityform.h"
#include "ui_commodityform.h"
#include <combodata.h>
#include <QSharedPointer>
#include <qlist.h>
#include "data/commoditytypedata.h"
CommodityForm::CommodityForm(QWidget *parent) :
AutoForm<CommodityData>(parent),
ui(new Ui::CommodityForm)
{
ui->setupUi(this);
registerBinding(ui->name);
registerBinding(ui->shortName);
registerBinding(ui->code);
registerBinding(ui->price);
QList<ComboData> 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<ComboData> ct;
Service<CommodityTypeData> cts;
foreach (QSharedPointer<CommodityTypeData> ctd , cts.all()) {
ComboData cd(ctd);
ct << cd;
}
registerBinding(ui->type,ct);
}

@ -0,0 +1,29 @@
#ifndef COMMODITYFORM_H
#define COMMODITYFORM_H
#include <QWidget>
#include <autoform.h>
#include "data/commoditydata.h"
#include "commodity-odb.hxx"
namespace Ui {
class CommodityForm;
}
class CommodityForm : public AutoForm<CommodityData>
{
Q_OBJECT
public:
explicit CommodityForm(QWidget *parent = 0);
~CommodityForm();
private:
Ui::CommodityForm *ui;
// FormBinder interface
protected:
void registerCombos();
};
#endif // COMMODITYFORM_H

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CommodityForm</class>
<widget class="QWidget" name="CommodityForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="name"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Short Name</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="shortName"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Code</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="code"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Price</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Vat</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Count</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="price"/>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="count"/>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="type"/>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="vat"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

@ -0,0 +1,8 @@
#include "commoditygrid.h"
#include "commoditytablemodel.h"
CommodityGrid::CommodityGrid(QWidget *parent)
:GridForm<CommodityData>(parent)
{
setTableModel(new CommodityTableModel());
}

@ -0,0 +1,15 @@
#ifndef COMMODITYGRID_H
#define COMMODITYGRID_H
#include <core.h>
#include "data/commoditydata.h"
#include "commodity-odb.hxx"
class CommodityGrid : public GridForm<CommodityData>
{
Q_OBJECT
public:
CommodityGrid(QWidget *parent = NULL);
};
#endif // COMMODITYGRID_H

@ -0,0 +1,6 @@
#include "commoditytablemodel.h"
CommodityTableModel::CommodityTableModel(QObject *parent)
:AutoTableModel<CommodityData>(parent)
{
}

@ -0,0 +1,13 @@
#ifndef COMMODITYTABLEMODEL_H
#define COMMODITYTABLEMODEL_H
#include <autotablemodel.h>
#include "data/commoditydata.h"
class CommodityTableModel : public AutoTableModel<CommodityData>
{
Q_OBJECT
public:
CommodityTableModel(QObject *parent= NULL);
};
#endif // COMMODITYTABLEMODEL_H

@ -0,0 +1,6 @@
#ifndef COMMODITY_DATA_H
#define COMMODITY_DATA_H
#include "commoditydata.h"
#include "commoditytypedata.h"
#endif // COMMODITY_DATA_H

@ -0,0 +1,89 @@
#include "commoditydata.h"
#include <define.h>
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<QObject> CommodityData::type() const
{
return m_type;
}
void CommodityData::setType(const QSharedPointer<QObject> &type)
{
if (qobject_cast<CommodityTypeData*>(type.data()) != NULL) {
m_type = qSharedPointerDynamicCast<CommodityTypeData, QObject>(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;
}

@ -0,0 +1,64 @@
#ifndef COMMODITYDATA_H
#define COMMODITYDATA_H
#include <QObject>
#include <QString>
#include <odb/core.hxx>
#include "commoditytypedata.h"
#include <QDecDouble.hh>
#include <QSharedDataPointer>
#include <enums.h>
#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<QObject> 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<QObject> type() const;
void setType(const QSharedPointer<QObject> &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<CommodityTypeData> m_type;
int m_price;
Enums::VatType m_vat;
int m_count;
};
#endif // COMMODITYDATA_H

@ -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<CommodityTypeData *> (other);
return ct != NULL && this->id() == ct->id() ;
}
QString CommodityTypeData::toString()
{
return this->name();
}

@ -0,0 +1,36 @@
#ifndef COMMODITYTYPEDATA_H
#define COMMODITYTYPEDATA_H
#include <QObject>
#include <QString>
#include <odb/core.hxx>
#include <data/comboitem.h>
#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

@ -11,5 +11,6 @@
#include "combodata.h"
#include "settingsservice.h"
#include "settingsform.h"
#include "enums.h"
#endif // CORE_H

@ -2,7 +2,7 @@
GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent)
{
m_ic = 0;
}
QString GlobalSettings::firmName() const

@ -5,7 +5,7 @@ SUBDIRS += \
core \
application \
accommodation \
services
#commodity \
#addressbook
services \
commodity \
addressbook

@ -1,7 +1,8 @@
#include "accservice.h"
#include <define.h>
AccService::AccService()
AccService::AccService(QObject *parent)
:QObject(parent)
{
m_price = 0;
m_active = 1;

@ -24,7 +24,7 @@ class AccService : public QObject
Q_PROPERTY(Enums::VatType vatType READ vatType WRITE setVatType)
public:
AccService();
AccService(QObject *parent = 0);

Loading…
Cancel
Save