cancel article / complete sale

This commit is contained in:
Martin Brodbeck 2018-07-23 13:39:49 +02:00
parent 3c318ffab9
commit 527241a0f3
7 changed files with 92 additions and 13 deletions

View file

@ -6,7 +6,7 @@
#include <regex>
#include <QItemSelectionModel>
#include <QMessageBox>
constexpr int STATUSBAR_TIMEOUT = 5000;
@ -28,9 +28,12 @@ MainWindow::MainWindow()
connect(ui_.sellerNoEdit, &QLineEdit::returnPressed, this,
&MainWindow::on_sellerNoEdit_checkSellerNo);
connect(ui_.paidButton, &QPushButton::clicked, this, &MainWindow::on_paidButton_triggered);
connect(ui_.basketView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&MainWindow::onBasketViewSelectionChanged);
connect(ui_.cancelArticleButton, &QPushButton::clicked, this,
&MainWindow::onCancelArticleButtonClicked);
connect(ui_.cancelAllArticlesButton, &QPushButton::clicked, this,
&MainWindow::onCancelAllArticlesButtonClicked);
}
void MainWindow::on_actionEditSeller_triggered()
@ -54,7 +57,6 @@ void MainWindow::on_paidButton_triggered()
if (marketplace_->basketSize() > 0) {
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
}
return;
}
void MainWindow::on_sellerNoEdit_checkSellerNo()
@ -93,11 +95,50 @@ void MainWindow::on_sellerNoEdit_checkSellerNo()
}
void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected,
[[maybe_unused]] const QItemSelection& deselected)
[[maybe_unused]] const QItemSelection& deselected)
{
if (selected.size() > 0) {
ui_.cancelArticleButton->setEnabled(true);
} else {
ui_.cancelArticleButton->setEnabled(false);
}
}
void MainWindow::onCancelArticleButtonClicked([[maybe_unused]] bool checked)
{
auto selModel = ui_.basketView->selectionModel();
if (selModel->hasSelection() == false)
return;
auto dlgResult =
QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?",
"Möchten Sie wirklich den Artikel stornieren?",
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this)
.exec();
if (dlgResult == QMessageBox::No)
return;
auto indexes = selModel->selectedRows();
std::sort(indexes.begin(), indexes.end());
// Deleting the rows, beginning with the last one!
for (auto iter = indexes.constEnd() - 1; iter >= indexes.constBegin(); --iter) {
ui_.basketView->model()->removeRow(iter->row());
}
}
void MainWindow::onCancelAllArticlesButtonClicked([[maybe_unused]] bool checked)
{
if (ui_.basketView->model()->rowCount() == 0)
return;
auto dlgResult =
QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?",
"Möchten Sie wirklich *alle* Artikel des aktuellen Einkaufs stornieren?",
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this)
.exec();
if (dlgResult == QMessageBox::No)
return;
dynamic_cast<BasketModel*>(ui_.basketView->model())->cancelSale();
}