Merge branch 'master' of https://git.bukova.info/repos/git/prodejna
This commit is contained in:
@@ -12,5 +12,6 @@
|
|||||||
#include "settingsservice.h"
|
#include "settingsservice.h"
|
||||||
#include "settingsform.h"
|
#include "settingsform.h"
|
||||||
#include "enums.h"
|
#include "enums.h"
|
||||||
|
#include "objectbinder.h"
|
||||||
|
|
||||||
#endif // CORE_H
|
#endif // CORE_H
|
||||||
|
|||||||
+4
-2
@@ -51,7 +51,8 @@ SOURCES += \
|
|||||||
settings/globalsettings.cpp \
|
settings/globalsettings.cpp \
|
||||||
settingsform.cpp \
|
settingsform.cpp \
|
||||||
settings/globalsettingsform.cpp \
|
settings/globalsettingsform.cpp \
|
||||||
permissionevaluator.cpp
|
permissionevaluator.cpp \
|
||||||
|
objectbinder.cpp
|
||||||
|
|
||||||
HEADERS += core.h\
|
HEADERS += core.h\
|
||||||
core_global.h \
|
core_global.h \
|
||||||
@@ -102,7 +103,8 @@ HEADERS += core.h\
|
|||||||
settingsform.h \
|
settingsform.h \
|
||||||
settings/globalsettingsform.h \
|
settings/globalsettingsform.h \
|
||||||
formbinder.h \
|
formbinder.h \
|
||||||
permissionevaluator.h
|
permissionevaluator.h \
|
||||||
|
objectbinder.h
|
||||||
|
|
||||||
unix {
|
unix {
|
||||||
target.path = /usr/lib
|
target.path = /usr/lib
|
||||||
|
|||||||
+14
-74
@@ -11,6 +11,7 @@
|
|||||||
#include "combodata.h"
|
#include "combodata.h"
|
||||||
#include "ivalidator.h"
|
#include "ivalidator.h"
|
||||||
#include "iform.h"
|
#include "iform.h"
|
||||||
|
#include "objectbinder.h"
|
||||||
|
|
||||||
#include "../qdecimal/src/QDecDouble.hh"
|
#include "../qdecimal/src/QDecDouble.hh"
|
||||||
|
|
||||||
@@ -19,31 +20,31 @@ class FormBinder : public IForm
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit FormBinder(QWidget *parent = NULL) : IForm(parent) {}
|
explicit FormBinder(QWidget *parent = NULL) : IForm(parent) {
|
||||||
|
connect(&m_binder, &ObjectBinder::validationError, [this](QString msg){
|
||||||
|
emit this->validationError(msg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
virtual ~FormBinder() {
|
virtual ~FormBinder() {
|
||||||
foreach (IValidator *val, m_validators) {
|
|
||||||
delete val;
|
|
||||||
}
|
|
||||||
m_validators.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerBinding(QWidget *widget) {
|
void registerBinding(QWidget *widget) {
|
||||||
if (!m_bindWidgets.contains(widget)) {
|
m_binder.registerBinding(widget);
|
||||||
m_bindWidgets.append(widget);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerBinding(QComboBox *combo, const QList<ComboData> &values) {
|
void registerBinding(QComboBox *combo, const QList<ComboData> &values) {
|
||||||
m_bindCombos[combo] = values;
|
m_binder.registerBinding(combo, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerValidator(IValidator *validator) {
|
void registerValidator(IValidator *validator) {
|
||||||
m_validators.append(validator);
|
m_binder.registerValidator(validator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setEntity(QSharedPointer<T> entity) {
|
void setEntity(QSharedPointer<T> entity) {
|
||||||
m_entity = entity;
|
m_entity = entity;
|
||||||
|
m_binder.setData(m_entity.data());
|
||||||
bindToUi();
|
bindToUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,77 +61,16 @@ protected:
|
|||||||
|
|
||||||
void bindToUi() {
|
void bindToUi() {
|
||||||
registerCombos();
|
registerCombos();
|
||||||
foreach (QWidget *widget, m_bindWidgets) {
|
m_binder.bindToUi();
|
||||||
const char* prop = widget->metaObject()->userProperty().name();
|
|
||||||
QVariant value = ((QObject*)m_entity.data())->property(widget->objectName().toStdString().c_str());
|
|
||||||
if (value.canConvert<QDecDouble>())
|
|
||||||
{
|
|
||||||
widget->setProperty(prop, value.value<QDecDouble>().toString());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
widget->setProperty(prop, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (QComboBox *combo, m_bindCombos.keys()) {
|
|
||||||
int idx = 0;
|
|
||||||
QVariant field = ((QObject*)m_entity.data())->property(combo->objectName().toStdString().c_str());
|
|
||||||
|
|
||||||
combo->clear();
|
|
||||||
for (int i = 0; i < m_bindCombos[combo].size(); i++) {
|
|
||||||
ComboData data = m_bindCombos[combo][i];
|
|
||||||
combo->addItem(data.label(), data.index());
|
|
||||||
|
|
||||||
if (data.index().canConvert<QObject*>()) {
|
|
||||||
ComboItem* ci = qobject_cast<ComboItem*>(data.index().value<QObject*>());
|
|
||||||
ComboItem* ciField = qobject_cast<ComboItem*>(field.value<QObject*>());
|
|
||||||
if (ci->eq(ciField)) {
|
|
||||||
idx = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (field == data.index()) {
|
|
||||||
idx = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
combo->setCurrentIndex(idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
bindOtherToUi();
|
bindOtherToUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bindToData() {
|
bool bindToData() {
|
||||||
foreach (IValidator *val, m_validators) {
|
return m_binder.bindToData() && bindOtherToData();
|
||||||
if (!val->validate()) {
|
|
||||||
emit validationError(val->errMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (QWidget *widget, m_bindWidgets) {
|
|
||||||
const char* prop = widget->metaObject()->userProperty().name();
|
|
||||||
|
|
||||||
QVariant val = widget->property(prop);
|
|
||||||
if (((QObject*)m_entity.data())->property(widget->objectName().toStdString().c_str()).canConvert<QDecDouble>())
|
|
||||||
{
|
|
||||||
QDecDouble dec(val.toDouble());
|
|
||||||
val = QVariant::fromValue(dec);
|
|
||||||
}
|
|
||||||
((QObject*)m_entity.data())->setProperty(widget->objectName().toStdString().c_str(), val);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (QComboBox *combo, m_bindCombos.keys()) {
|
|
||||||
((QObject*)m_entity.data())->setProperty(combo->objectName().toStdString().c_str(), combo->currentData());
|
|
||||||
}
|
|
||||||
|
|
||||||
return bindOtherToData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<QWidget*> m_bindWidgets;
|
ObjectBinder m_binder;
|
||||||
QHash<QComboBox*, QList<ComboData> > m_bindCombos;
|
|
||||||
QList<IValidator*> m_validators;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FORMBINDER_H
|
#endif // FORMBINDER_H
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
#include "objectbinder.h"
|
||||||
|
#include <QDecDouble.hh>
|
||||||
|
|
||||||
|
ObjectBinder::ObjectBinder(QObject *parent)
|
||||||
|
:QObject(parent)
|
||||||
|
{
|
||||||
|
m_data = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectBinder::registerBinding(QWidget *widget) {
|
||||||
|
if (!m_bindWidgets.contains(widget)) {
|
||||||
|
m_bindWidgets.append(widget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectBinder::registerBinding(QComboBox *combo, const QList<ComboData> &values) {
|
||||||
|
m_bindCombos[combo] = values;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectBinder::registerValidator(IValidator *validator) {
|
||||||
|
m_validators.append(validator);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectBinder::setData(QObject *data)
|
||||||
|
{
|
||||||
|
m_data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectBinder::bindToUi() {
|
||||||
|
foreach (QWidget *widget, m_bindWidgets) {
|
||||||
|
const char* prop = widget->metaObject()->userProperty().name();
|
||||||
|
QVariant value = m_data->property(widget->objectName().toStdString().c_str());
|
||||||
|
if (value.canConvert<QDecDouble>())
|
||||||
|
{
|
||||||
|
widget->setProperty(prop, value.value<QDecDouble>().toString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
widget->setProperty(prop, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (QComboBox *combo, m_bindCombos.keys()) {
|
||||||
|
int idx = 0;
|
||||||
|
QVariant field = m_data->property(combo->objectName().toStdString().c_str());
|
||||||
|
|
||||||
|
combo->clear();
|
||||||
|
for (int i = 0; i < m_bindCombos[combo].size(); i++) {
|
||||||
|
ComboData data = m_bindCombos[combo][i];
|
||||||
|
combo->addItem(data.label(), data.index());
|
||||||
|
|
||||||
|
if (data.index().canConvert<QObject*>()) {
|
||||||
|
ComboItem* ci = qobject_cast<ComboItem*>(data.index().value<QObject*>());
|
||||||
|
ComboItem* ciField = qobject_cast<ComboItem*>(field.value<QObject*>());
|
||||||
|
if (ci->eq(ciField)) {
|
||||||
|
idx = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (field == data.index()) {
|
||||||
|
idx = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
combo->setCurrentIndex(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ObjectBinder::bindToData() {
|
||||||
|
foreach (IValidator *val, m_validators) {
|
||||||
|
if (!val->validate()) {
|
||||||
|
emit validationError(val->errMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (QWidget *widget, m_bindWidgets) {
|
||||||
|
const char* prop = widget->metaObject()->userProperty().name();
|
||||||
|
|
||||||
|
QVariant val = widget->property(prop);
|
||||||
|
if (m_data->property(widget->objectName().toStdString().c_str()).canConvert<QDecDouble>())
|
||||||
|
{
|
||||||
|
QDecDouble dec(val.toDouble());
|
||||||
|
val = QVariant::fromValue(dec);
|
||||||
|
}
|
||||||
|
m_data->setProperty(widget->objectName().toStdString().c_str(), val);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (QComboBox *combo, m_bindCombos.keys()) {
|
||||||
|
m_data->setProperty(combo->objectName().toStdString().c_str(), combo->currentData());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef OBJECTBINDER_H
|
||||||
|
#define OBJECTBINDER_H
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QMetaProperty>
|
||||||
|
#include "ivalidator.h"
|
||||||
|
#include "combodata.h"
|
||||||
|
#include "core_global.h"
|
||||||
|
|
||||||
|
class CORESHARED_EXPORT ObjectBinder : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ObjectBinder(QObject *parent = NULL);
|
||||||
|
|
||||||
|
void registerBinding(QWidget *widget);
|
||||||
|
void registerBinding(QComboBox *combo, const QList<ComboData> &values);
|
||||||
|
void registerValidator(IValidator *validator);
|
||||||
|
void setData(QObject *data);
|
||||||
|
void bindToUi();
|
||||||
|
bool bindToData();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void validationError(QString msg);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<QWidget*> m_bindWidgets;
|
||||||
|
QHash<QComboBox*, QList<ComboData> > m_bindCombos;
|
||||||
|
QList<IValidator*> m_validators;
|
||||||
|
QObject *m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // OBJECTBINDER_H
|
||||||
@@ -3,7 +3,10 @@
|
|||||||
|
|
||||||
VoucherItem::VoucherItem(QObject *parent) : QObject(parent)
|
VoucherItem::VoucherItem(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
m_price = 0;
|
||||||
|
m_unitPrice = 0;
|
||||||
|
m_count = 0;
|
||||||
|
m_refId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VoucherItem::id() const
|
int VoucherItem::id() const
|
||||||
|
|||||||
@@ -17,8 +17,6 @@ class VoucherItem : public QObject
|
|||||||
Q_PROPERTY(int count READ count WRITE setCount)
|
Q_PROPERTY(int count READ count WRITE setCount)
|
||||||
Q_PROPERTY(QDecDouble unitPrice READ unitPrice WRITE setUnitPrice)
|
Q_PROPERTY(QDecDouble unitPrice READ unitPrice WRITE setUnitPrice)
|
||||||
Q_PROPERTY(QDecDouble price READ price WRITE setPrice)
|
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)
|
Q_PROPERTY(Enums::VatType vatType READ vatType WRITE setVatType)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -6,9 +6,32 @@ DirectSaleForm::DirectSaleForm(QWidget *parent) :
|
|||||||
ui(new Ui::DirectSaleForm)
|
ui(new Ui::DirectSaleForm)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
m_shopItem = QSharedPointer<DirectSaleItem>(new DirectSaleItem);
|
||||||
|
|
||||||
|
m_binder.setData(m_shopItem.data());
|
||||||
|
m_binder.registerBinding(ui->name);
|
||||||
|
m_binder.registerBinding(ui->unitPrice);
|
||||||
|
m_binder.registerBinding(ui->count);
|
||||||
|
m_binder.bindToUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
DirectSaleForm::~DirectSaleForm()
|
DirectSaleForm::~DirectSaleForm()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSharedPointer<IShopItem> DirectSaleForm::shopItem() const
|
||||||
|
{
|
||||||
|
return m_shopItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectSaleForm::on_buttonBox_rejected()
|
||||||
|
{
|
||||||
|
this->reject();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectSaleForm::on_buttonBox_accepted()
|
||||||
|
{
|
||||||
|
m_binder.bindToData();
|
||||||
|
this->accept();
|
||||||
|
}
|
||||||
|
|||||||
+15
-1
@@ -2,7 +2,12 @@
|
|||||||
#define DIRECTSALEFORM_H
|
#define DIRECTSALEFORM_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include<QWidget>
|
#include <QWidget>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
#include <core.h>
|
||||||
|
|
||||||
|
#include "ishopitem.h"
|
||||||
|
#include "directsaleitem.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class DirectSaleForm;
|
class DirectSaleForm;
|
||||||
@@ -16,8 +21,17 @@ public:
|
|||||||
explicit DirectSaleForm(QWidget *parent = 0);
|
explicit DirectSaleForm(QWidget *parent = 0);
|
||||||
~DirectSaleForm();
|
~DirectSaleForm();
|
||||||
|
|
||||||
|
QSharedPointer<IShopItem> shopItem() const;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_buttonBox_rejected();
|
||||||
|
|
||||||
|
void on_buttonBox_accepted();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::DirectSaleForm *ui;
|
Ui::DirectSaleForm *ui;
|
||||||
|
ObjectBinder m_binder;
|
||||||
|
QSharedPointer<DirectSaleItem> m_shopItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DIRECTSALEFORM_H
|
#endif // DIRECTSALEFORM_H
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLineEdit" name="commodityName"/>
|
<widget class="QLineEdit" name="name"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="priceLabel">
|
<widget class="QLabel" name="priceLabel">
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QDoubleSpinBox" name="price"/>
|
<widget class="QDoubleSpinBox" name="unitPrice"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="countLabel">
|
<widget class="QLabel" name="countLabel">
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
#include "directsaleitem.h"
|
||||||
|
|
||||||
|
DirectSaleItem::DirectSaleItem(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
m_count = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DirectSaleItem::id()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DirectSaleItem::name()
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDecDouble DirectSaleItem::unitPrice()
|
||||||
|
{
|
||||||
|
return m_unitPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DirectSaleItem::pluginId()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
int DirectSaleItem::count() const
|
||||||
|
{
|
||||||
|
return m_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectSaleItem::setCount(int count)
|
||||||
|
{
|
||||||
|
m_count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectSaleItem::setName(const QString &name)
|
||||||
|
{
|
||||||
|
m_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DirectSaleItem::setUnitPrice(const QDecDouble &unitPrice)
|
||||||
|
{
|
||||||
|
m_unitPrice = unitPrice;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#ifndef DIRECTSALEITEM_H
|
||||||
|
#define DIRECTSALEITEM_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
#include "ishopitem.h"
|
||||||
|
|
||||||
|
class DirectSaleItem : public QObject, public IShopItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString name READ name WRITE setName)
|
||||||
|
Q_PROPERTY(QDecDouble unitPrice READ unitPrice WRITE setUnitPrice)
|
||||||
|
Q_PROPERTY(int count READ count WRITE setCount)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DirectSaleItem(QObject *parent = 0);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
// IShopItem interface
|
||||||
|
public:
|
||||||
|
int id() override;
|
||||||
|
QString name() override;
|
||||||
|
QDecDouble unitPrice() override;
|
||||||
|
QString pluginId() override;
|
||||||
|
|
||||||
|
int count() const;
|
||||||
|
void setCount(int count);
|
||||||
|
|
||||||
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
void setUnitPrice(const QDecDouble &unitPrice);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_name;
|
||||||
|
QDecDouble m_unitPrice;
|
||||||
|
int m_count;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DIRECTSALEITEM_H
|
||||||
+4
-2
@@ -9,8 +9,10 @@ class SHOPSHARED_EXPORT IShopItem
|
|||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QString name() = 0;
|
virtual int id() = 0;
|
||||||
QDecDouble unitPrice() = 0;
|
virtual QString name() = 0;
|
||||||
|
virtual QDecDouble unitPrice() = 0;
|
||||||
|
virtual QString pluginId() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ISHOPITEM_H
|
#endif // ISHOPITEM_H
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "shop.h"
|
#include "shop.h"
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include "shopform.h"
|
#include "shopform.h"
|
||||||
|
#include "shopservice.h"
|
||||||
|
|
||||||
|
|
||||||
Shop::Shop()
|
Shop::Shop()
|
||||||
@@ -10,6 +11,7 @@ Shop::Shop()
|
|||||||
void Shop::initServiceUi()
|
void Shop::initServiceUi()
|
||||||
{
|
{
|
||||||
m_ui = new ShopForm();
|
m_ui = new ShopForm();
|
||||||
|
m_service = new ShopService();
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon Shop::pluginIcon()
|
QIcon Shop::pluginIcon()
|
||||||
|
|||||||
+7
-3
@@ -18,8 +18,10 @@ SOURCES += shop.cpp \
|
|||||||
directsaleform.cpp \
|
directsaleform.cpp \
|
||||||
temporaryreceiptsaveform.cpp \
|
temporaryreceiptsaveform.cpp \
|
||||||
receiptsaveform.cpp \
|
receiptsaveform.cpp \
|
||||||
receiptloadform.cpp
|
receiptloadform.cpp \
|
||||||
data/voucheritem.cpp
|
data/voucheritem.cpp \
|
||||||
|
shopservice.cpp \
|
||||||
|
directsaleitem.cpp
|
||||||
|
|
||||||
HEADERS += shop.h\
|
HEADERS += shop.h\
|
||||||
shop_global.h \
|
shop_global.h \
|
||||||
@@ -32,7 +34,9 @@ HEADERS += shop.h\
|
|||||||
ishopitem.h \
|
ishopitem.h \
|
||||||
data/voucheritem.h \
|
data/voucheritem.h \
|
||||||
data/shop-data.h \
|
data/shop-data.h \
|
||||||
isellableservice.h
|
isellableservice.h \
|
||||||
|
shopservice.h \
|
||||||
|
directsaleitem.h
|
||||||
|
|
||||||
unix {
|
unix {
|
||||||
target.path = /usr/lib
|
target.path = /usr/lib
|
||||||
|
|||||||
@@ -4,12 +4,17 @@
|
|||||||
#include "temporaryreceiptsaveform.h"
|
#include "temporaryreceiptsaveform.h"
|
||||||
#include "receiptsaveform.h"
|
#include "receiptsaveform.h"
|
||||||
#include "receiptloadform.h"
|
#include "receiptloadform.h"
|
||||||
|
#include "shopservice.h"
|
||||||
|
|
||||||
ShopForm::ShopForm(QWidget *parent) :
|
ShopForm::ShopForm(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::ShopForm)
|
ui(new Ui::ShopForm)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
ShopService srv;
|
||||||
|
m_voucher = srv.createVoucher();
|
||||||
|
m_itemsModel = new AutoTableModel<VoucherItem>(this);
|
||||||
|
ui->actualReceipt->setModel(m_itemsModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
ShopForm::~ShopForm()
|
ShopForm::~ShopForm()
|
||||||
@@ -20,6 +25,13 @@ ShopForm::~ShopForm()
|
|||||||
void ShopForm::on_directSale_clicked()
|
void ShopForm::on_directSale_clicked()
|
||||||
{
|
{
|
||||||
DirectSaleForm *form = new DirectSaleForm(this);
|
DirectSaleForm *form = new DirectSaleForm(this);
|
||||||
|
|
||||||
|
connect(form, &QDialog::accepted, [this, form](){
|
||||||
|
ShopService srv;
|
||||||
|
srv.addShopItem(m_voucher, form->shopItem(), ((DirectSaleItem*)form->shopItem().data())->count());
|
||||||
|
this->m_itemsModel->addRow(m_voucher->items()[m_voucher->items().count() - 1]);
|
||||||
|
});
|
||||||
|
|
||||||
form->show();
|
form->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
#define SHOPFORM_H
|
#define SHOPFORM_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QList>
|
||||||
|
#include "data/shop-data.h"
|
||||||
|
#include <autotablemodel.h>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ShopForm;
|
class ShopForm;
|
||||||
@@ -26,6 +29,8 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ShopForm *ui;
|
Ui::ShopForm *ui;
|
||||||
|
QSharedPointer<Voucher> m_voucher;
|
||||||
|
AutoTableModel<VoucherItem> *m_itemsModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHOPFORM_H
|
#endif // SHOPFORM_H
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#include "shopservice.h"
|
||||||
|
|
||||||
|
ShopService::ShopService()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QSharedPointer<Voucher> ShopService::createVoucher()
|
||||||
|
{
|
||||||
|
QSharedPointer<Voucher> voucher(new Voucher);
|
||||||
|
voucher->setStatus(Voucher::NEW);
|
||||||
|
return voucher;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShopService::addShopItem(QSharedPointer<Voucher> voucher, QSharedPointer<IShopItem> item, int count)
|
||||||
|
{
|
||||||
|
QSharedPointer<VoucherItem> vItem(new VoucherItem);
|
||||||
|
vItem->setName(item->name());
|
||||||
|
vItem->setUnitPrice(item->unitPrice());
|
||||||
|
vItem->setCount(count);
|
||||||
|
vItem->setRefId(item->id());
|
||||||
|
vItem->setItemPlugin(item->pluginId());
|
||||||
|
|
||||||
|
voucher->addItem(vItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShopService::calculate(QSharedPointer<Voucher> voucher)
|
||||||
|
{
|
||||||
|
QDecDouble total;
|
||||||
|
|
||||||
|
foreach (QSharedPointer<VoucherItem> item, voucher->items()) {
|
||||||
|
QDecDouble itemPrice = item->unitPrice() * item->count();
|
||||||
|
total += itemPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
voucher->setTotalPrice(total);
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef SHOPSERVICE_H
|
||||||
|
#define SHOPSERVICE_H
|
||||||
|
|
||||||
|
#include <QSharedPointer>
|
||||||
|
|
||||||
|
#include <core.h>
|
||||||
|
|
||||||
|
#include "data/shop-data.h"
|
||||||
|
#include "ishopitem.h"
|
||||||
|
|
||||||
|
class ShopService : public Service<Voucher>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ShopService();
|
||||||
|
QSharedPointer<Voucher> createVoucher();
|
||||||
|
void addShopItem(QSharedPointer<Voucher> voucher, QSharedPointer<IShopItem> item, int count);
|
||||||
|
void calculate(QSharedPointer<Voucher> voucher);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SHOPSERVICE_H
|
||||||
Reference in New Issue
Block a user