UI for load and save receipts.
This commit is contained in:
@@ -126,4 +126,6 @@ private:
|
|||||||
VoucherStatus m_status;
|
VoucherStatus m_status;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef QSharedPointer<Voucher> VoucherPtr;
|
||||||
|
|
||||||
#endif // VOUCHER_H
|
#endif // VOUCHER_H
|
||||||
|
|||||||
@@ -82,4 +82,6 @@ private:
|
|||||||
QWeakPointer<Voucher> m_voucher;
|
QWeakPointer<Voucher> m_voucher;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef QSharedPointer<VoucherItem> VoucherItemPtr;
|
||||||
|
|
||||||
#endif // VOUCHERITEM_H
|
#endif // VOUCHERITEM_H
|
||||||
|
|||||||
@@ -1,14 +1,58 @@
|
|||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
#include "receiptloadform.h"
|
#include "receiptloadform.h"
|
||||||
#include "ui_receiptloadform.h"
|
#include "ui_receiptloadform.h"
|
||||||
|
#include "shopservice.h"
|
||||||
|
#include "shop-odb.hxx"
|
||||||
|
|
||||||
ReceiptLoadForm::ReceiptLoadForm(QWidget *parent) :
|
ReceiptLoadForm::ReceiptLoadForm(QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::ReceiptLoadForm)
|
ui(new Ui::ReceiptLoadForm)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
m_voucherModel = new AutoTableModel<Voucher>(this);
|
||||||
|
ShopService srv;
|
||||||
|
m_voucherModel->setData(srv.all(QString("status = %1").arg(QString::number(Voucher::NOT_PAID))));
|
||||||
|
m_voucherModel->setTranslations(Context::instance().plugin("SHOP")->translations());
|
||||||
|
ui->tabVouchers->setModel(m_voucherModel);
|
||||||
|
ui->tabVouchers->hideColumn(3);
|
||||||
|
ui->tabVouchers->hideColumn(4);
|
||||||
|
ui->tabVouchers->hideColumn(5);
|
||||||
|
ui->tabVouchers->hideColumn(6);
|
||||||
|
ui->tabVouchers->hideColumn(7);
|
||||||
|
ui->tabVouchers->hideColumn(8);
|
||||||
|
ui->tabVouchers->hideColumn(10);
|
||||||
|
ui->tabVouchers->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||||
|
ui->tabVouchers->setColumnWidth(0, 190);
|
||||||
|
ui->tabVouchers->setColumnWidth(2, 200);
|
||||||
|
|
||||||
|
m_itemModel = new AutoTableModel<VoucherItem>(this);
|
||||||
|
ui->tabItems->setModel(m_itemModel);
|
||||||
|
|
||||||
|
connect(ui->tabVouchers->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](const QModelIndex ¤t, QModelIndex){
|
||||||
|
ShopService srv;
|
||||||
|
VoucherPtr voucher = m_voucherModel->itemFromIndex(current);
|
||||||
|
srv.loadItems(voucher);
|
||||||
|
m_itemModel->setData(voucher->items());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ReceiptLoadForm::~ReceiptLoadForm()
|
ReceiptLoadForm::~ReceiptLoadForm()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReceiptLoadForm::on_lineEdit_textChanged(const QString &text)
|
||||||
|
{
|
||||||
|
QSortFilterProxyModel proxy;
|
||||||
|
proxy.setSourceModel(m_voucherModel);
|
||||||
|
proxy.setFilterKeyColumn(0);
|
||||||
|
proxy.setFilterFixedString(text);
|
||||||
|
|
||||||
|
QModelIndex matchingIndex = proxy.mapToSource(proxy.index(0,0));
|
||||||
|
if(matchingIndex.isValid()){
|
||||||
|
ui->tabVouchers->scrollTo(matchingIndex,QAbstractItemView::EnsureVisible);
|
||||||
|
ui->tabVouchers->setCurrentIndex(matchingIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#define RECEIPTLOADFORM_H
|
#define RECEIPTLOADFORM_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include "data/voucher.h"
|
||||||
|
#include <autotablemodel.h>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ReceiptLoadForm;
|
class ReceiptLoadForm;
|
||||||
@@ -15,8 +17,13 @@ public:
|
|||||||
explicit ReceiptLoadForm(QWidget *parent = 0);
|
explicit ReceiptLoadForm(QWidget *parent = 0);
|
||||||
~ReceiptLoadForm();
|
~ReceiptLoadForm();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_lineEdit_textChanged(const QString &text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ReceiptLoadForm *ui;
|
Ui::ReceiptLoadForm *ui;
|
||||||
|
AutoTableModel<Voucher> *m_voucherModel;
|
||||||
|
AutoTableModel<VoucherItem> *m_itemModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RECEIPTLOADFORM_H
|
#endif // RECEIPTLOADFORM_H
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>454</width>
|
<width>804</width>
|
||||||
<height>483</height>
|
<height>500</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@@ -23,9 +23,6 @@
|
|||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QLineEdit" name="lineEdit"/>
|
<widget class="QLineEdit" name="lineEdit"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QTableView" name="tableView"/>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -33,6 +30,9 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="3" column="0" colspan="2">
|
||||||
|
<widget class="QTableView" name="tabVouchers"/>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableView" name="tableView_2"/>
|
<widget class="QTableView" name="tabItems"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
@@ -12,9 +12,10 @@
|
|||||||
#include <addressbookdata.h>
|
#include <addressbookdata.h>
|
||||||
|
|
||||||
#include "data/voucher.h"
|
#include "data/voucher.h"
|
||||||
|
#include "shopservice.h"
|
||||||
#include "shop-odb.hxx"
|
#include "shop-odb.hxx"
|
||||||
|
|
||||||
ReceiptSaveForm::ReceiptSaveForm(QWidget *parent) :
|
ReceiptSaveForm::ReceiptSaveForm(QSharedPointer<Voucher> voucher, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::ReceiptSaveForm)
|
ui(new Ui::ReceiptSaveForm)
|
||||||
{
|
{
|
||||||
@@ -22,7 +23,7 @@ ReceiptSaveForm::ReceiptSaveForm(QWidget *parent) :
|
|||||||
|
|
||||||
m_voucherModel = new AutoTableModel<Voucher>(this);
|
m_voucherModel = new AutoTableModel<Voucher>(this);
|
||||||
Service<Voucher> srv;
|
Service<Voucher> srv;
|
||||||
m_voucherModel->setData(srv.all());
|
m_voucherModel->setData(srv.all(QString("status = %1").arg(QString::number(Voucher::NOT_PAID))));
|
||||||
m_voucherModel->setTranslations(Context::instance().plugin("SHOP")->translations());
|
m_voucherModel->setTranslations(Context::instance().plugin("SHOP")->translations());
|
||||||
ui->tabVouchers->setModel(m_voucherModel);
|
ui->tabVouchers->setModel(m_voucherModel);
|
||||||
ui->tabVouchers->hideColumn(3);
|
ui->tabVouchers->hideColumn(3);
|
||||||
@@ -50,8 +51,11 @@ ReceiptSaveForm::ReceiptSaveForm(QWidget *parent) :
|
|||||||
comboData << ComboData(adb);
|
comboData << ComboData(adb);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_binder.setData(new Voucher);
|
m_voucher = voucher;
|
||||||
|
m_binder.setData(m_voucher.data());
|
||||||
m_binder.registerBinding(ui->contact, comboData);
|
m_binder.registerBinding(ui->contact, comboData);
|
||||||
|
m_binder.registerBinding(ui->name);
|
||||||
|
m_binder.registerBinding(ui->description);
|
||||||
m_binder.bindToUi();
|
m_binder.bindToUi();
|
||||||
|
|
||||||
ui->contact->completer()->setCompletionMode(QCompleter::PopupCompletion);
|
ui->contact->completer()->setCompletionMode(QCompleter::PopupCompletion);
|
||||||
@@ -102,3 +106,27 @@ void ReceiptSaveForm::on_radioAdd_toggled(bool checked)
|
|||||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!ui->name->text().isEmpty());
|
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!ui->name->text().isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReceiptSaveForm::accept()
|
||||||
|
{
|
||||||
|
ShopService srv;
|
||||||
|
m_binder.bindToData();
|
||||||
|
if (m_saveAsNew)
|
||||||
|
{
|
||||||
|
m_voucher->setStatus(Voucher::NOT_PAID);
|
||||||
|
srv.updateVoucher(m_voucher);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QSharedPointer<Voucher> voucher = m_voucherModel->itemFromIndex(ui->tabVouchers->currentIndex());
|
||||||
|
foreach (QSharedPointer<VoucherItem> item, m_voucher->items()) {
|
||||||
|
voucher->addItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
srv.calculate(voucher);
|
||||||
|
srv.updateVoucher(voucher);
|
||||||
|
srv.erase(m_voucher);
|
||||||
|
}
|
||||||
|
|
||||||
|
QDialog::accept();
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class ReceiptSaveForm : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ReceiptSaveForm(QWidget *parent = 0);
|
explicit ReceiptSaveForm(QSharedPointer<Voucher> voucher, QWidget *parent = 0);
|
||||||
~ReceiptSaveForm();
|
~ReceiptSaveForm();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@@ -28,6 +28,11 @@ private:
|
|||||||
ObjectBinder m_binder;
|
ObjectBinder m_binder;
|
||||||
AutoTableModel<Voucher> *m_voucherModel;
|
AutoTableModel<Voucher> *m_voucherModel;
|
||||||
bool m_saveAsNew;
|
bool m_saveAsNew;
|
||||||
|
QSharedPointer<Voucher> m_voucher;
|
||||||
|
|
||||||
|
// QDialog interface
|
||||||
|
public slots:
|
||||||
|
virtual void accept() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RECEIPTSAVEFORM_H
|
#endif // RECEIPTSAVEFORM_H
|
||||||
|
|||||||
+12
-2
@@ -96,13 +96,23 @@ void ShopForm::on_temporarySaveButton_clicked()
|
|||||||
|
|
||||||
void ShopForm::on_saveButton_clicked()
|
void ShopForm::on_saveButton_clicked()
|
||||||
{
|
{
|
||||||
ReceiptSaveForm *form = new ReceiptSaveForm;
|
ReceiptSaveForm *form = new ReceiptSaveForm(m_voucher, this);
|
||||||
|
form->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
|
connect(form, &QDialog::accepted, [this]() {
|
||||||
|
ShopService srv;
|
||||||
|
m_voucher = srv.createVoucher();
|
||||||
|
m_itemsModel->setData(m_voucher->items());
|
||||||
|
ui->total->setText("0");
|
||||||
|
});
|
||||||
|
|
||||||
form->show();
|
form->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShopForm::on_loadButton_clicked()
|
void ShopForm::on_loadButton_clicked()
|
||||||
{
|
{
|
||||||
ReceiptLoadForm *form = new ReceiptLoadForm;
|
ReceiptLoadForm *form = new ReceiptLoadForm(this);
|
||||||
|
form->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
form->show();
|
form->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user