Added recalculating receipt on item count changed. Some UI changes.

This commit is contained in:
2016-05-26 15:11:55 +02:00
parent 726da24de9
commit 9fbf216bba
12 changed files with 245 additions and 77 deletions
+25
View File
@@ -16,6 +16,7 @@ ShopForm::ShopForm(QWidget *parent) :
m_itemsModel = new AutoTableModel<VoucherItem>(this);
m_itemsModel->setEditableCols(QList<int>() << 1);
ui->actualReceipt->setModel(m_itemsModel);
ui->actualReceipt->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
}
ShopForm::~ShopForm()
@@ -31,6 +32,8 @@ void ShopForm::on_directSale_clicked()
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]);
connect(m_voucher->items()[m_voucher->items().count() - 1].data(), SIGNAL(countChanged()), this, SLOT(onCountChanged()));
onCountChanged();
});
form->show();
@@ -53,3 +56,25 @@ void ShopForm::on_loadButton_clicked()
ReceiptLoadForm *form = new ReceiptLoadForm;
form->show();
}
void ShopForm::onCountChanged()
{
VoucherItem *item = qobject_cast<VoucherItem*>(sender());
if (item != NULL && item->count() == 0)
{
for (int i = 0; i < m_voucher->items().count(); i++)
{
if (m_voucher->items()[i].data() == item)
{
m_voucher->removeItem(m_voucher->items()[i]);
m_itemsModel->setData(m_voucher->items());
}
}
}
ShopService srv;
srv.calculate(m_voucher);
ui->total->setText(m_voucher->totalPrice().toString());
//if (m_voucher->status())
}