diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainViewPresenter.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainViewPresenter.h index e6c30fd0670e..8376e1801b3b 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainViewPresenter.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/ReflMainViewPresenter.h @@ -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 ignoredRows = std::vector()) const; //make a transmission workspace Mantid::API::MatrixWorkspace_sptr makeTransWS(const std::string& transString); //Validate a row diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/ReflMainViewPresenter.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/ReflMainViewPresenter.cpp index e421184d6a0e..37ff2ec74281 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/ReflMainViewPresenter.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/ReflMainViewPresenter.cpp @@ -25,6 +25,32 @@ namespace MantidQt { } + /** + * Finds the first unused group id + */ + int ReflMainViewPresenter::getUnusedGroup(std::vector ignoredRows) const + { + std::vector 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 */ @@ -432,32 +458,15 @@ namespace MantidQt */ void ReflMainViewPresenter::groupRows() { - std::vector rows = m_view->getSelectedRowIndexes(); - std::vector 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 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); }