Skip to content

Commit

Permalink
Refs #6473. Control button logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbekasov committed Nov 20, 2013
1 parent f721208 commit 97d39ab
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Expand Up @@ -45,11 +45,19 @@ namespace MantidWidgets
virtual ~MuonSequentialFitDialog();

private:
enum ControlButtonType {
Start,
Stop
};

// -- FUNCTIONS -----------------------------------------------------------

/// Check if all the input field are valid
bool isInputValid();

/// Set the type of the control button
void setControlButtonType(ControlButtonType type);

// -- VARIABLES -----------------------------------------------------------

/// UI form
Expand All @@ -70,6 +78,11 @@ namespace MantidWidgets
/// Enables/disables start button depending on wether we are allowed to start
void updateControlButtonState();

/// Start fitting process
void startFit();

/// Stop fitting process
void stopFit();
};


Expand Down
Expand Up @@ -14,11 +14,12 @@ namespace MantidWidgets
* Constructor
*/
MuonSequentialFitDialog::MuonSequentialFitDialog(QWidget* parent) :
QDialog(parent)
QDialog(parent)
{
m_ui.setupUi(this);

// TODO: set initial values
setControlButtonType(Start);

// 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
Expand Down Expand Up @@ -84,6 +85,43 @@ namespace MantidWidgets
m_ui.controlButton->setEnabled( isInputValid() );
}

/**
* Set the type of the control button. It is Start button when fitting has not been started,
* and Stop button when fitting is running.
* @param type :: New type of the button
*/
void MuonSequentialFitDialog::setControlButtonType(ControlButtonType type)
{
// Disconnect everything connected to pressed() signal of the button
disconnect( m_ui.controlButton, SIGNAL( pressed() ), 0, 0);

// Connect to appropriate slot
auto buttonSlot = (type == Start) ? SLOT( startFit() ) : SLOT( stopFit() );
connect( m_ui.controlButton, SIGNAL( pressed() ), this, buttonSlot );

// Set appropriate text
QString buttonText = (type == Start) ? "Start" : "Stop";
m_ui.controlButton->setText(buttonText);
}

/**
* Start fitting process.
*/
void MuonSequentialFitDialog::startFit()
{
g_log.notice("Seq. fitting started");
setControlButtonType(Stop);
}

/**
* Stop fitting process.
*/
void MuonSequentialFitDialog::stopFit()
{
g_log.notice("Seq. fitting stopped");
setControlButtonType(Start);
}

/**
* Destructor
*/
Expand Down

0 comments on commit 97d39ab

Please sign in to comment.