Skip to content

Commit

Permalink
Improved run-range parse logic. Refs #8317.
Browse files Browse the repository at this point in the history
- Added tooltip and removed input mask from run-range field.
  • Loading branch information
jawrainey committed Nov 1, 2013
1 parent 8685cf8 commit d9b068c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
51 changes: 32 additions & 19 deletions Code/Mantid/Framework/ICat/src/CatalogSearch.cpp
Expand Up @@ -20,8 +20,8 @@ This algorithm searches for the investigations and stores the search results in
#include "MantidKernel/FacilityInfo.h"
#include "MantidAPI/ICatalog.h"


#include<limits>
#include <boost/algorithm/string/regex.hpp>
#include <limits>

namespace Mantid
{
Expand Down Expand Up @@ -135,35 +135,48 @@ namespace Mantid
// Obtain the ICAT4 runRange input text.
std::string runRange = getProperty("runRange");

// A container to hold the range of run numbers.
std::vector<std::string> runNumbers;
// Split the input text by "-" and add contents to runNumbers.
boost::split(runNumbers,runRange,boost::is_any_of("-"));

// Has the user input a runRange?
if (!runRange.empty())
{
double leftSide, rightSide;
// A container to hold the range of run numbers.
std::vector<std::string> runNumbers;
// Split the input text by "-",":" or "," and add contents to runNumbers.
boost::algorithm::split_regex(runNumbers, runRange, boost::regex("-|:"));

double startRange = 0;
double endRange = 0;

// If the user has only input a start range ("4444" or "4444-").
if (!runNumbers.at(0).empty())
{
leftSide = boost::lexical_cast<double>(runNumbers.at(0));
}
else if (runNumbers.at(0).empty() && !runNumbers.at(1).empty())
{
leftSide = boost::lexical_cast<double>(runNumbers.at(1)) - 100;
startRange = boost::lexical_cast<double>(runNumbers.at(0));
// We set the end range to be equal now, so we do not have to do a check if it exists later.
endRange = boost::lexical_cast<double>(runNumbers.at(0));
}

if (!runNumbers.at(1).empty())
// If the user has input a start and end range, or just an end range ("4444-4449" or "-4449").
if (runNumbers.size() == 2)
{
rightSide = boost::lexical_cast<double>(runNumbers.at(1));
// Has the user input an end range...
if (!runNumbers.at(1).empty())
{
endRange = boost::lexical_cast<double>(runNumbers.at(1));

// If they have not chosen a start range ("-4449");
if (startRange == 0)
{
startRange = boost::lexical_cast<double>(runNumbers.at(1));
}
}
}
else if (runNumbers.at(1).empty() && !runNumbers.at(0).empty())

if (startRange > endRange)
{
rightSide = boost::lexical_cast<double>(runNumbers.at(0)) + 100;
throw std::runtime_error("Run end number cannot be lower than run start number.");
}

params.setRunStart(leftSide);
params.setRunEnd(rightSide);
params.setRunStart(startRange);
params.setRunEnd(endRange);
}

std::string instrument = getPropertyValue("Instrument");
Expand Down
Expand Up @@ -421,14 +421,17 @@
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="RunRange">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enter a start range, end range, or both seperated by a hyphen (-) or colon (:).&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="inputMethodHints">
<set>Qt::ImhDigitsOnly</set>
</property>
<property name="inputMask">
<string>999999-999999; </string>
<string/>
</property>
<property name="text">
<string>-</string>
<string/>
</property>
</widget>
</item>
Expand Down

0 comments on commit d9b068c

Please sign in to comment.