UI for load and save receipts.
This commit is contained in:
@@ -126,4 +126,6 @@ private:
|
||||
VoucherStatus m_status;
|
||||
};
|
||||
|
||||
typedef QSharedPointer<Voucher> VoucherPtr;
|
||||
|
||||
#endif // VOUCHER_H
|
||||
|
||||
@@ -82,4 +82,6 @@ private:
|
||||
QWeakPointer<Voucher> m_voucher;
|
||||
};
|
||||
|
||||
typedef QSharedPointer<VoucherItem> VoucherItemPtr;
|
||||
|
||||
#endif // VOUCHERITEM_H
|
||||
|
||||
@@ -1,14 +1,58 @@
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
#include "receiptloadform.h"
|
||||
#include "ui_receiptloadform.h"
|
||||
#include "shopservice.h"
|
||||
#include "shop-odb.hxx"
|
||||
|
||||
ReceiptLoadForm::ReceiptLoadForm(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::ReceiptLoadForm)
|
||||
{
|
||||
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()
|
||||
{
|
||||
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
|
||||
|
||||
#include <QDialog>
|
||||
#include "data/voucher.h"
|
||||
#include <autotablemodel.h>
|
||||
|
||||
namespace Ui {
|
||||
class ReceiptLoadForm;
|
||||
@@ -15,8 +17,13 @@ public:
|
||||
explicit ReceiptLoadForm(QWidget *parent = 0);
|
||||
~ReceiptLoadForm();
|
||||
|
||||
private slots:
|
||||
void on_lineEdit_textChanged(const QString &text);
|
||||
|
||||
private:
|
||||
Ui::ReceiptLoadForm *ui;
|
||||
AutoTableModel<Voucher> *m_voucherModel;
|
||||
AutoTableModel<VoucherItem> *m_itemModel;
|
||||
};
|
||||
|
||||
#endif // RECEIPTLOADFORM_H
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>454</width>
|
||||
<height>483</height>
|
||||
<width>804</width>
|
||||
<height>500</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -23,9 +23,6 @@
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QTableView" name="tableView"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
@@ -33,6 +30,9 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QTableView" name="tabVouchers"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -43,7 +43,7 @@
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QTableView" name="tableView_2"/>
|
||||
<widget class="QTableView" name="tabItems"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
||||
@@ -12,9 +12,10 @@
|
||||
#include <addressbookdata.h>
|
||||
|
||||
#include "data/voucher.h"
|
||||
#include "shopservice.h"
|
||||
#include "shop-odb.hxx"
|
||||
|
||||
ReceiptSaveForm::ReceiptSaveForm(QWidget *parent) :
|
||||
ReceiptSaveForm::ReceiptSaveForm(QSharedPointer<Voucher> voucher, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::ReceiptSaveForm)
|
||||
{
|
||||
@@ -22,7 +23,7 @@ ReceiptSaveForm::ReceiptSaveForm(QWidget *parent) :
|
||||
|
||||
m_voucherModel = new AutoTableModel<Voucher>(this);
|
||||
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());
|
||||
ui->tabVouchers->setModel(m_voucherModel);
|
||||
ui->tabVouchers->hideColumn(3);
|
||||
@@ -50,8 +51,11 @@ ReceiptSaveForm::ReceiptSaveForm(QWidget *parent) :
|
||||
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->name);
|
||||
m_binder.registerBinding(ui->description);
|
||||
m_binder.bindToUi();
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
public:
|
||||
explicit ReceiptSaveForm(QWidget *parent = 0);
|
||||
explicit ReceiptSaveForm(QSharedPointer<Voucher> voucher, QWidget *parent = 0);
|
||||
~ReceiptSaveForm();
|
||||
|
||||
private slots:
|
||||
@@ -28,6 +28,11 @@ private:
|
||||
ObjectBinder m_binder;
|
||||
AutoTableModel<Voucher> *m_voucherModel;
|
||||
bool m_saveAsNew;
|
||||
QSharedPointer<Voucher> m_voucher;
|
||||
|
||||
// QDialog interface
|
||||
public slots:
|
||||
virtual void accept() override;
|
||||
};
|
||||
|
||||
#endif // RECEIPTSAVEFORM_H
|
||||
|
||||
+12
-2
@@ -96,13 +96,23 @@ void ShopForm::on_temporarySaveButton_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();
|
||||
}
|
||||
|
||||
void ShopForm::on_loadButton_clicked()
|
||||
{
|
||||
ReceiptLoadForm *form = new ReceiptLoadForm;
|
||||
ReceiptLoadForm *form = new ReceiptLoadForm(this);
|
||||
form->setAttribute(Qt::WA_DeleteOnClose);
|
||||
form->show();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user