diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/ALCPeakFittingView.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/ALCPeakFittingView.h index 4768632e3b7790dba370202c497aee51d41ece50..102df05d9b3fca7ea77189a98ac6843b71b3ed62 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/ALCPeakFittingView.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/ALCPeakFittingView.h @@ -59,6 +59,7 @@ namespace CustomInterfaces void setParameter(const QString& funcIndex, const QString& paramName, double value); void setPeakPickerEnabled(bool enabled); void setPeakPicker(const IPeakFunction_const_sptr& peak); + void displayError(const QString& message); void help(); // -- End of IALCPeakFitting interface --------------------------------------------------------- diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/IALCPeakFittingView.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/IALCPeakFittingView.h index 34a4704f73582f8e8db260a0b73dcfad0aea9097..d03360376a02a6d2f5f54c33b75d7e5d50b9a738 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/IALCPeakFittingView.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Muon/IALCPeakFittingView.h @@ -86,6 +86,12 @@ namespace CustomInterfaces /// @param peak :: A new peak to represent virtual void setPeakPicker(const IPeakFunction_const_sptr& peak) = 0; + /** + * Pops-up an error box + * @param message :: Error message to display + */ + virtual void displayError(const QString& message) = 0; + /// Opens the Mantid Wiki web page virtual void help() = 0; diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Muon/ALCPeakFittingPresenter.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Muon/ALCPeakFittingPresenter.cpp index 1e71ccfa51709b97de049d6ddc2301cad22a9855..d9e6894ab05bffd76db4c765c16885fe031f6cbe 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/Muon/ALCPeakFittingPresenter.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Muon/ALCPeakFittingPresenter.cpp @@ -31,7 +31,12 @@ namespace CustomInterfaces void ALCPeakFittingPresenter::fit() { - m_model->fitPeaks(m_view->function("")); + IFunction_const_sptr func = m_view->function(""); + if ( func ) { + m_model->fitPeaks(func); + } else { + m_view->displayError("Couldn't fit an empty function"); + } } void ALCPeakFittingPresenter::onCurrentFunctionChanged() diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Muon/ALCPeakFittingView.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Muon/ALCPeakFittingView.cpp index d8183fe40bf20cce35c5a291c4c6d091cfea6cd6..c965b9d93e921ee4a2ae80ce7224c85f09f55812 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/Muon/ALCPeakFittingView.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Muon/ALCPeakFittingView.cpp @@ -2,6 +2,8 @@ #include "MantidQtAPI/HelpWindow.h" +#include <QMessageBox> + #include <qwt_symbol.h> namespace MantidQt @@ -109,6 +111,11 @@ void ALCPeakFittingView::help() MantidQt::API::HelpWindow::showCustomInterface(NULL, QString("Muon_ALC")); } +void ALCPeakFittingView::displayError(const QString& message) +{ + QMessageBox::critical(m_widget, "Error", message); +} + } // namespace CustomInterfaces } // namespace Mantid diff --git a/Code/Mantid/MantidQt/CustomInterfaces/test/ALCPeakFittingPresenterTest.h b/Code/Mantid/MantidQt/CustomInterfaces/test/ALCPeakFittingPresenterTest.h index 36b8851b2caf33b3371c1e855787d6afe2417340..d28fd640b27691fe2298d7021159d485e45c0c5a 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/test/ALCPeakFittingPresenterTest.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/test/ALCPeakFittingPresenterTest.h @@ -50,6 +50,7 @@ public: MOCK_METHOD1(setPeakPicker, void(const IPeakFunction_const_sptr&)); MOCK_METHOD1(setFunction, void(const IFunction_const_sptr&)); MOCK_METHOD3(setParameter, void(const QString&, const QString&, double)); + MOCK_METHOD1(displayError, void(const QString&)); MOCK_METHOD0(help, void()); }; @@ -127,6 +128,14 @@ public: presenter.initialize(); } + void test_fitEmptyFunction() + { + ON_CALL(*m_view, function(QString(""))).WillByDefault(Return(IFunction_const_sptr())); + EXPECT_CALL(*m_view, displayError(QString("Couldn't fit an empty function"))).Times(1); + + m_view->requestFit(); + } + void test_fit() { IFunction_sptr peaks = createGaussian(1,2,3);