diff --git a/docs/source/release/v5.1.0/mantidworkbench.rst b/docs/source/release/v5.1.0/mantidworkbench.rst index 0c558d2fe77725a4fcdb736f378b15ec25c95f29..8107b1d6ff443e29d2cf3dfa76844468d4f6fabe 100644 --- a/docs/source/release/v5.1.0/mantidworkbench.rst +++ b/docs/source/release/v5.1.0/mantidworkbench.rst @@ -23,6 +23,8 @@ Bugfixes - Fixed a bug where setting columns to Y error in table workspaces wasn't working. The links between the Y error and Y columns weren't being set up properly. - Fixed a crash when you selected a spectra to plot that was not present in a workspace. +- Fixed a crash when you defined a new Fit Function after deleting a plot. - The scale of the color bars on colorfill plots of ragged workspaces now uses the maximum and minimum values of the data. + :ref:`Release 5.1.0 <v5.1.0>` diff --git a/qt/widgets/common/CMakeLists.txt b/qt/widgets/common/CMakeLists.txt index c5e06592e173490485b1fd0be073019534abb157..6a92f428600717b9fee7879f5e20d1db153130ee 100644 --- a/qt/widgets/common/CMakeLists.txt +++ b/qt/widgets/common/CMakeLists.txt @@ -931,6 +931,7 @@ set(TEST_FILES test/FileDialogHandlerTest.h test/FindFilesThreadPoolManagerTest.h test/FindFilesWorkerTest.h + test/FitPropertyBrowserTest.h test/FunctionModelTest.h test/FunctionMultiDomainPresenterTest.h test/FunctionBrowserUtilsTest.h @@ -976,6 +977,7 @@ set( test/FileDialogHandlerTest.h test/FindFilesThreadPoolManagerTest.h test/FindFilesWorkerTest.h + test/FitPropertyBrowserTest.h test/FunctionModelTest.h test/FunctionMultiDomainPresenterTest.h test/FunctionBrowserUtilsTest.h @@ -1047,6 +1049,7 @@ set( test/FileDialogHandlerTest.h test/FindFilesThreadPoolManagerTest.h test/FindFilesWorkerTest.h + test/FitPropertyBrowserTest.h test/InterfaceManagerTest.h test/QtJSONUtilsTest.h test/RepoModelTest.h diff --git a/qt/widgets/common/src/FitPropertyBrowser.cpp b/qt/widgets/common/src/FitPropertyBrowser.cpp index b23915349da946f92bf119023115179bc659ac5a..a7835c400c3bdd993635fdeb9dcb8e1b65ce86b5 100644 --- a/qt/widgets/common/src/FitPropertyBrowser.cpp +++ b/qt/widgets/common/src/FitPropertyBrowser.cpp @@ -713,6 +713,12 @@ void FitPropertyBrowser::executeSetupManageMenu(const QString &item) { /// Destructor FitPropertyBrowser::~FitPropertyBrowser() { m_compositeFunction.reset(); + + // remove the FunctionFactory Observer + using Mantid::API::FunctionFactory; + FunctionFactory::Instance().notificationCenter.removeObserver( + m_updateObserver); + m_browser->unsetFactoryForManager(m_enumManager); m_browser->unsetFactoryForManager(m_boolManager); m_browser->unsetFactoryForManager(m_intManager); diff --git a/qt/widgets/common/test/FitPropertyBrowserTest.h b/qt/widgets/common/test/FitPropertyBrowserTest.h new file mode 100644 index 0000000000000000000000000000000000000000..9fc51b0d84f69cfb12eda853df202a147076572c --- /dev/null +++ b/qt/widgets/common/test/FitPropertyBrowserTest.h @@ -0,0 +1,60 @@ +// Mantid Repository : https://github.com/mantidproject/mantid +// +// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, +// NScD Oak Ridge National Laboratory, European Spallation Source, +// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS +// SPDX - License - Identifier: GPL - 3.0 + +#pragma once + +#include "MantidAPI/FunctionFactory.h" +#include "MantidAPI/IFunction1D.h" +#include "MantidAPI/ParamFunction.h" +#include "MantidQtWidgets/Common/FitPropertyBrowser.h" +#include <cxxtest/TestSuite.h> + +using namespace Mantid::API; + +class FitPropertyBrowserTest_Funct : public ParamFunction, public IFunction1D { +public: + FitPropertyBrowserTest_Funct() { + declareParameter("b0"); + declareParameter("b1"); + } + + std::string name() const override { return "FitPropertyBrowserTest_Funct"; } + + void function1D(double *out, const double *xValues, + const size_t nData) const override { + UNUSED_ARG(out); + UNUSED_ARG(xValues); + UNUSED_ARG(nData); + } + void functionDeriv1D(Jacobian *out, const double *xValues, + const size_t nData) override { + UNUSED_ARG(out); + UNUSED_ARG(xValues); + UNUSED_ARG(nData); + } +}; + +DECLARE_FUNCTION(FitPropertyBrowserTest_Funct) + +class FitPropertyBrowserTest : public CxxTest::TestSuite { +public: + // This is a very specific test for a bug that is now fixed to prevent + // regression + void test_FunctionFactory_notification_is_released() { + + // create a FunctionBrowser + auto fpBrowser = + std::make_unique<MantidQt::MantidWidgets::FitPropertyBrowser>(); + // initialise it - this adds an observer on the function factory update + // message + fpBrowser->init(); + // delete the FunctionBrowser + fpBrowser.reset(); + // Make sure the FunctionFactory does not have a dead link as an observer + TS_ASSERT_THROWS_NOTHING(FunctionFactory::Instance().unsubscribe( + "FitPropertyBrowserTest_Funct");) + } +};