Added data entities for shop plugin.

print
Josef Rokos 9 years ago
parent aa5b3cf76f
commit e06f951307

@ -10,6 +10,8 @@
#define PERM_DELETE "DELETE"
#define DEC_MULTIPLE 100
#define TO_DEC(num) QDecDouble((double)num / DEC_MULTIPLE)
#define FROM_DEC(num) num.toDouble() * DEC_MULTIPLE
#endif // DEFINE_H

@ -18,7 +18,7 @@ unix {
LIBS += -lodb -lodb-sqlite -lodb-qt
}
ODB_FLAGS = --database sqlite --profile qt --generate-schema --generate-query --generate-session --at-once --input-name $$TARGET --schema-format sql
ODB_FLAGS += --database sqlite --profile qt --generate-schema --generate-query --generate-session --at-once --input-name $$TARGET --schema-format sql
win32 {
ODB_PATH = d:\prac\odb\odb-2.4.0-i686-windows\bin\odb
@ -45,6 +45,7 @@ ODB_FLAGS += -I $$[QT_INSTALL_HEADERS]/QtCore
ODB_FLAGS += -I $$PWD/core
ODB_FLAGS += -I $$PWD/qdecimal/src
ODB_FLAGS += -I $$PWD/qdecimal/decnumber
ODB_FLAGS += $$ODB_OTHER_INCLUDES
ODB_FLAGS += -D __PIC__
win32 {

@ -0,0 +1,7 @@
#ifndef SHOPDATA_H
#define SHOPDATA_H
#include "voucher.h"
#include "voucheritem.h"
#endif // SHOPDATA_H

@ -1,6 +1,90 @@
#include "voucher.h"
#include <define.h>
Voucher::Voucher(QObject *parent) : QObject(parent)
{
}
QString Voucher::name() const
{
return m_name;
}
void Voucher::setName(const QString &name)
{
m_name = name;
}
QString Voucher::description() const
{
return m_description;
}
void Voucher::setDescription(const QString &description)
{
m_description = description;
}
QSharedPointer<QObject> Voucher::contact() const
{
return m_contact;
}
void Voucher::setContact(const QSharedPointer<QObject> &contact)
{
if (qobject_cast<AddressbookData*>(contact.data()) != NULL)
{
m_contact = qSharedPointerDynamicCast<AddressbookData, QObject>(contact);
}
}
Voucher::VoucherStatus Voucher::status() const
{
return m_status;
}
void Voucher::setStatus(const Voucher::VoucherStatus &status)
{
m_status = status;
}
QDecDouble Voucher::totalPrice() const
{
return TO_DEC(m_totalPrice);
}
void Voucher::setTotalPrice(QDecDouble totalPrice)
{
m_totalPrice = FROM_DEC(totalPrice);
}
QList<QSharedPointer<VoucherItem> > Voucher::items() const
{
return m_items;
}
void Voucher::setItems(const QList<QSharedPointer<VoucherItem> > &items)
{
m_items = items;
}
void Voucher::addItem(QSharedPointer<VoucherItem> item)
{
m_items.append(item);
}
void Voucher::clearItems()
{
m_items.clear();
}
int Voucher::id() const
{
return m_id;
}
void Voucher::setId(int id)
{
m_id = id;
}

@ -2,16 +2,72 @@
#define VOUCHER_H
#include <QObject>
#include <QDecDouble.hh>
#include <QString>
#include <QSharedPointer>
#include <addressbookdata.h>
#include <odb/core.hxx>
#include <odb/qt/list.hxx>
#include "voucheritem.h"
#pragma db object
class Voucher : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(QString description READ description WRITE setDescription)
Q_PROPERTY(QSharedPointer<QObject> contact READ contact WRITE setContact)
Q_PROPERTY(QDecDouble totalPrice READ totalPrice WRITE setTotalPrice)
Q_ENUMS(VoucherStatus)
Q_PROPERTY(VoucherStatus status READ status WRITE setStatus)
public:
explicit Voucher(QObject *parent = 0);
signals:
enum VoucherStatus
{
NEW,
TEMPORARY,
NOT_PAID,
PAID
};
int id() const;
void setId(int id);
QString name() const;
void setName(const QString &name);
QString description() const;
void setDescription(const QString &description);
QSharedPointer<QObject> contact() const;
void setContact(const QSharedPointer<QObject> &contact);
VoucherStatus status() const;
void setStatus(const VoucherStatus &status);
QDecDouble totalPrice() const;
void setTotalPrice(QDecDouble totalPrice);
QList<QSharedPointer<VoucherItem> > items() const;
void setItems(const QList<QSharedPointer<VoucherItem> > &items);
void addItem(QSharedPointer<VoucherItem> item);
void clearItems();
public slots:
private:
friend class odb::access;
#pragma db id auto
int m_id;
QString m_name;
QString m_description;
QSharedPointer<AddressbookData> m_contact;
int m_totalPrice;
QOdbList<QSharedPointer<VoucherItem> > m_items;
VoucherStatus m_status;
};
#endif // VOUCHER_H
#endif // VOUCHER_H

@ -0,0 +1,87 @@
#include "voucheritem.h"
#include <define.h>
VoucherItem::VoucherItem(QObject *parent) : QObject(parent)
{
}
int VoucherItem::id() const
{
return m_id;
}
void VoucherItem::setId(int id)
{
m_id = id;
}
QString VoucherItem::name() const
{
return m_name;
}
void VoucherItem::setName(const QString &name)
{
m_name = name;
}
int VoucherItem::count() const
{
return m_count;
}
void VoucherItem::setCount(int count)
{
m_count = count;
}
QDecDouble VoucherItem::unitPrice() const
{
return TO_DEC(m_unitPrice);
}
void VoucherItem::setUnitPrice(QDecDouble unitPrice)
{
m_unitPrice = FROM_DEC(unitPrice);
}
QDecDouble VoucherItem::price() const
{
return TO_DEC(m_price);
}
void VoucherItem::setPrice(QDecDouble price)
{
m_price = FROM_DEC(price);
}
int VoucherItem::refId() const
{
return m_refId;
}
void VoucherItem::setRefId(int refId)
{
m_refId = refId;
}
QString VoucherItem::itemPlugin() const
{
return m_itemPlugin;
}
void VoucherItem::setItemPlugin(const QString &itemPlugin)
{
m_itemPlugin = itemPlugin;
}
Enums::VatType VoucherItem::vatType() const
{
return m_vatType;
}
void VoucherItem::setVatType(const Enums::VatType &vatType)
{
m_vatType = vatType;
}

@ -0,0 +1,64 @@
#ifndef VOUCHERITEM_H
#define VOUCHERITEM_H
#include <QObject>
#include <QString>
#include <QDecDouble.hh>
#include <odb/core.hxx>
#include <enums.h>
#pragma db object
class VoucherItem : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(int count READ count WRITE setCount)
Q_PROPERTY(QDecDouble unitPrice READ unitPrice WRITE setUnitPrice)
Q_PROPERTY(QDecDouble price READ price WRITE setPrice)
Q_PROPERTY(int refId READ refId WRITE setRefId)
Q_PROPERTY(QString itemPlugin READ itemPlugin WRITE setItemPlugin)
Q_PROPERTY(Enums::VatType vatType READ vatType WRITE setVatType)
public:
explicit VoucherItem(QObject *parent = 0);
int id() const;
void setId(int id);
QString name() const;
void setName(const QString &name);
int count() const;
void setCount(int count);
QDecDouble unitPrice() const;
void setUnitPrice(QDecDouble unitPrice);
QDecDouble price() const;
void setPrice(QDecDouble price);
int refId() const;
void setRefId(int refId);
QString itemPlugin() const;
void setItemPlugin(const QString &itemPlugin);
Enums::VatType vatType() const;
void setVatType(const Enums::VatType &vatType);
private:
friend class odb::access;
#pragma db id auto
int m_id;
QString m_name;
int m_count;
int m_unitPrice;
int m_price;
int m_refId;
QString m_itemPlugin;
Enums::VatType m_vatType;
};
#endif // VOUCHERITEM_H

@ -0,0 +1,15 @@
#ifndef ISELLABLESERVICE_H
#define ISELLABLESERVICE_H
#include "shop_global.h"
#include "ishopitem.h"
#include <QList>
#include <QSharedPointer>
class SHOPSHARED_EXPORT ISellableService
{
public:
QList<QSharedPointer<IShopItem> > shopItems() = 0;
};
#endif // ISELLABLESERVICE_H

@ -0,0 +1,16 @@
#ifndef ISHOPITEM_H
#define ISHOPITEM_H
#include "shop_global.h"
#include <QDecDouble.hh>
#include <QString>
class SHOPSHARED_EXPORT IShopItem
{
public:
QString name() = 0;
QDecDouble unitPrice() = 0;
};
#endif // ISHOPITEM_H

@ -10,8 +10,46 @@
},
"schemaVersion" : 1,
"sql" : [
"CREATE TABLE \"VoucherItem\" (
\"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
\"name\" TEXT NULL,
\"count\" INTEGER NOT NULL,
\"unitPrice\" INTEGER NOT NULL,
\"price\" INTEGER NOT NULL,
\"refId\" INTEGER NOT NULL,
\"itemPlugin\" TEXT NULL,
\"vatType\" INTEGER NOT NULL);
CREATE TABLE \"Voucher\" (
\"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
\"name\" TEXT NULL,
\"description\" TEXT NULL,
\"contact\" INTEGER NULL,
\"totalPrice\" INTEGER NOT NULL,
\"status\" INTEGER NOT NULL,
CONSTRAINT \"contact_fk\"
FOREIGN KEY (\"contact\")
REFERENCES \"AddressbookData\" (\"id\")
DEFERRABLE INITIALLY DEFERRED);
CREATE TABLE \"Voucher_items\" (
\"object_id\" INTEGER NOT NULL,
\"index\" INTEGER NOT NULL,
\"value\" INTEGER NULL,
CONSTRAINT \"object_id_fk\"
FOREIGN KEY (\"object_id\")
REFERENCES \"Voucher\" (\"id\")
ON DELETE CASCADE,
CONSTRAINT \"value_fk\"
FOREIGN KEY (\"value\")
REFERENCES \"VoucherItem\" (\"id\")
DEFERRABLE INITIALLY DEFERRED);
CREATE INDEX \"Voucher_items_object_id_i\"
ON \"Voucher_items\" (\"object_id\");
CREATE INDEX \"Voucher_items_index_i\"
ON \"Voucher_items\" (\"index\");"
],
"dependencies" : []
"dependencies" : [ "ADDRESSBOOK" ]
}

@ -13,11 +13,16 @@ DEFINES += SHOP_LIBRARY\
_GLIBCXX_USE_CXX11_ABI=1
SOURCES += shop.cpp \
data/voucher.cpp
data/voucher.cpp \
data/voucheritem.cpp
HEADERS += shop.h\
shop_global.h \
data/voucher.h
data/voucher.h \
ishopitem.h \
data/voucheritem.h \
data/shop-data.h \
isellableservice.h
unix {
target.path = /usr/lib
@ -37,12 +42,20 @@ else:unix: LIBS += -L$$OUT_PWD/../core/ -lcore
INCLUDEPATH += $$PWD/../core
DEPENDPATH += $$PWD/../core
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -laddressbook
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../plugins/ -laddressbook
else:unix: LIBS += -L$$OUT_PWD/../plugins/ -laddressbook
INCLUDEPATH += $$PWD/../addressbook/data
DEPENDPATH += $$PWD/../addressbook
DESTDIR = ../plugins
OTHER_FILES += shop.json
#ODB_FILES = shop/data/....h
ODB_FILES = shop/data/shop-data.h
H_DIR = $$PWD/data/*.h
ODB_OTHER_INCLUDES = -I $$PWD/../addressbook/data
include(../odb.pri)
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../qdecimal/lib/ -lqdecimal -ldecnumber

Loading…
Cancel
Save