Skip to content
Snippets Groups Projects
Commit 0182a096 authored by Sofia Antony's avatar Sofia Antony
Browse files

re#1175 - added a method to check the workspace group is empty and delete the...

re#1175 - added a method to check the workspace group is empty and delete the group if the it is empty.
parent 50fec5d5
No related branches found
No related tags found
No related merge requests found
......@@ -70,6 +70,9 @@ public:
void remove(const std::string& name);
void removeAll();
void deepRemoveAll();
/// This method returns true if the group is empty (no member workspace)
bool isEmpty();
private:
/// Private, unimplemented copy constructor
......
......@@ -117,5 +117,13 @@ void WorkspaceGroup::workspaceRenameHandle(Mantid::API::WorkspaceRenameNotificat
}
}
/**
* This method returns true if the workspace group is empty
*/
bool WorkspaceGroup::isEmpty()
{
return m_wsNames.empty();
}
} // namespace API
} // namespace Mantid
......@@ -457,7 +457,7 @@ void MantidDockWidget::removeWorkspaceEntry(const QString & ws_name)
return;
}
int childCounts=topItem->childCount();
for(int chIndex=0;chIndex<childCounts;++chIndex)
for(int chIndex=0;chIndex<childCounts;++chIndex)
{
QTreeWidgetItem* childItem= topItem->child(chIndex);
if(!childItem)
......@@ -468,7 +468,9 @@ void MantidDockWidget::removeWorkspaceEntry(const QString & ws_name)
if(!ws_name.compare(childItem->text(0)))
{
topItem->takeChild(chIndex);
parent_item = topItem;
parent_item = topItem;
deleteGroupWorkspaceIfEmpty(topItem);
}
}
}
......@@ -488,6 +490,43 @@ void MantidDockWidget::removeWorkspaceEntry(const QString & ws_name)
}
void MantidDockWidget::deleteGroupWorkspaceIfEmpty(QTreeWidgetItem* item)
{
//if there are no members in the group workspace delete the group workspace
if(item->childCount()==1)//workspace id
{
Workspace_sptr ws_sptr;
try
{
ws_sptr= Mantid::API::AnalysisDataService::Instance().retrieve(item->text(0).toStdString());
}
catch(Mantid::Kernel::Exception::NotFoundError &)
{
return;
}
WorkspaceGroup_sptr wsgrp_sptr;
try
{
wsgrp_sptr = boost::dynamic_pointer_cast<WorkspaceGroup>(ws_sptr);
}
catch(std::runtime_error&)
{
return;
}
if(!wsgrp_sptr)
{
return;
}
if(wsgrp_sptr->isEmpty())
{
//if the group workspace is empty
m_mantidUI->deleteWorkspace(item->text(0));
}
}
}
void MantidDockWidget::clickedWorkspace(QTreeWidgetItem* item, int)
{
......
......@@ -58,6 +58,7 @@ private:
void populateMatrixWorkspaceData(Mantid::API::MatrixWorkspace_sptr workspace, QTreeWidgetItem* ws_item);
void populateWorkspaceGroupData(Mantid::API::WorkspaceGroup_sptr workspace, QTreeWidgetItem* ws_item);
void populateTableWorkspaceData(Mantid::API::ITableWorkspace_sptr workspace, QTreeWidgetItem* ws_item);
void deleteGroupWorkspaceIfEmpty(QTreeWidgetItem* item);
protected:
MantidTreeWidget * m_tree;
......
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