From eb20d269bb30dd2d2976d2754cc792abc80cde38 Mon Sep 17 00:00:00 2001 From: Arturs Bekasovs Date: Wed, 20 Nov 2013 11:57:18 +0000 Subject: [PATCH] Refs #6473. Enabling/disabling start button on input change. --- .../MuonSequentialFitDialog.h | 9 +++- .../src/MuonSequentialFitDialog.cpp | 41 ++++++++++++++++++- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MuonSequentialFitDialog.h b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MuonSequentialFitDialog.h index 79ea8bd07e68..a8de1c12ce2e 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MuonSequentialFitDialog.h +++ b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MuonSequentialFitDialog.h @@ -48,6 +48,9 @@ namespace MantidWidgets /// UI form Ui::MuonSequentialFitDialog ui; + /// Check if all the input field are valid + bool isInputValid(); + /// Checks if specified name is valid as a name for label. static std::string isValidLabel(const std::string& label); @@ -55,9 +58,11 @@ namespace MantidWidgets static Mantid::Kernel::Logger& g_log; private slots: - /// Updates visibility/tooltip of label error asterisk - void validateLabel(const QString& label); + void updateLabelError(const QString& label); + + /// Enables/disables start button depending on wether we are allowed to start. + void updateStartButton(); }; diff --git a/Code/Mantid/MantidQt/MantidWidgets/src/MuonSequentialFitDialog.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/MuonSequentialFitDialog.cpp index 15aa7c775f36..7212c292d2ca 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/src/MuonSequentialFitDialog.cpp +++ b/Code/Mantid/MantidQt/MantidWidgets/src/MuonSequentialFitDialog.cpp @@ -18,8 +18,21 @@ namespace MantidWidgets { ui.setupUi(this); + // TODO: set initial values + + // After initial values are set, update depending elements accordingly. We don't rely on + // slot/signal update, as element might be left with default values which means these will + // never be called on initialication. + updateLabelError( ui.labelInput->text() ); + updateStartButton(); + + connect( ui.labelInput, SIGNAL( textChanged(const QString&) ), + this, SLOT( updateLabelError(const QString&) ) ); + connect( ui.labelInput, SIGNAL( textChanged(const QString&) ), - this, SLOT( validateLabel(const QString&) ) ); + this, SLOT( updateStartButton() ) ); + connect( ui.runs, SIGNAL( fileFindingFinished() ), + this, SLOT( updateStartButton() ) ); } /** @@ -39,7 +52,7 @@ namespace MantidWidgets * Updates visibility/tooltip of label error asterisk. * @param label :: New label as specified by user */ - void MuonSequentialFitDialog::validateLabel(const QString& label) + void MuonSequentialFitDialog::updateLabelError(const QString& label) { std::string error = isValidLabel( label.toStdString() ); @@ -47,6 +60,30 @@ namespace MantidWidgets ui.labelError->setToolTip( QString::fromStdString(error) ); } + /** + * Check if all the input field are valid. + * @return True if everything valid, false otherwise + */ + bool MuonSequentialFitDialog::isInputValid() + { + if ( ! ui.runs->isValid() ) + return false; + + std::string label = ui.labelInput->text().toStdString(); + if ( ! isValidLabel(label).empty() ) + return false; + + return true; + } + + /** + * Enables/disables start button depending on wether we are allowed to start. + */ + void MuonSequentialFitDialog::updateStartButton() + { + ui.controlButton->setEnabled( isInputValid() ); + } + /** * Destructor */