Skip to content

Commit

Permalink
Refs #6473. Enabling/disabling start button on input change.
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbekasov committed Nov 20, 2013
1 parent 6bcf617 commit eb20d26
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
Expand Up @@ -48,16 +48,21 @@ 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);

/// Instance used to print log messages
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();
};


Expand Down
41 changes: 39 additions & 2 deletions Code/Mantid/MantidQt/MantidWidgets/src/MuonSequentialFitDialog.cpp
Expand Up @@ -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() ) );
}

/**
Expand All @@ -39,14 +52,38 @@ 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() );

ui.labelError->setVisible( ! error.empty() );
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
*/
Expand Down

0 comments on commit eb20d26

Please sign in to comment.