Skip to content

Commit

Permalink
Merge pull request #531 from mantidproject/9505_Fitting_with_no_peaks
Browse files Browse the repository at this point in the history
Fitting with no peaks
  • Loading branch information
DanNixon committed Apr 8, 2015
2 parents 7330325 + 01f0cff commit aeeb9d0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "MantidQtAPI/HelpWindow.h"

#include <QMessageBox>

#include <qwt_symbol.h>

namespace MantidQt
Expand Down Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class MockALCPeakFittingView : public IALCPeakFittingView
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());
};

Expand Down Expand Up @@ -127,6 +128,14 @@ class ALCPeakFittingPresenterTest : public CxxTest::TestSuite
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);
Expand Down

0 comments on commit aeeb9d0

Please sign in to comment.