From 609003fc06f2b619c8629a812216934a53d7307a Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Mon, 23 Jul 2018 12:49:19 +0200 Subject: [PATCH] enable/disable button --- src/gui/mainwindow.cpp | 29 ++++++++++++++++++++++------- src/gui/mainwindow.h | 4 ++++ src/gui/mainwindow.ui | 4 ++-- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 8b03e70..ed90180 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -6,19 +6,14 @@ #include +#include + constexpr int STATUSBAR_TIMEOUT = 5000; MainWindow::MainWindow() { ui_.setupUi(this); - connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::quit); - connect(ui_.actionEditSeller, &QAction::triggered, this, - &MainWindow::on_actionEditSeller_triggered); - connect(ui_.sellerNoEdit, &QLineEdit::returnPressed, this, - &MainWindow::on_sellerNoEdit_checkSellerNo); - connect(ui_.paidButton, &QPushButton::clicked, this, &MainWindow::on_paidButton_triggered); - marketplace_ = std::make_unique(); marketplace_->loadFromDb(); statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT); @@ -26,6 +21,16 @@ MainWindow::MainWindow() BasketModel* model = new BasketModel(getMarketplace(), ui_.basketView); ui_.basketView->setModel(model); ui_.basketView->setColumnHidden(0, true); // hide the uuid + + connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::quit); + connect(ui_.actionEditSeller, &QAction::triggered, this, + &MainWindow::on_actionEditSeller_triggered); + 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); } void MainWindow::on_actionEditSeller_triggered() @@ -85,4 +90,14 @@ void MainWindow::on_sellerNoEdit_checkSellerNo() } ui_.sellerNoEdit->clear(); +} + +void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected, + [[maybe_unused]] const QItemSelection& deselected) +{ + if (selected.size() > 0) { + ui_.cancelArticleButton->setEnabled(true); + } else { + ui_.cancelArticleButton->setEnabled(false); + } } \ No newline at end of file diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 598129c..34e4334 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -17,6 +17,10 @@ class MainWindow : public QMainWindow MainWindow(); Marketplace* getMarketplace() { return marketplace_.get(); } + private slots: + void onBasketViewSelectionChanged(const QItemSelection& selected, + const QItemSelection& deselected); + private: void on_actionEditSeller_triggered(); void on_sellerNoEdit_checkSellerNo(); diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 8e3c4c4..eea630f 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -194,7 +194,7 @@ - + false @@ -204,7 +204,7 @@ - + false