Skip to content

Commit

Permalink
Restore selection after dock updates. Re #8032
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Sep 27, 2013
1 parent 6c63a94 commit ec1ade8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ void MantidDockWidget::populateChildData(QTreeWidgetItem* item)
auto ws = group->getItem(i);
auto * node = addTreeEntry(std::make_pair(ws->name(), ws), item);
excludeItemFromSort(node);
if(m_selectedNames.contains(node->text(0))) node->setSelected(true);
}
}
else
Expand Down Expand Up @@ -378,13 +379,24 @@ void MantidDockWidget::setTreeUpdating(const bool state)
void MantidDockWidget::populateTopLevel(const std::map<std::string,Mantid::API::Workspace_sptr> & topLevelItems,
const QStringList & expanded)
{
// collect names of selected workspaces
QList<QTreeWidgetItem *> selected = m_tree->selectedItems();
m_selectedNames.clear(); // just in case
foreach( QTreeWidgetItem *item, selected)
{
m_selectedNames << item->text(0);
}

// populate the tree from scratch
m_tree->clear();
auto iend = topLevelItems.end();
for(auto it = topLevelItems.begin(); it != iend; ++it)
{
auto *node = addTreeEntry(*it);
if(expanded.contains(node->text(0))) node->setExpanded(true);
if(m_selectedNames.contains(node->text(0))) node->setSelected(true);
}
m_selectedNames.clear();
}

/**
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidDock.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ private slots:
QAtomicInt m_updateCount;
bool m_treeUpdating;
Mantid::API::AnalysisDataServiceImpl & m_ads;
/// Temporarily keeps names of selected workspaces during tree update
/// in order to restore selection after update
QStringList m_selectedNames;

static Mantid::Kernel::Logger& logObject;
};
Expand Down

0 comments on commit ec1ade8

Please sign in to comment.