diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DataComparison.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DataComparison.h index 808de84da6af..c6d5541c54eb 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DataComparison.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DataComparison.h @@ -6,10 +6,9 @@ //---------------------- #include "ui_DataComparison.h" #include "MantidQtAPI/UserSubWindow.h" +#include "MantidQtAPI/WorkspaceObserver.h" #include "MantidAPI/MatrixWorkspace.h" -#include - #include #include #include @@ -21,7 +20,7 @@ namespace MantidQt { namespace CustomInterfaces { - class DataComparison : public MantidQt::API::UserSubWindow + class DataComparison : public MantidQt::API::UserSubWindow, public MantidQt::API::WorkspaceObserver { Q_OBJECT @@ -79,6 +78,11 @@ namespace CustomInterfaces int getInitialColourIndex(); private: + // Handlers for ADS events + void preDeleteHandle(const std::string& wsName,const boost::shared_ptr ws); + void renameHandle(const std::string &oldName, const std::string &newName); + void afterReplaceHandle(const std::string& wsName,const boost::shared_ptr ws); + // The form generated by Qt Designer Ui::DataComparison m_uiForm; diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/DataComparison.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/DataComparison.cpp index ac2b4b17b2ce..18a9da6e02ca 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/DataComparison.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/DataComparison.cpp @@ -31,9 +31,13 @@ using namespace Mantid::API; ///Constructor DataComparison::DataComparison(QWidget *parent) : UserSubWindow(parent), + WorkspaceObserver(), m_plot(new QwtPlot(parent)), m_diffWorkspaceNames(qMakePair(QString(), QString())) { + observeAfterReplace(); + observeRename(); + observePreDelete(); } @@ -590,3 +594,84 @@ void DataComparison::resetView() // Set this as the default zoom level m_zoomTool->setZoomBase(true); } + + +/** + * Handles removing a workspace when it is deleted from ADS. + * + * @param wsName Name of the workspace being deleted + * @param ws Pointer to the workspace + */ +void DataComparison::preDeleteHandle(const std::string& wsName,const boost::shared_ptr ws) +{ + UNUSED_ARG(ws); + QString oldWsName = QString::fromStdString(wsName); + + // Find the row in the data table for the workspace + int numRows = m_uiForm.twCurrentData->rowCount(); + for(int row = 0; row < numRows; row++) + { + // Remove the row + QString workspaceName = m_uiForm.twCurrentData->item(row, WORKSPACE_NAME)->text(); + if(workspaceName == oldWsName) + { + m_uiForm.twCurrentData->removeRow(row); + break; + } + } + + // Detach the old curve from the plot if it exists + if(m_curves.contains(oldWsName)) + m_curves[oldWsName]->attach(NULL); + + // Update the plot + plotWorkspaces(); +} + + +/** + * Handle a workspace being renamed. + * + * @param oldName Old name for the workspace + * @param newName New name for the workspace + */ +void DataComparison::renameHandle(const std::string &oldName, const std::string &newName) +{ + QString oldWsName = QString::fromStdString(oldName); + + // Find the row in the data table for the workspace + int numRows = m_uiForm.twCurrentData->rowCount(); + for(int row = 0; row < numRows; row++) + { + // Rename the workspace in the data table + QString workspaceName = m_uiForm.twCurrentData->item(row, WORKSPACE_NAME)->text(); + if(workspaceName == oldWsName) + { + m_uiForm.twCurrentData->item(row, WORKSPACE_NAME)->setText(QString::fromStdString(newName)); + break; + } + } + + // Detach the old curve from the plot if it exists + if(m_curves.contains(oldWsName)) + m_curves[oldWsName]->attach(NULL); + + // Update the plot + plotWorkspaces(); +} + + +/** + * Handle replotting after a workspace has been changed. + * + * @param wsName Name of changed workspace + * @ws Pointer to changed workspace + */ +void DataComparison::afterReplaceHandle(const std::string& wsName,const boost::shared_ptr ws) +{ + UNUSED_ARG(wsName); + UNUSED_ARG(ws); + + // Update the plot + plotWorkspaces(); +}