closes #4: Allowed to multiselect items on voucher and delete them via context menu or Ctrl+Del shortcut.
This commit is contained in:
+69
-23
@@ -14,6 +14,7 @@
|
|||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
#include <QItemSelectionModel>
|
||||||
#include "data/favorititem.h"
|
#include "data/favorititem.h"
|
||||||
#include "favbutton.h"
|
#include "favbutton.h"
|
||||||
|
|
||||||
@@ -71,6 +72,14 @@ ShopForm::ShopForm(QWidget *parent) :
|
|||||||
ui->temporarySaveButton->setEnabled(false);
|
ui->temporarySaveButton->setEnabled(false);
|
||||||
ui->saveButton->setEnabled(false);
|
ui->saveButton->setEnabled(false);
|
||||||
ui->payButton->setEnabled(false);
|
ui->payButton->setEnabled(false);
|
||||||
|
|
||||||
|
m_itemCtxMenu.reset(new QMenu());
|
||||||
|
m_itemCtxMenu->addAction(ui->actionDelete_items);
|
||||||
|
ui->actualReceipt->addAction(ui->actionDelete_items);
|
||||||
|
|
||||||
|
connect(ui->actualReceipt->selectionModel(), &QItemSelectionModel::selectionChanged, [this](const QItemSelection &selected, const QItemSelection &) {
|
||||||
|
ui->actionDelete_items->setEnabled(!selected.isEmpty());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ShopForm::~ShopForm()
|
ShopForm::~ShopForm()
|
||||||
@@ -341,29 +350,8 @@ void ShopForm::onCountChanged(int oldCount/* = 0*/)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ShopService srv;
|
recalculate();
|
||||||
srv.calculate(m_voucher);
|
updateItemCount(item, oldCount);
|
||||||
this->m_itemsModel->setData(m_voucher->items());
|
|
||||||
|
|
||||||
setTotalText();
|
|
||||||
ui->temporarySaveButton->setEnabled(!m_voucher->items().isEmpty());
|
|
||||||
ui->saveButton->setEnabled(!m_voucher->items().isEmpty());
|
|
||||||
ui->payButton->setEnabled(!m_voucher->items().isEmpty());
|
|
||||||
|
|
||||||
if (m_voucher->status() == Voucher::NEW && m_voucher->id() == 0)
|
|
||||||
{
|
|
||||||
srv.saveVoucher(m_voucher);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
srv.updateVoucher(m_voucher);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item != nullptr)
|
|
||||||
{
|
|
||||||
int countAdded = item->count() - oldCount;
|
|
||||||
srv.updateRelatedItem(item, countAdded);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShopForm::createVoucher()
|
void ShopForm::createVoucher()
|
||||||
@@ -502,6 +490,37 @@ void ShopForm::setTotalText()
|
|||||||
ui->priceNoVat->setText(QString::number(m_voucher->priceNoVat().toDouble(), 'f', 2));
|
ui->priceNoVat->setText(QString::number(m_voucher->priceNoVat().toDouble(), 'f', 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShopForm::updateItemCount(VoucherItem *item, int oldCount)
|
||||||
|
{
|
||||||
|
if (item != nullptr)
|
||||||
|
{
|
||||||
|
ShopService srv;
|
||||||
|
int countAdded = item->count() - oldCount;
|
||||||
|
srv.updateRelatedItem(item, countAdded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShopForm::recalculate()
|
||||||
|
{
|
||||||
|
ShopService srv;
|
||||||
|
srv.calculate(m_voucher);
|
||||||
|
this->m_itemsModel->setData(m_voucher->items());
|
||||||
|
|
||||||
|
setTotalText();
|
||||||
|
ui->temporarySaveButton->setEnabled(!m_voucher->items().isEmpty());
|
||||||
|
ui->saveButton->setEnabled(!m_voucher->items().isEmpty());
|
||||||
|
ui->payButton->setEnabled(!m_voucher->items().isEmpty());
|
||||||
|
|
||||||
|
if (m_voucher->status() == Voucher::NEW && m_voucher->id() == 0)
|
||||||
|
{
|
||||||
|
srv.saveVoucher(m_voucher);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
srv.updateVoucher(m_voucher);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ShopForm::on_receiptCombo_currentIndexChanged(int)
|
void ShopForm::on_receiptCombo_currentIndexChanged(int)
|
||||||
{
|
{
|
||||||
if (!m_voucher.isNull() && m_voucher->items().isEmpty())
|
if (!m_voucher.isNull() && m_voucher->items().isEmpty())
|
||||||
@@ -617,3 +636,30 @@ void ShopForm::on_commoditySearch_returnPressed()
|
|||||||
}
|
}
|
||||||
ui->commoditySearch->clear();
|
ui->commoditySearch->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShopForm::on_actionDelete_items_triggered()
|
||||||
|
{
|
||||||
|
if (QMessageBox::question(this, tr("Delete items"), tr("Realy delete selected voucher items?")) == QMessageBox::Yes) {
|
||||||
|
QList<VoucherItemPtr> forDelete;
|
||||||
|
|
||||||
|
for (const auto& row : ui->actualReceipt->selectionModel()->selectedIndexes()) {
|
||||||
|
forDelete << m_itemsModel->itemFromIndex(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& item : forDelete) {
|
||||||
|
m_voucher->removeItem(item);
|
||||||
|
int oldCount = item->count();
|
||||||
|
item->setCount(0);
|
||||||
|
updateItemCount(item.data(), oldCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
recalculate();
|
||||||
|
m_itemsModel->setData(m_voucher->items());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShopForm::on_actualReceipt_customContextMenuRequested(const QPoint &pos)
|
||||||
|
{
|
||||||
|
QPoint globalPos = ui->actualReceipt->mapToGlobal(pos);
|
||||||
|
m_itemCtxMenu->exec(globalPos);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <QScopedPointer>
|
||||||
|
#include <QMenu>
|
||||||
#include "data/shop-data.h"
|
#include "data/shop-data.h"
|
||||||
#include <autotablemodel.h>
|
#include <autotablemodel.h>
|
||||||
#include "settings/shopsettings.h"
|
#include "settings/shopsettings.h"
|
||||||
@@ -50,12 +52,18 @@ private slots:
|
|||||||
|
|
||||||
void on_commoditySearch_returnPressed();
|
void on_commoditySearch_returnPressed();
|
||||||
|
|
||||||
|
void on_actionDelete_items_triggered();
|
||||||
|
|
||||||
|
void on_actualReceipt_customContextMenuRequested(const QPoint &pos);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ShopForm *ui;
|
Ui::ShopForm *ui;
|
||||||
QSharedPointer<Voucher> m_voucher;
|
QSharedPointer<Voucher> m_voucher;
|
||||||
AutoTableModel<VoucherItem> *m_itemsModel;
|
AutoTableModel<VoucherItem> *m_itemsModel;
|
||||||
AutoTableModel<ShopItem> *m_commodityModel;
|
AutoTableModel<ShopItem> *m_commodityModel;
|
||||||
bool m_itemFound;
|
bool m_itemFound;
|
||||||
|
QScopedPointer<QMenu> m_itemCtxMenu;
|
||||||
|
|
||||||
void loadLast();
|
void loadLast();
|
||||||
void loadButtons(const ShopSettingsPtr& settings);
|
void loadButtons(const ShopSettingsPtr& settings);
|
||||||
@@ -67,6 +75,8 @@ private:
|
|||||||
void createEmptyVoucher();
|
void createEmptyVoucher();
|
||||||
void addItem(QSharedPointer<IShopItem> item, int count);
|
void addItem(QSharedPointer<IShopItem> item, int count);
|
||||||
void setTotalText();
|
void setTotalText();
|
||||||
|
void recalculate();
|
||||||
|
void updateItemCount(VoucherItem *item, int oldCount);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHOPFORM_H
|
#endif // SHOPFORM_H
|
||||||
|
|||||||
+15
-1
@@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>988</width>
|
<width>990</width>
|
||||||
<height>643</height>
|
<height>643</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@@ -174,6 +174,12 @@
|
|||||||
<height>0</height>
|
<height>0</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="contextMenuPolicy">
|
||||||
|
<enum>Qt::CustomContextMenu</enum>
|
||||||
|
</property>
|
||||||
|
<property name="selectionBehavior">
|
||||||
|
<enum>QAbstractItemView::SelectRows</enum>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@@ -599,6 +605,14 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
<action name="actionDelete_items">
|
||||||
|
<property name="text">
|
||||||
|
<string>Delete items</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+Del</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../core/rc.qrc"/>
|
<include location="../core/rc.qrc"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user