diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp index c56801d06085..d920daca5fa7 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp @@ -1386,15 +1386,12 @@ void MantidUI::showAlgorithmDialog(const QString & algName, int version) * @param paramList :: A list of algorithm properties to be passed to Algorithm::setProperties * @param obs :: A pointer to an instance of AlgorithmObserver which will be attached to the finish notification */ -void MantidUI::showAlgorithmDialog(QString algName, QHash paramList,Mantid::API::AlgorithmObserver* obs) +void MantidUI::showAlgorithmDialog(QString algName, QHash paramList, Mantid::API::AlgorithmObserver *obs) { //Get latest version of the algorithm Mantid::API::IAlgorithm_sptr alg = this->createAlgorithm(algName, -1); if( !alg ) return; - if (obs) - { - obs->observeFinish(alg); - } + for(QHash::Iterator it = paramList.begin(); it != paramList.end(); ++it) { alg->setPropertyValue(it.key().toStdString(),it.value().toStdString()); @@ -1408,6 +1405,11 @@ void MantidUI::showAlgorithmDialog(QString algName, QHash param connect(dlg, SIGNAL(accepted()), this, SLOT(loadFileDialogAccept())); } + if (obs) + { + dlg->addAlgorithmObserver(obs); + } + dlg->show(); dlg->raise(); dlg->activateWindow(); @@ -1428,7 +1430,7 @@ void MantidUI::executeAlgorithm(Mantid::API::IAlgorithm_sptr alg) * @param paramList :: A list of algorithm properties to be passed to Algorithm::setProperties * @param obs :: A pointer to an instance of AlgorithmObserver which will be attached to the finish notification */ -void MantidUI::executeAlgorithm(const QString & algName, const QString & paramList,Mantid::API::AlgorithmObserver* obs) +void MantidUI::executeAlgorithm(const QString & algName, const QString & paramList, Mantid::API::AlgorithmObserver* obs) { //Get latest version of the algorithm Mantid::API::IAlgorithm_sptr alg = this->createAlgorithm(algName, -1); diff --git a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.h b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.h index 9167ddb96cd6..dbde213200a3 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/MantidUI.h +++ b/Code/Mantid/MantidPlot/src/Mantid/MantidUI.h @@ -377,12 +377,12 @@ class MantidUI:public QObject // Execute algorithm given name and version void showAlgorithmDialog(const QString & algName, int version = -1); - //Execute an algorithm with the given parameter list - void showAlgorithmDialog(QString algName, QHash paramList, Mantid::API::AlgorithmObserver* obs = NULL); + // Execute an algorithm with the given parameter list + void showAlgorithmDialog(QString algName, QHash paramList, Mantid::API::AlgorithmObserver *obs = NULL); // Execute an algorithm void executeAlgorithm(Mantid::API::IAlgorithm_sptr alg); // Execute a named algorithm using the given parameters - void executeAlgorithm(const QString & algName, const QString & paramList,Mantid::API::AlgorithmObserver* obs); + void executeAlgorithm(const QString & algName, const QString & paramList, Mantid::API::AlgorithmObserver* obs); // Find the name of the first input workspace for an algorithm QString findInputWorkspaceProperty(Mantid::API::IAlgorithm_sptr algorithm) const; diff --git a/Code/Mantid/MantidQt/API/inc/MantidQtAPI/AlgorithmDialog.h b/Code/Mantid/MantidQt/API/inc/MantidQtAPI/AlgorithmDialog.h index 70cc02d3aafe..19ffa1cfe7c7 100644 --- a/Code/Mantid/MantidQt/API/inc/MantidQtAPI/AlgorithmDialog.h +++ b/Code/Mantid/MantidQt/API/inc/MantidQtAPI/AlgorithmDialog.h @@ -23,6 +23,7 @@ // Could have forward declared this but it makes it easier to use from // inheriting classes if it is included here #include "MantidAPI/IAlgorithm.h" +#include "MantidAPI/AlgorithmObserver.h" #include #include @@ -246,6 +247,8 @@ protected slots: void setOptionalMessage(const QString & message); /// Set comma-separated-list of enabled parameter names void addEnabledAndDisableLists(const QStringList & enabled, const QStringList & disabled); + /// Add an AlgorithmObserver to the algorithm + void addAlgorithmObserver(Mantid::API::AlgorithmObserver *observer); protected: @@ -300,6 +303,9 @@ protected slots: /// A map to keep track of replace workspace button presses QHash m_wsbtn_tracker; + + /// A list of AlgorithmObservers to add to the algorithm prior to execution + std::vector m_observers; //@} }; diff --git a/Code/Mantid/MantidQt/API/src/AlgorithmDialog.cpp b/Code/Mantid/MantidQt/API/src/AlgorithmDialog.cpp index 21d06a50739d..a782246830dd 100644 --- a/Code/Mantid/MantidQt/API/src/AlgorithmDialog.cpp +++ b/Code/Mantid/MantidQt/API/src/AlgorithmDialog.cpp @@ -31,6 +31,7 @@ #include #include +#include #include using namespace MantidQt::API; @@ -761,7 +762,12 @@ void AlgorithmDialog::executeAlgorithmAsync() { try { + // Add AlgorithmObservers to the algorithm + for(auto it = m_observers.begin(); it != m_observers.end(); ++it) + (*it)->observeAll(m_algorithm); + m_algorithm->executeAsync(); + m_observers.clear(); } catch (Poco::NoThreadAvailableException &) { @@ -1042,3 +1048,15 @@ void AlgorithmDialog::setPreviousValue(QWidget* widget, const QString& propName) QString("Cannot set value for ") + widget->metaObject()->className() + ". Update AlgorithmDialog::setValue() to cope with this widget."); } + +/** + * Observer the execution of the algorithm using an AlgorithmObserver. + * + * All notifications will be observed. + * + * @Param observer Pointer to the AlgorithmObserver to add. + */ +void AlgorithmDialog::addAlgorithmObserver(Mantid::API::AlgorithmObserver *observer) +{ + m_observers.push_back(observer); +}