Skip to content

Commit

Permalink
Re #6002. This should fix the workspace group.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Oct 26, 2012
1 parent 8e8f579 commit 4088754
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Code/Mantid/Framework/API/inc/MantidAPI/WorkspaceGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ class MANTID_API_DLL WorkspaceGroup : public Workspace
void workspaceDeleteHandle(Mantid::API::WorkspacePostDeleteNotification_ptr notice);
/// Observer for workspace delete notfications
Poco::NObserver<WorkspaceGroup, Mantid::API::WorkspacePostDeleteNotification> m_deleteObserver;
/// Callback when a after-replace notification is received
void workspaceReplaceHandle(Mantid::API::WorkspaceAfterReplaceNotification_ptr notice);
/// Observer for workspace after-replace notfications
Poco::NObserver<WorkspaceGroup, Mantid::API::WorkspaceAfterReplaceNotification> m_replaceObserver;
/// Callback when a before-replace notification is received
void workspaceReplaceHandle(Mantid::API::WorkspaceBeforeReplaceNotification_ptr notice);
/// Observer for workspace before-replace notfications
Poco::NObserver<WorkspaceGroup, Mantid::API::WorkspaceBeforeReplaceNotification> m_replaceObserver;
/// The list of workspace pointers in the group
std::vector<Workspace_sptr> m_workspaces;
/// Flag as to whether the observers have been added to the ADS
Expand Down
15 changes: 11 additions & 4 deletions Code/Mantid/Framework/API/src/WorkspaceGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ void WorkspaceGroup::print() const
*/
void WorkspaceGroup::workspaceDeleteHandle(Mantid::API::WorkspacePostDeleteNotification_ptr notice)
{
Poco::Mutex::ScopedLock _lock(m_mutex);
const std::string deletedName = notice->object_name();
if( !this->contains(deletedName)) return;

Expand All @@ -225,20 +226,23 @@ void WorkspaceGroup::workspaceDeleteHandle(Mantid::API::WorkspacePostDeleteNotif
* Replaces a member if it was replaced in the ADS.
* @param notice :: A pointer to a workspace after-replace notificiation object
*/
void WorkspaceGroup::workspaceReplaceHandle(Mantid::API::WorkspaceAfterReplaceNotification_ptr notice)
void WorkspaceGroup::workspaceReplaceHandle(Mantid::API::WorkspaceBeforeReplaceNotification_ptr notice)
{
Poco::Mutex::ScopedLock _lock(m_mutex);
observeADSNotifications(false);
bool isObserving = m_observingADS;
if ( isObserving )
observeADSNotifications( false );
const std::string replacedName = notice->object_name();
for(auto citr=m_workspaces.begin(); citr!=m_workspaces.end(); ++citr)
{
if ( (**citr).name() == replacedName )
{
*citr = notice->object();
*citr = notice->new_object();
break;
}
}
observeADSNotifications(true);
if ( isObserving )
observeADSNotifications( true );
}

/**
Expand All @@ -247,6 +251,7 @@ void WorkspaceGroup::workspaceReplaceHandle(Mantid::API::WorkspaceAfterReplaceNo
*/
bool WorkspaceGroup::isEmpty() const
{
Poco::Mutex::ScopedLock _lock(m_mutex);
return m_workspaces.empty();
}

Expand All @@ -259,6 +264,7 @@ bool WorkspaceGroup::isEmpty() const
*/
bool WorkspaceGroup::areNamesSimilar() const
{
Poco::Mutex::ScopedLock _lock(m_mutex);
if(m_workspaces.empty()) return false;

//Check all the members are of similar names
Expand All @@ -285,6 +291,7 @@ bool WorkspaceGroup::areNamesSimilar() const
*/
void WorkspaceGroup::updated() const
{
Poco::Mutex::ScopedLock _lock(m_mutex);
if ( m_observingADS )
{
try
Expand Down
7 changes: 6 additions & 1 deletion Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,9 @@ void MantidDockWidget::populateWorkspaceGroupData(Mantid::API::WorkspaceGroup_sp
else
{
QString itemName = QString("Unnamed_%1").arg(unnamedCount);
MantidTreeWidgetItem *ws_item = new MantidTreeWidgetItem(QStringList(itemName), m_tree);
MantidTreeWidgetItem *item = new MantidTreeWidgetItem(QStringList(itemName), m_tree);
setItemIcon(item, member_ws);
ws_item->addChild(item);
++unnamedCount;
}
}
Expand Down Expand Up @@ -869,6 +871,8 @@ void MantidDockWidget::removeWorkspaceEntry(const QString & ws_name)
*/
void MantidDockWidget::renameWorkspaceEntry(const QString & ws_name, const QString& new_name)
{
(void)ws_name;
(void)new_name;
scheduleFindAbandonedWorkspaces();
}

Expand All @@ -878,6 +882,7 @@ void MantidDockWidget::renameWorkspaceEntry(const QString & ws_name, const QStri
*/
void MantidDockWidget::updateWorkspaceGroup(const QString & group_name)
{
(void)group_name;
scheduleFindAbandonedWorkspaces();
}

Expand Down

0 comments on commit 4088754

Please sign in to comment.