diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/SplatterPlotView.h b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/SplatterPlotView.h index ab87a452167b85488870518caaec09b9d0ca2eb9..7c44cfcb49acc6735f4c76346e95b89f96937a03 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/SplatterPlotView.h +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/SplatterPlotView.h @@ -95,6 +95,8 @@ signals: public slots: /// Check the coordinates for the peaks overlay if necessary void checkPeaksCoordinates(); + /// Listen to destruction of peak sources + void onPeakSourceDestroyed(); protected slots: /// Check state of toggle button with respect to peak coordinates. diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/SplatterPlotView.cpp b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/SplatterPlotView.cpp index 08a110a003a22ac313df0fadc1c0fb450b837fc5..7f357727b7d6bf85f1ac49565fde8f0fd2d2992a 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/SplatterPlotView.cpp +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/SplatterPlotView.cpp @@ -162,6 +162,9 @@ void SplatterPlotView::render() { this->peaksSource.append(src); renderType = "Wireframe"; + // Connect the peak source to a listener, to detect its destruction + QObject::connect(src, SIGNAL(destroyed()), + this, SLOT(onPeakSourceDestroyed())); } // Show the data @@ -308,6 +311,34 @@ void SplatterPlotView::destroyPeakSources() this->peaksSource.clear(); } +/** + * React to the destruction of a peak source, mainly unregister it from the peakSource container + */ +void SplatterPlotView::onPeakSourceDestroyed() { + pqServer *server = pqActiveObjects::instance().activeServer(); + pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel(); + QList<pqPipelineSource *> sources; + sources = smModel->findItems<pqPipelineSource *>(server); + + // Check for each source in the peakSource container, if it still is an existing source + for (QList<QPointer<pqPipelineSource>>::Iterator it = peaksSource.begin(); it != peaksSource.end();) { + bool foundSource = false; + for (QList<pqPipelineSource*>::Iterator source = sources.begin(); source != sources.end(); ++source) { + // Check if the source registered in PV matches our current peak source + if ((*source) == (*it)) { + foundSource = true; + } + } + + if (!foundSource) { + it = peaksSource.erase(it); + } + else { + ++it; + } + } +} + /** * This function reads the coordinates from the probe point plugin and * passes them on to a listening serivce that will handle them in the