cancel sale button activated

This commit is contained in:
Martin Brodbeck 2018-07-27 16:04:01 +02:00
parent a130fa33c2
commit 99bc19f7a3
3 changed files with 41 additions and 1 deletions

View file

@ -36,8 +36,12 @@ MainWindow::MainWindow()
connect(ui_.paidButton, &QPushButton::clicked, this, &MainWindow::onPaidButtonTriggered); connect(ui_.paidButton, &QPushButton::clicked, this, &MainWindow::onPaidButtonTriggered);
connect(ui_.basketView->selectionModel(), &QItemSelectionModel::selectionChanged, this, connect(ui_.basketView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&MainWindow::onBasketViewSelectionChanged); &MainWindow::onBasketViewSelectionChanged);
connect(ui_.salesView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&MainWindow::onSalesViewSelectionChanged);
connect(ui_.cancelArticleButton, &QPushButton::clicked, this, connect(ui_.cancelArticleButton, &QPushButton::clicked, this,
&MainWindow::onCancelArticleButtonClicked); &MainWindow::onCancelArticleButtonClicked);
connect(ui_.cancelSaleButton, &QPushButton::clicked, this,
&MainWindow::onCancelSaleButtonClicked);
connect(ui_.cancelAllArticlesButton, &QPushButton::clicked, this, connect(ui_.cancelAllArticlesButton, &QPushButton::clicked, this,
&MainWindow::onCancelAllArticlesButtonClicked); &MainWindow::onCancelAllArticlesButtonClicked);
connect(static_cast<BasketModel*>(ui_.basketView->model()), &BasketModel::basketDataChanged, connect(static_cast<BasketModel*>(ui_.basketView->model()), &BasketModel::basketDataChanged,
@ -128,6 +132,16 @@ void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected,
} }
} }
void MainWindow::onSalesViewSelectionChanged(const QItemSelection& selected,
[[maybe_unused]] const QItemSelection& deselected)
{
if (selected.size() > 0) {
ui_.cancelSaleButton->setEnabled(true);
} else {
ui_.cancelSaleButton->setEnabled(false);
}
}
void MainWindow::onCancelArticleButtonClicked([[maybe_unused]] bool checked) void MainWindow::onCancelArticleButtonClicked([[maybe_unused]] bool checked)
{ {
auto selModel = ui_.basketView->selectionModel(); auto selModel = ui_.basketView->selectionModel();
@ -151,6 +165,29 @@ void MainWindow::onCancelArticleButtonClicked([[maybe_unused]] bool checked)
} }
} }
void MainWindow::onCancelSaleButtonClicked([[maybe_unused]] bool checked)
{
auto selModel = ui_.salesView->selectionModel();
if (selModel->hasSelection() == false)
return;
auto dlgResult =
QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?",
"Möchten Sie wirklich 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_.salesView->model()->removeRow(iter->row());
}
}
void MainWindow::onCancelAllArticlesButtonClicked([[maybe_unused]] bool checked) void MainWindow::onCancelAllArticlesButtonClicked([[maybe_unused]] bool checked)
{ {
if (ui_.basketView->model()->rowCount() == 0) if (ui_.basketView->model()->rowCount() == 0)

View file

@ -20,7 +20,10 @@ class MainWindow : public QMainWindow
private slots: private slots:
void onBasketViewSelectionChanged(const QItemSelection& selected, void onBasketViewSelectionChanged(const QItemSelection& selected,
const QItemSelection& deselected); const QItemSelection& deselected);
void onSalesViewSelectionChanged(const QItemSelection& selected,
const QItemSelection& deselected);
void onCancelArticleButtonClicked(bool checked); void onCancelArticleButtonClicked(bool checked);
void onCancelSaleButtonClicked(bool checked);
void onCancelAllArticlesButtonClicked(bool checked); void onCancelAllArticlesButtonClicked(bool checked);
private: private:

View file

@ -234,7 +234,7 @@
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QPushButton" name="pushButton"> <widget class="QPushButton" name="cancelSaleButton">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>