diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflMainWindowPresenter.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflMainWindowPresenter.h index 0059af2d68ee1c8f2c590e472d9846def15386b9..701aaee4e961864ee260548542aa055a7a6dd6df 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflMainWindowPresenter.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflMainWindowPresenter.h @@ -44,6 +44,15 @@ public: virtual std::string getProcessingOptions() = 0; /// Returns global post-processing options virtual std::string getPostprocessingOptions() = 0; + /// Dialog/Prompt methods + virtual std::string askUserString(const std::string &prompt, + const std::string &title, + const std::string &defaultValue) = 0; + virtual bool askUserYesNo(std::string prompt, std::string title) = 0; + virtual void giveUserWarning(std::string prompt, std::string title) = 0; + virtual void giveUserCritical(std::string prompt, std::string title) = 0; + virtual void giveUserInfo(std::string prompt, std::string title) = 0; + virtual std::string runPythonAlgorithm(const std::string &pythonCode) = 0; }; } } diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflMainWindowView.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflMainWindowView.h index 1fa09f344f89ca51390d95e6a002f57e49eee173..5a7a775709702fdba95f8c94af2a7fbd3087198b 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflMainWindowView.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflMainWindowView.h @@ -1,6 +1,8 @@ #ifndef MANTID_CUSTOMINTERFACES_IREFLMAINWINDOWVIEW_H #define MANTID_CUSTOMINTERFACES_IREFLMAINWINDOWVIEW_H +#include <string> + namespace MantidQt { namespace CustomInterfaces { @@ -36,6 +38,16 @@ class IReflMainWindowView { public: /// Destructor virtual ~IReflMainWindowView(){}; + + /// Dialog/Prompt methods + virtual std::string askUserString(const std::string &prompt, + const std::string &title, + const std::string &defaultValue) = 0; + virtual bool askUserYesNo(std::string prompt, std::string title) = 0; + virtual void giveUserWarning(std::string prompt, std::string title) = 0; + virtual void giveUserCritical(std::string prompt, std::string title) = 0; + virtual void giveUserInfo(std::string prompt, std::string title) = 0; + virtual std::string runPythonAlgorithm(const std::string &pythonCode) = 0; }; } } diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflRunsTabView.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflRunsTabView.h index aba2892ac06bf3622f3fc478761414859d708355..0727439375528d747db2ef774693c1221c089b92 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflRunsTabView.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflRunsTabView.h @@ -55,14 +55,6 @@ public: // Connect the model virtual void showSearch(boost::shared_ptr<ReflSearchModel> model) = 0; - // Dialog/Prompt methods - virtual std::string askUserString(const std::string &prompt, - const std::string &title, - const std::string &defaultValue) = 0; - virtual void giveUserInfo(std::string prompt, std::string title) = 0; - virtual void giveUserCritical(std::string prompt, std::string title) = 0; - virtual void showAlgorithmDialog(const std::string &algorithm) = 0; - // Setter methods virtual void setInstrumentList(const std::vector<std::string> &instruments, const std::string &defaultInstrument) = 0; diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/QtReflMainWindowView.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/QtReflMainWindowView.h index 24b4f7f4a16eee1469c2c7a1eebb4ac860804e7f..3a2c9b8648a30f96dd02459c9bd70e206b7b0218 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/QtReflMainWindowView.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/QtReflMainWindowView.h @@ -50,6 +50,15 @@ public: /// This interface's categories. static QString categoryInfo() { return "Reflectometry"; } + /// Dialog/Prompt methods + std::string askUserString(const std::string &prompt, const std::string &title, + const std::string &defaultValue) override; + bool askUserYesNo(std::string prompt, std::string title) override; + void giveUserWarning(std::string prompt, std::string title) override; + void giveUserCritical(std::string prompt, std::string title) override; + void giveUserInfo(std::string prompt, std::string title) override; + std::string runPythonAlgorithm(const std::string &pythonCode) override; + private: /// Initializes the interface void initLayout() override; diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/QtReflRunsTabView.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/QtReflRunsTabView.h index cfd01bb951c3946700404e1333ca90ca5564c691..02038581736658138b74735da1aef8ad4c3d6cb6 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/QtReflRunsTabView.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/QtReflRunsTabView.h @@ -68,13 +68,6 @@ public: // Connect the model void showSearch(boost::shared_ptr<ReflSearchModel> model) override; - // Dialog/Prompt methods - std::string askUserString(const std::string &prompt, const std::string &title, - const std::string &defaultValue) override; - void giveUserInfo(std::string prompt, std::string title) override; - void giveUserCritical(std::string prompt, std::string title) override; - void showAlgorithmDialog(const std::string &algorithm) override; - // Setter methods void setInstrumentList(const std::vector<std::string> &instruments, const std::string &defaultInstrument) override; diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflMainWindowPresenter.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflMainWindowPresenter.h index fbbcfe0d77a520f8e496e2fb330a99e79da6da86..0a10c5b04c4be289fa17913020af4269185ac66e 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflMainWindowPresenter.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflMainWindowPresenter.h @@ -50,6 +50,14 @@ public: std::string getProcessingOptions() override; /// Returns global post-processing options std::string getPostprocessingOptions() override; + /// Dialog/Prompt methods + std::string askUserString(const std::string &prompt, const std::string &title, + const std::string &defaultValue) override; + bool askUserYesNo(std::string prompt, std::string title) override; + void giveUserWarning(std::string prompt, std::string title) override; + void giveUserCritical(std::string prompt, std::string title) override; + void giveUserInfo(std::string prompt, std::string title) override; + std::string runPythonAlgorithm(const std::string &pythonCode) override; private: /// The view we are handling diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflRunsTabPresenter.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflRunsTabPresenter.h index 9ed2da44f3a45b506e425700def4100b5c5d4f57..6b6c0090215f6e5f62df97b26df8b0bfecac7b21 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflRunsTabPresenter.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflRunsTabPresenter.h @@ -66,6 +66,13 @@ public: void acceptMainPresenter(IReflMainWindowPresenter *mainPresenter) override; void notify(IReflRunsTabPresenter::Flag flag) override; void notify(DataProcessorMainPresenter::Flag flag) override; + /// Dialog/Prompt methods + std::string askUserString(const std::string &prompt, const std::string &title, + const std::string &defaultValue) override; + bool askUserYesNo(std::string prompt, std::string title) override; + void giveUserWarning(std::string prompt, std::string title) override; + void giveUserCritical(std::string prompt, std::string title) override; + std::string runPythonAlgorithm(const std::string &pythonCode) override; protected: /// The search model diff --git a/MantidQt/CustomInterfaces/src/Reflectometry/QtReflMainWindowView.cpp b/MantidQt/CustomInterfaces/src/Reflectometry/QtReflMainWindowView.cpp index 91899643d9771d754293c2feb3e3b1e7befa9b4f..ec43dcaf1c7f9f00899d22f33d941d183b45e75d 100644 --- a/MantidQt/CustomInterfaces/src/Reflectometry/QtReflMainWindowView.cpp +++ b/MantidQt/CustomInterfaces/src/Reflectometry/QtReflMainWindowView.cpp @@ -3,6 +3,9 @@ #include "MantidQtCustomInterfaces/Reflectometry/QtReflSettingsTabView.h" #include "MantidQtCustomInterfaces/Reflectometry/ReflMainWindowPresenter.h" +#include <qinputdialog.h> +#include <qmessagebox.h> + namespace MantidQt { namespace CustomInterfaces { @@ -42,12 +45,6 @@ IReflRunsTabPresenter *QtReflMainWindowView::createRunsTab() { QtReflRunsTabView *runsTab = new QtReflRunsTabView(this); m_ui.mainTab->addTab(runsTab, QString("Runs")); - // This tab may need to run python code (to import/export TBL and to search - // the ICAT). The corresponding signal needs to be re-emitted by this widget - // so the python code is executed - connect(runsTab, SIGNAL(runAsPythonScript(const QString &, bool)), this, - SIGNAL(runAsPythonScript(const QString &, bool))); - return runsTab->getPresenter(); } @@ -61,5 +58,86 @@ IReflSettingsTabPresenter *QtReflMainWindowView::createSettingsTab() { return settingsTab->getPresenter(); } + +/** +Show an critical error dialog +@param prompt : The prompt to appear on the dialog +@param title : The text for the title bar of the dialog +*/ +void QtReflMainWindowView::giveUserCritical(std::string prompt, + std::string title) { + QMessageBox::critical(this, QString(title.c_str()), QString(prompt.c_str()), + QMessageBox::Ok, QMessageBox::Ok); +} + +/** +Show a warning dialog +@param prompt : The prompt to appear on the dialog +@param title : The text for the title bar of the dialog +*/ +void QtReflMainWindowView::giveUserWarning(std::string prompt, + std::string title) { + QMessageBox::warning(this, QString(title.c_str()), QString(prompt.c_str()), + QMessageBox::Ok, QMessageBox::Ok); +} + +/** +Show an information dialog +@param prompt : The prompt to appear on the dialog +@param title : The text for the title bar of the dialog +*/ +void QtReflMainWindowView::giveUserInfo(std::string prompt, std::string title) { + QMessageBox::information(this, QString(title.c_str()), + QString(prompt.c_str()), QMessageBox::Ok, + QMessageBox::Ok); +} + +/** +Ask the user a Yes/No question +@param prompt : The prompt to appear on the dialog +@param title : The text for the title bar of the dialog +@returns a boolean true if Yes, false if No +*/ +bool QtReflMainWindowView::askUserYesNo(std::string prompt, std::string title) { + auto response = QMessageBox::question( + this, QString(title.c_str()), QString(prompt.c_str()), + QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + if (response == QMessageBox::Yes) { + return true; + } + return false; +} + +/** +Ask the user to enter a string. +@param prompt : The prompt to appear on the dialog +@param title : The text for the title bar of the dialog +@param defaultValue : The default value entered. +@returns The user's string if submitted, or an empty string +*/ +std::string +QtReflMainWindowView::askUserString(const std::string &prompt, + const std::string &title, + const std::string &defaultValue) { + bool ok; + QString text = QInputDialog::getText( + this, QString::fromStdString(title), QString::fromStdString(prompt), + QLineEdit::Normal, QString::fromStdString(defaultValue), &ok); + if (ok) + return text.toStdString(); + return ""; +} + +/** +Runs python code +* @param pythonCode : [input] The code to run +* @return : Result of the execution +*/ +std::string +QtReflMainWindowView::runPythonAlgorithm(const std::string &pythonCode) { + + QString output = runPythonCode(QString::fromStdString(pythonCode), false); + return output.toStdString(); +} } } diff --git a/MantidQt/CustomInterfaces/src/Reflectometry/QtReflRunsTabView.cpp b/MantidQt/CustomInterfaces/src/Reflectometry/QtReflRunsTabView.cpp index 8d74e3484d98241efcaf7ae0814cb1ff08207577..e1e280b88b548efb0b3d2e317339fdba273375a4 100644 --- a/MantidQt/CustomInterfaces/src/Reflectometry/QtReflRunsTabView.cpp +++ b/MantidQt/CustomInterfaces/src/Reflectometry/QtReflRunsTabView.cpp @@ -13,8 +13,6 @@ #include "MantidQtMantidWidgets/DataProcessorUI/QDataProcessorWidget.h" #include "MantidQtMantidWidgets/HintingLineEditFactory.h" #include "MantidQtMantidWidgets/SlitCalculator.h" -#include <qinputdialog.h> -#include <qmessagebox.h> namespace MantidQt { namespace CustomInterfaces { @@ -73,10 +71,6 @@ void QtReflRunsTabView::initLayout() { connect(qDataProcessorWidget, SIGNAL(comboProcessInstrument_currentIndexChanged(int)), this, SLOT(instrumentChanged(int))); - // Needed to Import/Export TBL, plot row and plot group - connect(qDataProcessorWidget, - SIGNAL(runAsPythonScript(const QString &, bool)), this, - SIGNAL(runAsPythonScript(const QString &, bool))); // Create the presenter m_presenter = new ReflRunsTabPresenter( @@ -256,59 +250,6 @@ void QtReflRunsTabView::instrumentChanged(int index) { m_calculator->processInstrumentHasBeenChanged(); } -/** -Show an information dialog -@param prompt : The prompt to appear on the dialog -@param title : The text for the title bar of the dialog -*/ -void QtReflRunsTabView::giveUserInfo(std::string prompt, std::string title) { - QMessageBox::information(this, QString(title.c_str()), - QString(prompt.c_str()), QMessageBox::Ok, - QMessageBox::Ok); -} - -/** -Show an critical error dialog -@param prompt : The prompt to appear on the dialog -@param title : The text for the title bar of the dialog -*/ -void QtReflRunsTabView::giveUserCritical(std::string prompt, - std::string title) { - QMessageBox::critical(this, QString(title.c_str()), QString(prompt.c_str()), - QMessageBox::Ok, QMessageBox::Ok); -} - -/** -Ask the user to enter a string. -@param prompt : The prompt to appear on the dialog -@param title : The text for the title bar of the dialog -@param defaultValue : The default value entered. -@returns The user's string if submitted, or an empty string -*/ -std::string QtReflRunsTabView::askUserString(const std::string &prompt, - const std::string &title, - const std::string &defaultValue) { - bool ok; - QString text = QInputDialog::getText( - this, QString::fromStdString(title), QString::fromStdString(prompt), - QLineEdit::Normal, QString::fromStdString(defaultValue), &ok); - if (ok) - return text.toStdString(); - return ""; -} - -/** -Show the user the dialog for an algorithm -*/ -void QtReflRunsTabView::showAlgorithmDialog(const std::string &algorithm) { - std::stringstream pythonSrc; - pythonSrc << "try:\n"; - pythonSrc << " algm = " << algorithm << "Dialog()\n"; - pythonSrc << "except:\n"; - pythonSrc << " pass\n"; - runPythonCode(QString::fromStdString(pythonSrc.str()), false); -} - /** Get the selected instrument for searching @returns the selected instrument to search for diff --git a/MantidQt/CustomInterfaces/src/Reflectometry/ReflMainWindowPresenter.cpp b/MantidQt/CustomInterfaces/src/Reflectometry/ReflMainWindowPresenter.cpp index aee4f792e17fd1d234605d28c4b3f4300e393ce4..e4a6114c6ce7f1430e0d3a7f67be1594e8ef6a7c 100644 --- a/MantidQt/CustomInterfaces/src/Reflectometry/ReflMainWindowPresenter.cpp +++ b/MantidQt/CustomInterfaces/src/Reflectometry/ReflMainWindowPresenter.cpp @@ -55,5 +55,76 @@ std::string ReflMainWindowPresenter::getPostprocessingOptions() { // Request global post-processing options to 'Settings' presenter return m_settingsPresenter->getPostprocessingOptions(); } + +/** +Tells the view to show an critical error dialog +@param prompt : The prompt to appear on the dialog +@param title : The text for the title bar of the dialog +*/ +void ReflMainWindowPresenter::giveUserCritical(std::string prompt, + std::string title) { + + m_view->giveUserCritical(prompt, title); +} + +/** +Tells the view to show a warning dialog +@param prompt : The prompt to appear on the dialog +@param title : The text for the title bar of the dialog +*/ +void ReflMainWindowPresenter::giveUserWarning(std::string prompt, + std::string title) { + + m_view->giveUserWarning(prompt, title); +} + +/** +Tells the view to show an information dialog +@param prompt : The prompt to appear on the dialog +@param title : The text for the title bar of the dialog +*/ +void ReflMainWindowPresenter::giveUserInfo(std::string prompt, + std::string title) { + + m_view->giveUserInfo(prompt, title); +} + +/** +Tells the view to ask the user a Yes/No question +@param prompt : The prompt to appear on the dialog +@param title : The text for the title bar of the dialog +@returns a boolean true if Yes, false if No +*/ +bool ReflMainWindowPresenter::askUserYesNo(std::string prompt, + std::string title) { + + return m_view->askUserYesNo(prompt, title); +} + +/** +Tells the view to ask the user to enter a string. +@param prompt : The prompt to appear on the dialog +@param title : The text for the title bar of the dialog +@param defaultValue : The default value entered. +@returns The user's string if submitted, or an empty string +*/ +std::string +ReflMainWindowPresenter::askUserString(const std::string &prompt, + const std::string &title, + const std::string &defaultValue) { + + return m_view->askUserString(prompt, title, defaultValue); +} + +/** +Tells the view to show the user the dialog for an algorithm +* @param pythonCode : [input] The algorithm as python code +* @return : Result of the execution +*/ +std::string +ReflMainWindowPresenter::runPythonAlgorithm(const std::string &pythonCode) { + + return m_view->runPythonAlgorithm(pythonCode); +} } } \ No newline at end of file diff --git a/MantidQt/CustomInterfaces/src/Reflectometry/ReflRunsTabPresenter.cpp b/MantidQt/CustomInterfaces/src/Reflectometry/ReflRunsTabPresenter.cpp index 6a7e218188b67cf8255c5339127607808d946c7d..3a1c744dd5e55dc72ee653aee683ab634e200c2d 100644 --- a/MantidQt/CustomInterfaces/src/Reflectometry/ReflRunsTabPresenter.cpp +++ b/MantidQt/CustomInterfaces/src/Reflectometry/ReflRunsTabPresenter.cpp @@ -159,9 +159,14 @@ void ReflRunsTabPresenter::search() { // If we're not logged into a catalog, prompt the user to do so if (CatalogManager::Instance().getActiveSessions().empty()) { try { - m_view->showAlgorithmDialog("CatalogLogin"); + std::stringstream pythonSrc; + pythonSrc << "try:\n"; + pythonSrc << " algm = CatalogLoginDialog()\n"; + pythonSrc << "except:\n"; + pythonSrc << " pass\n"; + m_mainPresenter->runPythonAlgorithm(pythonSrc.str()); } catch (std::runtime_error &e) { - m_view->giveUserCritical("Error Logging in:\n" + std::string(e.what()), + m_mainPresenter->giveUserCritical("Error Logging in:\n" + std::string(e.what()), "login failed"); } } @@ -173,7 +178,7 @@ void ReflRunsTabPresenter::search() { CatalogManager::Instance().getActiveSessions().front()->getSessionId(); } else { // there are no active sessions, we return here to avoid an exception - m_view->giveUserInfo( + m_mainPresenter->giveUserInfo( "Error Logging in: Please press 'Search' to try again.", "Login Failed"); return; @@ -347,6 +352,65 @@ std::string ReflRunsTabPresenter::getPostprocessingOptions() const { return m_mainPresenter->getPostprocessingOptions(); } +/** +Tells the view to show an critical error dialog +@param prompt : The prompt to appear on the dialog +@param title : The text for the title bar of the dialog +*/ +void ReflRunsTabPresenter::giveUserCritical(std::string prompt, + std::string title) { + + m_mainPresenter->giveUserCritical(prompt, title); +} + +/** +Tells the view to show a warning dialog +@param prompt : The prompt to appear on the dialog +@param title : The text for the title bar of the dialog +*/ +void ReflRunsTabPresenter::giveUserWarning(std::string prompt, + std::string title) { + + m_mainPresenter->giveUserWarning(prompt, title); +} + +/** +Tells the view to ask the user a Yes/No question +@param prompt : The prompt to appear on the dialog +@param title : The text for the title bar of the dialog +@returns a boolean true if Yes, false if No +*/ +bool ReflRunsTabPresenter::askUserYesNo(std::string prompt, std::string title) { + + return m_mainPresenter->askUserYesNo(prompt, title); +} + +/** +Tells the view to ask the user to enter a string. +@param prompt : The prompt to appear on the dialog +@param title : The text for the title bar of the dialog +@param defaultValue : The default value entered. +@returns The user's string if submitted, or an empty string +*/ +std::string +ReflRunsTabPresenter::askUserString(const std::string &prompt, + const std::string &title, + const std::string &defaultValue) { + + return m_mainPresenter->askUserString(prompt, title, defaultValue); +} + +/** +Tells the main presenter to run an algorithm as python code +* @param pythonCode : [input] The algorithm as python code +* @return : The result of the execution +*/ +std::string +ReflRunsTabPresenter::runPythonAlgorithm(const std::string &pythonCode) { + + return m_mainPresenter->runPythonAlgorithm(pythonCode); +} + const std::string ReflRunsTabPresenter::MeasureTransferMethod = "Measurement"; const std::string ReflRunsTabPresenter::LegacyTransferMethod = "Description"; } diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorMainPresenter.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorMainPresenter.h index 535e80e1407b9c7965eba4fad4938322a165a3b6..90d332fc318978bfc7721fcab142cef310b2543e 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorMainPresenter.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorMainPresenter.h @@ -41,15 +41,24 @@ public: enum Flag { ADSChangedFlag }; - // Notify this receiver that something changed in the ADS + /// Notify this receiver that something changed in the ADS virtual void notify(DataProcessorMainPresenter::Flag flag) = 0; - // Return global options for pre-processing + /// Dialog/Prompt methods + virtual std::string askUserString(const std::string &prompt, + const std::string &title, + const std::string &defaultValue) = 0; + virtual bool askUserYesNo(std::string prompt, std::string title) = 0; + virtual void giveUserWarning(std::string prompt, std::string title) = 0; + virtual void giveUserCritical(std::string prompt, std::string title) = 0; + virtual std::string runPythonAlgorithm(const std::string &algorithm) = 0; + + /// Return global options for pre-processing virtual std::map<std::string, std::string> getPreprocessingOptions() const = 0; - // Return global options for reduction + /// Return global options for reduction virtual std::string getProcessingOptions() const = 0; - // Return global options for post-processing + /// Return global options for post-processing virtual std::string getPostprocessingOptions() const = 0; }; } diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorView.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorView.h index a7311969e4360a1345b2d72b63446145878de567..ccc82d55e660cbbf037f9579ce3846aba7fe991f 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorView.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/DataProcessorView.h @@ -51,14 +51,6 @@ public: virtual void showTable(QDataProcessorTreeModel_sptr model) = 0; // Dialog/Prompt methods - virtual std::string askUserString(const std::string &prompt, - const std::string &title, - const std::string &defaultValue) = 0; - virtual bool askUserYesNo(std::string prompt, std::string title) = 0; - virtual void giveUserWarning(std::string prompt, std::string title) = 0; - virtual void giveUserCritical(std::string prompt, std::string title) = 0; - virtual void showAlgorithmDialog(const std::string &algorithm) = 0; - virtual void showImportDialog() = 0; virtual std::string requestNotebookPath() = 0; // Settings @@ -69,9 +61,6 @@ public: // produced virtual bool getEnableNotebook() = 0; - // Plotting - virtual void plotWorkspaces(const std::set<std::string> &workspaces) = 0; - // Setter methods virtual void setTableList(const std::set<std::string> &tables) = 0; virtual void setInstrumentList(const std::vector<std::string> &instruments, diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/GenericDataProcessorPresenter.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/GenericDataProcessorPresenter.h index d40ba86910ec30d7d9cef33e2556cdd588be46bd..b534145ba9881701880f0306a8a1334d522c9dc6 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/GenericDataProcessorPresenter.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/GenericDataProcessorPresenter.h @@ -170,6 +170,8 @@ protected: // plotting void plotRow(); void plotGroup(); + void plotWorkspaces(const std::set<std::string> &workspaces); + // options void showOptionsDialog(); void initOptions(); diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/QDataProcessorWidget.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/QDataProcessorWidget.h index af6572bd1be81405bf610a5e6c0fd198cb502299..6cac52ac6428472a42d021ebe6bd6abdc9980dab 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/QDataProcessorWidget.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/DataProcessorUI/QDataProcessorWidget.h @@ -52,22 +52,12 @@ public: void showTable(QDataProcessorTreeModel_sptr model) override; // Dialog/Prompt methods - std::string askUserString(const std::string &prompt, const std::string &title, - const std::string &defaultValue) override; - bool askUserYesNo(std::string prompt, std::string title) override; - void giveUserWarning(std::string prompt, std::string title) override; - void giveUserCritical(std::string prompt, std::string title) override; - void showAlgorithmDialog(const std::string &algorithm) override; - void showImportDialog() override; std::string requestNotebookPath() override; // Settings void saveSettings(const std::map<std::string, QVariant> &options) override; void loadSettings(std::map<std::string, QVariant> &options) override; - // Plotting - void plotWorkspaces(const std::set<std::string> &workspaces) override; - // Set the status of the progress bar void setProgressRange(int min, int max) override; void setProgress(int progress) override; diff --git a/MantidQt/MantidWidgets/src/DataProcessorUI/GenericDataProcessorPresenter.cpp b/MantidQt/MantidWidgets/src/DataProcessorUI/GenericDataProcessorPresenter.cpp index d82d581faffadc46286d201bb72c51c23a97e4de..c8164b7f58a1ba143b60a9818cb181139e17ccda 100644 --- a/MantidQt/MantidWidgets/src/DataProcessorUI/GenericDataProcessorPresenter.cpp +++ b/MantidQt/MantidWidgets/src/DataProcessorUI/GenericDataProcessorPresenter.cpp @@ -223,7 +223,8 @@ Process selected rows */ void GenericDataProcessorPresenter::process() { if (m_model->rowCount() == 0) { - m_view->giveUserWarning("Cannot process an empty Table", "Warning"); + m_mainPresenter->giveUserWarning("Cannot process an empty Table", + "Warning"); return; } @@ -235,7 +236,7 @@ void GenericDataProcessorPresenter::process() { if (groups.empty() && rows.empty()) { if (m_options["WarnProcessAll"].toBool()) { // Does the user want to abort? - if (!m_view->askUserYesNo( + if (!m_mainPresenter->askUserYesNo( "This will process all rows in the table. Continue?", "Process all rows?")) return; @@ -271,7 +272,7 @@ void GenericDataProcessorPresenter::process() { err << "You have only selected " << rowIds.size() << " of the "; err << numRowsInGroup(groupId) << " rows in group " << groupId << "."; err << " Are you sure you want to continue?"; - if (!m_view->askUserYesNo(err.str(), "Continue Processing?")) + if (!m_mainPresenter->askUserYesNo(err.str(), "Continue Processing?")) return; } } @@ -420,7 +421,7 @@ bool GenericDataProcessorPresenter::processGroups( Mantid::Kernel::Strings::toString<int>(groupId); const std::string message = "Error encountered while processing row " + rowNo + " in group " + groupNo + ":\n"; - m_view->giveUserCritical(message + ex.what(), "Error"); + m_mainPresenter->giveUserCritical(message + ex.what(), "Error"); progressReporter.clear(); return false; } @@ -436,7 +437,7 @@ bool GenericDataProcessorPresenter::processGroups( Mantid::Kernel::Strings::toString<int>(groupId); const std::string message = "Error encountered while stitching group " + groupNo + ":\n"; - m_view->giveUserCritical(message + ex.what(), "Error"); + m_mainPresenter->giveUserCritical(message + ex.what(), "Error"); progressReporter.clear(); return false; } @@ -470,9 +471,10 @@ bool GenericDataProcessorPresenter::rowsValid( const std::string rowNo = Mantid::Kernel::Strings::toString<int>(*it + 1); - m_view->giveUserCritical("Error found in group " + groupNo + ", row " + - rowNo + ":\n" + ex.what(), - "Error"); + m_mainPresenter->giveUserCritical("Error found in group " + groupNo + + ", row " + rowNo + ":\n" + + ex.what(), + "Error"); return false; } } @@ -1057,8 +1059,8 @@ void GenericDataProcessorPresenter::saveTable() { Press changes to a new item in the ADS */ void GenericDataProcessorPresenter::saveTableAs() { - const std::string userString = - m_view->askUserString("Save As", "Enter a workspace name:", "Workspace"); + const std::string userString = m_mainPresenter->askUserString( + "Save As", "Enter a workspace name:", "Workspace"); if (!userString.empty()) { m_wsName = userString; saveTable(); @@ -1070,9 +1072,10 @@ Start a new, untitled table */ void GenericDataProcessorPresenter::newTable() { if (m_tableDirty && m_options["WarnDiscardChanges"].toBool()) - if (!m_view->askUserYesNo("Your current table has unsaved changes. Are you " - "sure you want to discard them?", - "Start New Table?")) + if (!m_mainPresenter->askUserYesNo( + "Your current table has unsaved changes. Are you " + "sure you want to discard them?", + "Start New Table?")) return; m_ws = createDefaultWorkspace(); @@ -1088,9 +1091,10 @@ Open a table from the ADS */ void GenericDataProcessorPresenter::openTable() { if (m_tableDirty && m_options["WarnDiscardChanges"].toBool()) - if (!m_view->askUserYesNo("Your current table has unsaved changes. Are you " - "sure you want to discard them?", - "Open Table?")) + if (!m_mainPresenter->askUserYesNo( + "Your current table has unsaved changes. Are you " + "sure you want to discard them?", + "Open Table?")) return; auto &ads = AnalysisDataService::Instance(); @@ -1100,7 +1104,8 @@ void GenericDataProcessorPresenter::openTable() { return; if (!ads.isValid(toOpen).empty()) { - m_view->giveUserCritical("Could not open workspace: " + toOpen, "Error"); + m_mainPresenter->giveUserCritical("Could not open workspace: " + toOpen, + "Error"); return; } @@ -1119,7 +1124,7 @@ void GenericDataProcessorPresenter::openTable() { m_view->showTable(m_model); m_tableDirty = false; } catch (std::runtime_error &e) { - m_view->giveUserCritical( + m_mainPresenter->giveUserCritical( "Could not open workspace: " + std::string(e.what()), "Error"); } } @@ -1128,14 +1133,38 @@ void GenericDataProcessorPresenter::openTable() { Import a table from TBL file */ void GenericDataProcessorPresenter::importTable() { - m_view->showImportDialog(); + + std::stringstream pythonSrc; + pythonSrc << "try:\n"; + pythonSrc << " algm = " + << "LoadTBL" + << "Dialog()\n"; + pythonSrc << " print algm.getPropertyValue(\"OutputWorkspace\")\n"; + pythonSrc << "except:\n"; + pythonSrc << " pass\n"; + + const std::string result = + m_mainPresenter->runPythonAlgorithm(pythonSrc.str()); + + // result will hold the name of the output workspace + // otherwise this should be an empty string. + QString outputWorkspaceName = QString::fromStdString(result); + auto toOpen = outputWorkspaceName.trimmed().toStdString(); + m_view->setModel(toOpen); } /** Export a table to TBL file */ void GenericDataProcessorPresenter::exportTable() { - m_view->showAlgorithmDialog("SaveTBL"); + + std::stringstream pythonSrc; + pythonSrc << "try:\n"; + pythonSrc << " algm = SaveTBLDialog()\n"; + pythonSrc << "except:\n"; + pythonSrc << " pass\n"; + + m_mainPresenter->runPythonAlgorithm(pythonSrc.str()); } /** @@ -1387,14 +1416,15 @@ void GenericDataProcessorPresenter::plotRow() { } if (!notFound.empty()) - m_view->giveUserWarning("The following workspaces were not plotted because " - "they were not found:\n" + - boost::algorithm::join(notFound, "\n") + - "\n\nPlease check that the rows you are trying " - "to plot have been fully processed.", - "Error plotting rows."); - - m_view->plotWorkspaces(workspaces); + m_mainPresenter->giveUserWarning( + "The following workspaces were not plotted because " + "they were not found:\n" + + boost::algorithm::join(notFound, "\n") + + "\n\nPlease check that the rows you are trying " + "to plot have been fully processed.", + "Error plotting rows."); + + plotWorkspaces(workspaces); } /** Plots any currently selected groups */ @@ -1428,14 +1458,35 @@ void GenericDataProcessorPresenter::plotGroup() { } if (!notFound.empty()) - m_view->giveUserWarning("The following workspaces were not plotted because " - "they were not found:\n" + - boost::algorithm::join(notFound, "\n") + - "\n\nPlease check that the groups you are " - "trying to plot have been fully processed.", - "Error plotting groups."); - - m_view->plotWorkspaces(workspaces); + m_mainPresenter->giveUserWarning( + "The following workspaces were not plotted because " + "they were not found:\n" + + boost::algorithm::join(notFound, "\n") + + "\n\nPlease check that the groups you are " + "trying to plot have been fully processed.", + "Error plotting groups."); + + plotWorkspaces(workspaces); +} + +/** +Plot a set of workspaces +* @param workspaces : [input] The list of workspaces as a set +*/ +void GenericDataProcessorPresenter::plotWorkspaces( + const std::set<std::string> &workspaces) { + if (workspaces.empty()) + return; + + std::stringstream pythonSrc; + pythonSrc << "base_graph = None\n"; + for (auto ws = workspaces.begin(); ws != workspaces.end(); ++ws) + pythonSrc << "base_graph = plotSpectrum(\"" << *ws + << "\", 0, True, window = base_graph)\n"; + + pythonSrc << "base_graph.activeLayer().logLogAxes()\n"; + + m_mainPresenter->runPythonAlgorithm(pythonSrc.str()); } /** Shows the Refl Options dialog */ diff --git a/MantidQt/MantidWidgets/src/DataProcessorUI/QDataProcessorWidget.cpp b/MantidQt/MantidWidgets/src/DataProcessorUI/QDataProcessorWidget.cpp index a0e6c5702b55046a6afe3b7ec5bec4356fc49e6b..6e6c8527a32055b4090785d60ece782dddd7c66c 100644 --- a/MantidQt/MantidWidgets/src/DataProcessorUI/QDataProcessorWidget.cpp +++ b/MantidQt/MantidWidgets/src/DataProcessorUI/QDataProcessorWidget.cpp @@ -80,8 +80,7 @@ this method is intended to be called by the presenter @param name : the string name of the workspace to be grabbed */ void QDataProcessorWidget::setModel(const std::string &name) { - m_toOpen = name; - m_presenter->notify(DataProcessorPresenter::TableUpdatedFlag); + setModel(QString::fromStdString(name)); } /** @@ -279,100 +278,6 @@ void QDataProcessorWidget::showContextMenu(const QPoint &pos) { menu->popup(ui.viewTable->viewport()->mapToGlobal(pos)); } -/** -Show an critical error dialog -@param prompt : The prompt to appear on the dialog -@param title : The text for the title bar of the dialog -*/ -void QDataProcessorWidget::giveUserCritical(std::string prompt, - std::string title) { - QMessageBox::critical(this, QString(title.c_str()), QString(prompt.c_str()), - QMessageBox::Ok, QMessageBox::Ok); -} - -/** -Show a warning dialog -@param prompt : The prompt to appear on the dialog -@param title : The text for the title bar of the dialog -*/ -void QDataProcessorWidget::giveUserWarning(std::string prompt, - std::string title) { - QMessageBox::warning(this, QString(title.c_str()), QString(prompt.c_str()), - QMessageBox::Ok, QMessageBox::Ok); -} - -/** -Ask the user a Yes/No question -@param prompt : The prompt to appear on the dialog -@param title : The text for the title bar of the dialog -@returns a boolean true if Yes, false if No -*/ -bool QDataProcessorWidget::askUserYesNo(std::string prompt, std::string title) { - auto response = QMessageBox::question( - this, QString(title.c_str()), QString(prompt.c_str()), - QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); - if (response == QMessageBox::Yes) { - return true; - } - return false; -} - -/** -Ask the user to enter a string. -@param prompt : The prompt to appear on the dialog -@param title : The text for the title bar of the dialog -@param defaultValue : The default value entered. -@returns The user's string if submitted, or an empty string -*/ -std::string -QDataProcessorWidget::askUserString(const std::string &prompt, - const std::string &title, - const std::string &defaultValue) { - bool ok; - QString text = QInputDialog::getText( - this, QString::fromStdString(title), QString::fromStdString(prompt), - QLineEdit::Normal, QString::fromStdString(defaultValue), &ok); - if (ok) - return text.toStdString(); - return ""; -} - -/** -Show the user the dialog for an algorithm -* @param algorithm : [input] The algorithm -*/ -void QDataProcessorWidget::showAlgorithmDialog(const std::string &algorithm) { - std::stringstream pythonSrc; - pythonSrc << "try:\n"; - pythonSrc << " algm = " << algorithm << "Dialog()\n"; - pythonSrc << "except:\n"; - pythonSrc << " pass\n"; - runPythonCode(QString::fromStdString(pythonSrc.str()), false); -} - -/** -Show the user the dialog for "LoadReflTBL" -*/ -void QDataProcessorWidget::showImportDialog() { - std::stringstream pythonSrc; - pythonSrc << "try:\n"; - pythonSrc << " algm = " - << "LoadTBL" - << "Dialog()\n"; - pythonSrc << " print algm.getPropertyValue(\"OutputWorkspace\")\n"; - pythonSrc << "except:\n"; - pythonSrc << " pass\n"; - // outputWorkspaceName will hold the name of the workspace - // otherwise this should be an empty string. - QString outputWorkspaceName = - runPythonCode(QString::fromStdString(pythonSrc.str()), false); - m_toOpen = outputWorkspaceName.trimmed().toStdString(); - // notifying the presenter that a new table should be opened - // The presenter will ask about any unsaved changes etc - // before opening the new table - m_presenter->notify(DataProcessorPresenter::OpenTableFlag); -} - /** Show the user file dialog to choose save location of notebook */ @@ -428,26 +333,6 @@ void QDataProcessorWidget::loadSettings( settings.endGroup(); } -/** -Plot a set of workspaces -* @param workspaces : [input] The list of workspaces as a set -*/ -void QDataProcessorWidget::plotWorkspaces( - const std::set<std::string> &workspaces) { - if (workspaces.empty()) - return; - - std::stringstream pythonSrc; - pythonSrc << "base_graph = None\n"; - for (auto ws = workspaces.begin(); ws != workspaces.end(); ++ws) - pythonSrc << "base_graph = plotSpectrum(\"" << *ws - << "\", 0, True, window = base_graph)\n"; - - pythonSrc << "base_graph.activeLayer().logLogAxes()\n"; - - runPythonCode(QString::fromStdString(pythonSrc.str())); -} - /** Set the range of the progress bar @param min : The minimum value of the bar