From 6f84de2b6cb802fbb08d9da6c5e58d24c5f7f716 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Tue, 21 Jun 2016 14:40:14 +0200 Subject: [PATCH] Ok button on ReceiptSaveForm is now disabled if nothing is selected in grid or name field is empty. --- shop/receiptsaveform.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/shop/receiptsaveform.cpp b/shop/receiptsaveform.cpp index 4d7fbf1..f3dd4e8 100644 --- a/shop/receiptsaveform.cpp +++ b/shop/receiptsaveform.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -35,6 +36,14 @@ ReceiptSaveForm::ReceiptSaveForm(QWidget *parent) : ui->tabVouchers->setColumnWidth(0, 190); ui->tabVouchers->setColumnWidth(2, 200); + connect(ui->tabVouchers->selectionModel(), &QItemSelectionModel::currentRowChanged, [this](QModelIndex, QModelIndex){ + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); + }); + + connect(ui->name, &QLineEdit::textChanged, [this](QString text){ + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty()); + }); + AddressBookService srvAdb; QList comboData; foreach (QSharedPointer adb, srvAdb.all()) { @@ -50,6 +59,8 @@ ReceiptSaveForm::ReceiptSaveForm(QWidget *parent) : m_saveAsNew = false; ui->groupBox_2->setEnabled(false); + + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); } ReceiptSaveForm::~ReceiptSaveForm() @@ -68,6 +79,7 @@ void ReceiptSaveForm::on_lineEdit_textChanged(const QString &text) if(matchingIndex.isValid()){ ui->tabVouchers->scrollTo(matchingIndex,QAbstractItemView::EnsureVisible); ui->tabVouchers->setCurrentIndex(matchingIndex); + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); } } @@ -78,11 +90,15 @@ void ReceiptSaveForm::on_radioAdd_toggled(bool checked) m_saveAsNew = false; ui->groupBox_2->setEnabled(false); ui->groupBox->setEnabled(true); + + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ui->tabVouchers->currentIndex().isValid()); } else { m_saveAsNew = true; ui->groupBox_2->setEnabled(true); ui->groupBox->setEnabled(false); + + ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!ui->name->text().isEmpty()); } }