Skip to content
Snippets Groups Projects
Unverified Commit e45f9cad authored by Martyn Gigg's avatar Martyn Gigg Committed by GitHub
Browse files

Merge pull request #22989 from samueljackson92/22946-indirect-msd-fit-mantid-crash

Fix PreviewPlot crash when removing workspace.
parents c276be85 99a0a2ce
No related branches found
No related tags found
No related merge requests found
...@@ -112,6 +112,8 @@ signals: ...@@ -112,6 +112,8 @@ signals:
void needToHardReplot(); void needToHardReplot();
/// Signals that the axis scale has been changed /// Signals that the axis scale has been changed
void axisScaleChanged(); void axisScaleChanged();
/// Signals that workspace has been removed
void workspaceRemoved(Mantid::API::MatrixWorkspace_sptr);
public slots: public slots:
void showLegend(bool show); void showLegend(bool show);
...@@ -158,6 +160,7 @@ private slots: ...@@ -158,6 +160,7 @@ private slots:
void showContextMenu(QPoint position); void showContextMenu(QPoint position);
void handleViewToolSelect(); void handleViewToolSelect();
void handleAxisTypeSelect(); void handleAxisTypeSelect();
void removeWorkspace(Mantid::API::MatrixWorkspace_sptr ws);
private: private:
Ui::PreviewPlot m_uiForm; Ui::PreviewPlot m_uiForm;
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
//------------------------------------------------------ //------------------------------------------------------
#include "MantidQtWidgets/LegacyQwt/PreviewPlot.h" #include "MantidQtWidgets/LegacyQwt/PreviewPlot.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/AnalysisDataService.h"
#include <Poco/Notification.h> #include <Poco/Notification.h>
#include <Poco/NotificationCenter.h> #include <Poco/NotificationCenter.h>
...@@ -22,7 +22,7 @@ using namespace Mantid::API; ...@@ -22,7 +22,7 @@ using namespace Mantid::API;
namespace { namespace {
Mantid::Kernel::Logger g_log("PreviewPlot"); Mantid::Kernel::Logger g_log("PreviewPlot");
bool isNegative(double v) { return v <= 0.0; } bool isNegative(double v) { return v <= 0.0; }
} } // namespace
PreviewPlot::PreviewPlot(QWidget *parent, bool init) PreviewPlot::PreviewPlot(QWidget *parent, bool init)
: API::MantidWidget(parent), : API::MantidWidget(parent),
...@@ -122,6 +122,9 @@ PreviewPlot::PreviewPlot(QWidget *parent, bool init) ...@@ -122,6 +122,9 @@ PreviewPlot::PreviewPlot(QWidget *parent, bool init)
connect(this, SIGNAL(needToReplot()), this, SLOT(replot())); connect(this, SIGNAL(needToReplot()), this, SLOT(replot()));
connect(this, SIGNAL(needToHardReplot()), this, SLOT(hardReplot())); connect(this, SIGNAL(needToHardReplot()), this, SLOT(hardReplot()));
connect(this, SIGNAL(workspaceRemoved(Mantid::API::MatrixWorkspace_sptr)),
this, SLOT(removeWorkspace(Mantid::API::MatrixWorkspace_sptr)),
Qt::QueuedConnection);
} }
/** /**
...@@ -562,23 +565,25 @@ void PreviewPlot::hardReplot() { ...@@ -562,23 +565,25 @@ void PreviewPlot::hardReplot() {
} }
/** /**
* Handle a workspace being deleted from ADS. * Handle a notifcation about a workspace being deleted from ADS.
*
* Removes it from the plot (via removeSpectrum).
*
* @param pNf Poco notification * @param pNf Poco notification
*/ */
void PreviewPlot::handleRemoveEvent(WorkspacePreDeleteNotification_ptr pNf) { void PreviewPlot::handleRemoveEvent(WorkspacePreDeleteNotification_ptr pNf) {
MatrixWorkspace_sptr ws = auto ws = boost::dynamic_pointer_cast<MatrixWorkspace>(pNf->object());
boost::dynamic_pointer_cast<MatrixWorkspace>(pNf->object());
// Ignore non matrix worksapces if (ws)
if (!ws) // emit a queued signal to the queued slot
return; emit workspaceRemoved(ws);
}
// Remove the workspace /**
* Remove the spectrum & replot when a workspace is removed.
*
* @param ws the workspace that is being removed.
*/
void PreviewPlot::removeWorkspace(MatrixWorkspace_sptr ws) {
// Remove the workspace on the main GUI thread
removeSpectrum(ws); removeSpectrum(ws);
emit needToReplot(); emit needToReplot();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment