Skip to content

Commit

Permalink
Refs #10302 Add getUnusedGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Jeffery committed Oct 2, 2014
1 parent 89fdb52 commit aa28f0c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
Expand Up @@ -57,6 +57,8 @@ namespace MantidQt
Mantid::API::Workspace_sptr loadRun(const std::string& run, const std::string& instrument);
//get the run number of a TOF workspace
std::string getRunNumber(const Mantid::API::Workspace_sptr& ws);
//get an unused group id
int getUnusedGroup(std::vector<size_t> ignoredRows = std::vector<size_t>()) const;
//make a transmission workspace
Mantid::API::MatrixWorkspace_sptr makeTransWS(const std::string& transString);
//Validate a row
Expand Down
51 changes: 30 additions & 21 deletions Code/Mantid/MantidQt/CustomInterfaces/src/ReflMainViewPresenter.cpp
Expand Up @@ -25,6 +25,32 @@ namespace MantidQt
{
}

/**
* Finds the first unused group id
*/
int ReflMainViewPresenter::getUnusedGroup(std::vector<size_t> ignoredRows) const
{
std::vector<int> usedGroups;

//Scan through all the rows, working out which group ids are used
for(size_t idx = 0; idx < m_model->rowCount(); ++idx)
{
if(std::find(ignoredRows.begin(), ignoredRows.end(), idx) != ignoredRows.end())
continue;

//This is an unselected row. Add it to the list of used group ids
usedGroups.push_back(m_model->Int(idx, COL_GROUP));
}

int groupId = 0;

//While the group id is one of the used ones, increment it by 1
while(std::find(usedGroups.begin(), usedGroups.end(), groupId) != usedGroups.end())
groupId++;

return groupId;
}

/**
Process selected rows
*/
Expand Down Expand Up @@ -432,32 +458,15 @@ namespace MantidQt
*/
void ReflMainViewPresenter::groupRows()
{
std::vector<size_t> rows = m_view->getSelectedRowIndexes();
std::vector<int> usedGroups;

//First we need find the first unused group id

//Scan through all the rows, working out which group ids are used
for(size_t idx = 0; idx < m_model->rowCount(); ++idx)
{
//If this row is one of the selected rows we don't need to include it
if(std::find(rows.begin(), rows.end(), idx) != rows.end())
continue;

//This is an unselected row. At it to the list of used group ids
usedGroups.push_back(m_model->Int(idx, COL_GROUP));
}

int groupId = 0;

//While the group id is one of the used ones, increment it by 1
while(std::find(usedGroups.begin(), usedGroups.end(), groupId) != usedGroups.end())
groupId++;
const std::vector<size_t> rows = m_view->getSelectedRowIndexes();
//Find the first unused group id, ignoring the selected rows
const int groupId = getUnusedGroup(rows);

//Now we just have to set the group id on the selected rows
for(auto it = rows.begin(); it != rows.end(); ++it)
m_model->Int(*it, COL_GROUP) = groupId;

//Make sure the view updates
m_view->showTable(m_model);
}

Expand Down

0 comments on commit aa28f0c

Please sign in to comment.