diff --git a/qt/widgets/mplcpp/inc/MantidQtWidgets/MplCpp/MantidAxes.h b/qt/widgets/mplcpp/inc/MantidQtWidgets/MplCpp/MantidAxes.h index b8fe6481941fde78c67a7c7b86e28616576914db..5876a9af511bc3f76c4c43b4f4e3e3b26ab048b6 100644 --- a/qt/widgets/mplcpp/inc/MantidQtWidgets/MplCpp/MantidAxes.h +++ b/qt/widgets/mplcpp/inc/MantidQtWidgets/MplCpp/MantidAxes.h @@ -47,8 +47,8 @@ public: /// @name Artist removal/replacement ///@{ - void removeWorkspaceArtists(const Mantid::API::MatrixWorkspace_sptr &ws); - void replaceWorkspaceArtists(const Mantid::API::MatrixWorkspace_sptr &newWS); + bool removeWorkspaceArtists(const Mantid::API::MatrixWorkspace_sptr &ws); + bool replaceWorkspaceArtists(const Mantid::API::MatrixWorkspace_sptr &newWS); ///@} }; diff --git a/qt/widgets/mplcpp/src/MantidAxes.cpp b/qt/widgets/mplcpp/src/MantidAxes.cpp index c5df093cb1aa55e9db6894326d800969d7d89bae..dc3b4edfa56fc139116034ec4f7ef848ae4daedf 100644 --- a/qt/widgets/mplcpp/src/MantidAxes.cpp +++ b/qt/widgets/mplcpp/src/MantidAxes.cpp @@ -96,25 +96,27 @@ void MantidAxes::pcolormesh( * @param ws A reference to a workspace whose name is used to * lookup any artists for removal */ -void MantidAxes::removeWorkspaceArtists( +bool MantidAxes::removeWorkspaceArtists( const Mantid::API::MatrixWorkspace_sptr &ws) { GlobalInterpreterLock lock; + bool removed = false; try { - pyobj().attr("remove_workspace_artists")( + removed = pyobj().attr("remove_workspace_artists")( Python::NewRef(MatrixWorkpaceToPython()(ws))); } catch (Python::ErrorAlreadySet &) { throw Mantid::PythonInterface::PythonException(); } + return removed; } /** * Replace the artists on this axes instance that are based off this workspace * @param newWS A reference to the new workspace containing the data */ -void MantidAxes::replaceWorkspaceArtists( +bool MantidAxes::replaceWorkspaceArtists( const Mantid::API::MatrixWorkspace_sptr &newWS) { GlobalInterpreterLock lock; - pyobj().attr("replace_workspace_artists")( + return pyobj().attr("replace_workspace_artists")( Python::NewRef(MatrixWorkpaceToPython()(newWS))); } diff --git a/qt/widgets/plotting/src/Mpl/PreviewPlot.cpp b/qt/widgets/plotting/src/Mpl/PreviewPlot.cpp index f6581efa3701ed5d0c905de36cb1af07b9701b25..4554c8aca965723eb4176afd3a5f75509fed1ccd 100644 --- a/qt/widgets/plotting/src/Mpl/PreviewPlot.cpp +++ b/qt/widgets/plotting/src/Mpl/PreviewPlot.cpp @@ -588,15 +588,21 @@ QStringList PreviewPlot::linesWithErrors() const { */ void PreviewPlot::onWorkspaceRemoved( Mantid::API::WorkspacePreDeleteNotification_ptr nf) { + if (m_lines.isEmpty()) { + return; + } // Ignore non matrix workspaces if (auto ws = boost::dynamic_pointer_cast<MatrixWorkspace>(nf->object())) { // the artist may have already been removed. ignore the event is that is the // case + bool removed = false; try { - m_canvas->gca<MantidAxes>().removeWorkspaceArtists(ws); + removed = m_canvas->gca<MantidAxes>().removeWorkspaceArtists(ws); } catch (Mantid::PythonInterface::PythonException &) { } - this->replot(); + if (removed) { + this->replot(); + } } } @@ -606,13 +612,17 @@ void PreviewPlot::onWorkspaceRemoved( */ void PreviewPlot::onWorkspaceReplaced( Mantid::API::WorkspaceBeforeReplaceNotification_ptr nf) { + if (m_lines.isEmpty()) { + return; + } // Ignore non matrix workspaces if (auto oldWS = boost::dynamic_pointer_cast<MatrixWorkspace>(nf->oldObject())) { if (auto newWS = boost::dynamic_pointer_cast<MatrixWorkspace>(nf->newObject())) { - m_canvas->gca<MantidAxes>().replaceWorkspaceArtists(newWS); - this->replot(); + if (m_canvas->gca<MantidAxes>().replaceWorkspaceArtists(newWS)) { + this->replot(); + } } } }