Skip to content

Commit

Permalink
Re #5816. Fixed it in MantidDockWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Sep 18, 2012
1 parent 27ba445 commit 94b42f1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
52 changes: 39 additions & 13 deletions Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ QDockWidget(tr("Workspaces"),parent), m_mantidUI(mui), m_known_groups()
connect(m_tree,SIGNAL(itemSelectionChanged()),this,SLOT(treeSelectionChanged()));

connect(m_tree, SIGNAL(itemExpanded(QTreeWidgetItem*)), this, SLOT(populateChildData(QTreeWidgetItem*)));

connect(this,SIGNAL(rerunFindAbandonedWorkspaces()),this,SLOT(findAbandonedWorkspaces()),Qt::QueuedConnection);
}

/**
Expand Down Expand Up @@ -919,33 +921,57 @@ void MantidDockWidget::findAbandonedWorkspaces()
topItems.append( m_tree->topLevelItem(i)->text(0) );
}
// list of all workspaces in the ADS
auto workspaces = Mantid::API::AnalysisDataService::Instance().getObjects();
auto wsSet = Mantid::API::AnalysisDataService::Instance().getObjectNames();
std::vector<std::string> workspaces( wsSet.begin(), wsSet.end() );
// find all groups, remove their members from workspaces
for( auto ws = workspaces.begin(); ws != workspaces.end(); ++ws )
for( auto wsName = workspaces.begin(); wsName != workspaces.end(); ++wsName )
{
if ( !(*ws) ) continue;
if ( auto group = boost::dynamic_pointer_cast<Mantid::API::WorkspaceGroup>( *ws ) )
try
{
size_t n = static_cast<size_t>( group->getNumberOfEntries() );
for(size_t i = 0; i < n; ++i)
auto ws = Mantid::API::AnalysisDataService::Instance().retrieve( *wsName );
if ( auto group = boost::dynamic_pointer_cast<Mantid::API::WorkspaceGroup>( ws ) )
{
auto it = std::find(workspaces.begin(), workspaces.end(), group->getItem( i ));
if ( it != workspaces.end() )
size_t n = static_cast<size_t>( group->getNumberOfEntries() );
for(size_t i = 0; i < n; ++i)
{
it->reset();
if ( i >= group->getNumberOfEntries() )
{
emit rerunFindAbandonedWorkspaces();
return;
}
const std::string name = group->getItem(i)->name();
auto it = std::find( workspaces.begin(), workspaces.end(), name );
if ( it != workspaces.end() )
{
it->clear();
}
}
}
}
catch(...)
{
emit rerunFindAbandonedWorkspaces();
return;
}
}
// now workspaces contains only top-level items
for( auto ws = workspaces.begin(); ws != workspaces.end(); ++ws )
for( auto wsName = workspaces.begin(); wsName != workspaces.end(); ++wsName )
{
if ( !(*ws) ) continue;
QString qName = QString::fromStdString( (**ws).name() );
if ( wsName->empty() ) continue;
QString qName = QString::fromStdString( *wsName );
auto item = m_tree->findItems( qName, Qt::MatchFixedString );
if ( item.isEmpty() )
{
addTreeEntry( qName, *ws );
try
{
auto ws = Mantid::API::AnalysisDataService::Instance().retrieve( *wsName );
addTreeEntry( qName, ws );
}
catch(...)
{
emit rerunFindAbandonedWorkspaces();
return;
}
}
else
{
Expand Down
5 changes: 4 additions & 1 deletion Code/Mantid/MantidPlot/src/Mantid/MantidDock.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class MantidDockWidget: public QDockWidget
QString getSelectedWorkspaceName() const;
Mantid::API::Workspace_sptr getSelectedWorkspace() const;

signals:
void rerunFindAbandonedWorkspaces();

public slots:
void clickedWorkspace(QTreeWidgetItem*, int);
void deleteWorkspaces();
Expand Down Expand Up @@ -80,6 +83,7 @@ private slots:
void showDetectorTable();
void convertToMatrixWorkspace();
void convertMDHistoToMatrixWorkspace();
void findAbandonedWorkspaces();

private:
void createWorkspaceMenuActions();
Expand All @@ -102,7 +106,6 @@ private slots:
void addTableWorkspaceMenuItems(QMenu * menu) const;

void excludeItemFromSort(MantidTreeWidgetItem *item);
void findAbandonedWorkspaces();

protected:
MantidTreeWidget * m_tree;
Expand Down

0 comments on commit 94b42f1

Please sign in to comment.