From cb9a76af48407d3002b95731e6c438bf6f3dfddb Mon Sep 17 00:00:00 2001 From: Steven Hahn <hahnse@ornl.gov> Date: Fri, 29 Jul 2016 13:57:56 -0400 Subject: [PATCH] Add override keyword. Limit number of std::string copies. --- .../Reflectometry/IReflMainWindowPresenter.h | 12 +++++--- .../Reflectometry/IReflMainWindowView.h | 12 +++++--- .../Reflectometry/QtReflMainWindowView.h | 12 +++++--- .../Reflectometry/QtReflSettingsTabView.h | 10 +++---- .../Reflectometry/ReflMainWindowPresenter.h | 22 ++++++++------ .../Reflectometry/ReflSettingsTabPresenter.h | 8 ++--- .../Reflectometry/QtReflMainWindowView.cpp | 30 +++++++++++-------- .../Reflectometry/ReflMainWindowPresenter.cpp | 18 +++++------ .../CustomInterfaces/test/ReflMockObjects.h | 18 ++++++----- 9 files changed, 82 insertions(+), 60 deletions(-) diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflMainWindowPresenter.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflMainWindowPresenter.h index 75c56fd3c01..b3bce89ed13 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflMainWindowPresenter.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflMainWindowPresenter.h @@ -49,10 +49,14 @@ public: 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 bool askUserYesNo(const std::string &prompt, + const std::string &title) = 0; + virtual void giveUserWarning(const std::string &prompt, + const std::string &title) = 0; + virtual void giveUserCritical(const std::string &prompt, + const std::string &title) = 0; + virtual void giveUserInfo(const std::string &prompt, + const 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 5a7a7757097..d5315143284 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflMainWindowView.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/IReflMainWindowView.h @@ -43,10 +43,14 @@ public: 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 bool askUserYesNo(const std::string &prompt, + const std::string &title) = 0; + virtual void giveUserWarning(const std::string &prompt, + const std::string &title) = 0; + virtual void giveUserCritical(const std::string &prompt, + const std::string &title) = 0; + virtual void giveUserInfo(const std::string &prompt, + const std::string &title) = 0; virtual std::string runPythonAlgorithm(const std::string &pythonCode) = 0; }; } diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/QtReflMainWindowView.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/QtReflMainWindowView.h index 2bc9ed23ed3..a3f05e178c4 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/QtReflMainWindowView.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/QtReflMainWindowView.h @@ -53,10 +53,14 @@ public: /// 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; + bool askUserYesNo(const std::string &prompt, + const std::string &title) override; + void giveUserWarning(const std::string &prompt, + const std::string &title) override; + void giveUserCritical(const std::string &prompt, + const std::string &title) override; + void giveUserInfo(const std::string &prompt, + const std::string &title) override; std::string runPythonAlgorithm(const std::string &pythonCode) override; private: diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/QtReflSettingsTabView.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/QtReflSettingsTabView.h index a624226de51..afa5c5882ba 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/QtReflSettingsTabView.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/QtReflSettingsTabView.h @@ -43,15 +43,15 @@ public: /// Destructor ~QtReflSettingsTabView() override; /// Returns the presenter managing this view - IReflSettingsTabPresenter *getPresenter() const; + IReflSettingsTabPresenter *getPresenter() const override; /// Returns global options for 'Plus' algorithm - std::string getPlusOptions() const; + std::string getPlusOptions() const override; /// Returns global options for 'CreateTransmissionWorkspaceAuto' - std::string getTransmissionOptions() const; + std::string getTransmissionOptions() const override; /// Returns global options for 'ReflectometryReductionOneAuto' - std::string getReductionOptions() const; + std::string getReductionOptions() const override; /// Returns global options for 'Stitch1DMany' - std::string getStitchOptions() const; + std::string getStitchOptions() const override; /// Creates hints for 'Plus' void diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflMainWindowPresenter.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflMainWindowPresenter.h index 396db08609c..eb5f07ac6dd 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflMainWindowPresenter.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflMainWindowPresenter.h @@ -47,20 +47,24 @@ public: /// Destructor ~ReflMainWindowPresenter() override; /// Returns global options for 'Plus' algorithm - std::string getPlusOptions() const; + std::string getPlusOptions() const override; /// Returns global options for 'CreateTransmissionWorkspaceAuto' - std::string getTransmissionOptions() const; + std::string getTransmissionOptions() const override; /// Returns global options for 'ReflectometryReductionOneAuto' - std::string getReductionOptions() const; + std::string getReductionOptions() const override; /// Returns global options for 'Stitch1DMany' - std::string getStitchOptions() const; + std::string getStitchOptions() const 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; + bool askUserYesNo(const std::string &prompt, + const std::string &title) override; + void giveUserWarning(const std::string &prompt, + const std::string &title) override; + void giveUserCritical(const std::string &prompt, + const std::string &title) override; + void giveUserInfo(const std::string &prompt, + const std::string &title) override; std::string runPythonAlgorithm(const std::string &pythonCode) override; private: @@ -75,4 +79,4 @@ private: }; } } -#endif /* MANTID_CUSTOMINTERFACES_REFLMAINWINDOWPRESENTER_H */ \ No newline at end of file +#endif /* MANTID_CUSTOMINTERFACES_REFLMAINWINDOWPRESENTER_H */ diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflSettingsTabPresenter.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflSettingsTabPresenter.h index 8e803b5fbbf..0e3b1affad2 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflSettingsTabPresenter.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Reflectometry/ReflSettingsTabPresenter.h @@ -48,13 +48,13 @@ public: void acceptMainPresenter(IReflMainWindowPresenter *mainPresenter) override; /// Returns global options for 'Plus' algorithm - std::string getPlusOptions() const; + std::string getPlusOptions() const override; /// Returns global options for 'CreateTransmissionWorkspaceAuto' - std::string getTransmissionOptions() const; + std::string getTransmissionOptions() const override; /// Returns global options for 'ReflectometryReductionOneAuto' - std::string getReductionOptions() const; + std::string getReductionOptions() const override; /// Returns global options for 'Stitch1DMany' - std::string getStitchOptions() const; + std::string getStitchOptions() const override; private: void createPlusHints(); diff --git a/MantidQt/CustomInterfaces/src/Reflectometry/QtReflMainWindowView.cpp b/MantidQt/CustomInterfaces/src/Reflectometry/QtReflMainWindowView.cpp index 43399c538f3..3c082f951ec 100644 --- a/MantidQt/CustomInterfaces/src/Reflectometry/QtReflMainWindowView.cpp +++ b/MantidQt/CustomInterfaces/src/Reflectometry/QtReflMainWindowView.cpp @@ -64,10 +64,11 @@ 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); +void QtReflMainWindowView::giveUserCritical(const std::string &prompt, + const std::string &title) { + QMessageBox::critical(this, QString::fromStdString(title), + QString::fromStdString(prompt), QMessageBox::Ok, + QMessageBox::Ok); } /** @@ -75,10 +76,11 @@ 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); +void QtReflMainWindowView::giveUserWarning(const std::string &prompt, + const std::string &title) { + QMessageBox::warning(this, QString::fromStdString(title), + QString::fromStdString(prompt), QMessageBox::Ok, + QMessageBox::Ok); } /** @@ -86,9 +88,10 @@ 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, +void QtReflMainWindowView::giveUserInfo(const std::string &prompt, + const std::string &title) { + QMessageBox::information(this, QString::fromStdString(title), + QString::fromStdString(prompt), QMessageBox::Ok, QMessageBox::Ok); } @@ -98,9 +101,10 @@ Ask the user a Yes/No question @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) { +bool QtReflMainWindowView::askUserYesNo(const std::string &prompt, + const std::string &title) { auto response = QMessageBox::question( - this, QString(title.c_str()), QString(prompt.c_str()), + this, QString::fromStdString(title), QString::fromStdString(prompt), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if (response == QMessageBox::Yes) { return true; diff --git a/MantidQt/CustomInterfaces/src/Reflectometry/ReflMainWindowPresenter.cpp b/MantidQt/CustomInterfaces/src/Reflectometry/ReflMainWindowPresenter.cpp index 66884b4b604..0a58beb7542 100644 --- a/MantidQt/CustomInterfaces/src/Reflectometry/ReflMainWindowPresenter.cpp +++ b/MantidQt/CustomInterfaces/src/Reflectometry/ReflMainWindowPresenter.cpp @@ -73,8 +73,8 @@ 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) { +void ReflMainWindowPresenter::giveUserCritical(const std::string &prompt, + const std::string &title) { m_view->giveUserCritical(prompt, title); } @@ -84,8 +84,8 @@ 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) { +void ReflMainWindowPresenter::giveUserWarning(const std::string &prompt, + const std::string &title) { m_view->giveUserWarning(prompt, title); } @@ -95,8 +95,8 @@ 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) { +void ReflMainWindowPresenter::giveUserInfo(const std::string &prompt, + const std::string &title) { m_view->giveUserInfo(prompt, title); } @@ -107,8 +107,8 @@ Tells the view to ask the user a Yes/No question @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) { +bool ReflMainWindowPresenter::askUserYesNo(const std::string &prompt, + const std::string &title) { return m_view->askUserYesNo(prompt, title); } @@ -148,4 +148,4 @@ void ReflMainWindowPresenter::checkPtrValid( throw std::invalid_argument("Could not read settings"); } } -} \ No newline at end of file +} diff --git a/MantidQt/CustomInterfaces/test/ReflMockObjects.h b/MantidQt/CustomInterfaces/test/ReflMockObjects.h index 0dd4c8d1029..6daba719226 100644 --- a/MantidQt/CustomInterfaces/test/ReflMockObjects.h +++ b/MantidQt/CustomInterfaces/test/ReflMockObjects.h @@ -94,10 +94,11 @@ public: MOCK_METHOD3(askUserString, std::string(const std::string &, const std::string &, const std::string &)); - MOCK_METHOD2(askUserYesNo, bool(std::string, std::string)); - MOCK_METHOD2(giveUserWarning, void(std::string, std::string)); - MOCK_METHOD2(giveUserCritical, void(std::string, std::string)); - MOCK_METHOD2(giveUserInfo, void(std::string, std::string)); + MOCK_METHOD2(askUserYesNo, bool(const std::string &, const std::string &)); + MOCK_METHOD2(giveUserWarning, void(const std::string &, const std::string &)); + MOCK_METHOD2(giveUserCritical, + void(const std::string &, const std::string &)); + MOCK_METHOD2(giveUserInfo, void(const std::string &, const std::string &)); MOCK_METHOD1(runPythonAlgorithm, std::string(const std::string &)); ~MockMainWindowView() override{}; }; @@ -135,10 +136,11 @@ public: MOCK_METHOD3(askUserString, std::string(const std::string &, const std::string &, const std::string &)); - MOCK_METHOD2(askUserYesNo, bool(std::string, std::string)); - MOCK_METHOD2(giveUserWarning, void(std::string, std::string)); - MOCK_METHOD2(giveUserCritical, void(std::string, std::string)); - MOCK_METHOD2(giveUserInfo, void(std::string, std::string)); + MOCK_METHOD2(askUserYesNo, bool(const std::string &, const std::string &)); + MOCK_METHOD2(giveUserWarning, void(const std::string &, const std::string &)); + MOCK_METHOD2(giveUserCritical, + void(const std::string &, const std::string &)); + MOCK_METHOD2(giveUserInfo, void(const std::string &, const std::string &)); MOCK_METHOD1(runPythonAlgorithm, std::string(const std::string &)); ~MockMainWindowPresenter() override{}; }; -- GitLab