From 1569bcd9baeb70e4eb8fc866d820fda8fc880212 Mon Sep 17 00:00:00 2001 From: Tom Perkins <thomas.perkins@stfc.ac.uk> Date: Fri, 6 May 2016 16:16:08 +0100 Subject: [PATCH] Replace busy wait with signal and slot The sequential fit dialog runs the file search in case the user has edited the run input box. We need to wait for the search to complete before getting the filenames. Previously this was done in a busy while loop using QApplication::processEvents(). This has been changed so that the fit is only started once the search reports that it is done. (We use a new signal fileInspectionFinished() because the existing fileFindingFinished() is emitted "too soon", i.e. when the thread finishes but while its member variables are still being accessed). re #9963 --- .../inc/MantidQtMantidWidgets/MWRunFiles.h | 2 ++ .../MuonSequentialFitDialog.h | 3 +++ MantidQt/MantidWidgets/src/MWRunFiles.cpp | 2 ++ .../src/MuonSequentialFitDialog.cpp | 22 +++++++++++-------- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MWRunFiles.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MWRunFiles.h index 5b733cc5974..96a6c63e877 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MWRunFiles.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MWRunFiles.h @@ -240,6 +240,8 @@ signals: void liveButtonPressed(bool); /// Signal emitted after asynchronous checking of live stream availability void liveButtonSetEnabledSignal(bool); + /// Emitted when inspection of any found files is completed + void fileInspectionFinished(); public slots: /// Set the file text and try and find it diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MuonSequentialFitDialog.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MuonSequentialFitDialog.h index 8807f5667b2..e4424425c5a 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MuonSequentialFitDialog.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/MuonSequentialFitDialog.h @@ -128,6 +128,9 @@ namespace MantidWidgets /// Stop fitting process void stopFit(); + /// Run fit after getting file input + void continueFit(); + }; diff --git a/MantidQt/MantidWidgets/src/MWRunFiles.cpp b/MantidQt/MantidWidgets/src/MWRunFiles.cpp index 18df2f32dbf..f8a8ea891d0 100644 --- a/MantidQt/MantidWidgets/src/MWRunFiles.cpp +++ b/MantidQt/MantidWidgets/src/MWRunFiles.cpp @@ -812,6 +812,8 @@ void MWRunFiles::inspectThreadResult() { setFileProblem(""); } + emit fileInspectionFinished(); + // Only emit the signal if file(s) were found if (!m_foundFiles.isEmpty()) emit filesFound(); diff --git a/MantidQt/MantidWidgets/src/MuonSequentialFitDialog.cpp b/MantidQt/MantidWidgets/src/MuonSequentialFitDialog.cpp index 4c4a06d1246..ece05ee74d4 100644 --- a/MantidQt/MantidWidgets/src/MuonSequentialFitDialog.cpp +++ b/MantidQt/MantidWidgets/src/MuonSequentialFitDialog.cpp @@ -279,7 +279,8 @@ void MuonSequentialFitDialog::updateCursor(DialogState newState) { } /** - * Start fitting process. + * Start fitting process by running file search. + * Once search is complete, fit continues in continueFit(). */ void MuonSequentialFitDialog::startFit() { if (m_state != Stopped) @@ -291,16 +292,19 @@ void MuonSequentialFitDialog::startFit() { // straight after editing the run box. In that case, lost focus event might // not be processed yet and search might not have been started yet. // Otherwise, search is not done as the widget sees that it has not been - // changed. Taken from LoadDialog.cpp:124. + // changed. + connect(m_ui.runs, SIGNAL(fileInspectionFinished()), this, + SLOT(continueFit())); m_ui.runs->findFiles(); +} - // Wait for file search to finish. - while (m_ui.runs->isSearching()) { - QApplication::processEvents(); - } - - // To process events from the finished thread - QApplication::processEvents(); +/** + * Carries out the fitting process once the file search has completed. + * Called when the run control reports that its search has finished. + */ +void MuonSequentialFitDialog::continueFit() { + disconnect(m_ui.runs, SIGNAL(fileInspectionFinished()), this, + SLOT(continueFit())); // Validate input fields if (!isInputValid()) { -- GitLab