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:
void needToHardReplot();
/// Signals that the axis scale has been changed
void axisScaleChanged();
/// Signals that workspace has been removed
void workspaceRemoved(Mantid::API::MatrixWorkspace_sptr);
public slots:
void showLegend(bool show);
......@@ -158,6 +160,7 @@ private slots:
void showContextMenu(QPoint position);
void handleViewToolSelect();
void handleAxisTypeSelect();
void removeWorkspace(Mantid::API::MatrixWorkspace_sptr ws);
private:
Ui::PreviewPlot m_uiForm;
......
......@@ -3,8 +3,8 @@
//------------------------------------------------------
#include "MantidQtWidgets/LegacyQwt/PreviewPlot.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/AnalysisDataService.h"
#include <Poco/Notification.h>
#include <Poco/NotificationCenter.h>
......@@ -22,7 +22,7 @@ using namespace Mantid::API;
namespace {
Mantid::Kernel::Logger g_log("PreviewPlot");
bool isNegative(double v) { return v <= 0.0; }
}
} // namespace
PreviewPlot::PreviewPlot(QWidget *parent, bool init)
: API::MantidWidget(parent),
......@@ -122,6 +122,9 @@ PreviewPlot::PreviewPlot(QWidget *parent, bool init)
connect(this, SIGNAL(needToReplot()), this, SLOT(replot()));
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() {
}
/**
* Handle a workspace being deleted from ADS.
*
* Removes it from the plot (via removeSpectrum).
*
* Handle a notifcation about a workspace being deleted from ADS.
* @param pNf Poco notification
*/
void PreviewPlot::handleRemoveEvent(WorkspacePreDeleteNotification_ptr pNf) {
MatrixWorkspace_sptr ws =
boost::dynamic_pointer_cast<MatrixWorkspace>(pNf->object());
auto ws = boost::dynamic_pointer_cast<MatrixWorkspace>(pNf->object());
// Ignore non matrix worksapces
if (!ws)
return;
if (ws)
// emit a queued signal to the queued slot
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);
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