From d9b068ca40abfaee396ec2f1d169504d8b2b7772 Mon Sep 17 00:00:00 2001 From: Jay Rainey Date: Fri, 1 Nov 2013 09:53:10 +0000 Subject: [PATCH] Improved run-range parse logic. Refs #8317. - Added tooltip and removed input mask from run-range field. --- .../Framework/ICat/src/CatalogSearch.cpp | 51 ++++++++++++------- .../inc/MantidQtMantidWidgets/ICatSearch2.ui | 7 ++- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/Code/Mantid/Framework/ICat/src/CatalogSearch.cpp b/Code/Mantid/Framework/ICat/src/CatalogSearch.cpp index 37a520687b04..73dca32ece70 100644 --- a/Code/Mantid/Framework/ICat/src/CatalogSearch.cpp +++ b/Code/Mantid/Framework/ICat/src/CatalogSearch.cpp @@ -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 +#include +#include namespace Mantid { @@ -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 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 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(runNumbers.at(0)); - } - else if (runNumbers.at(0).empty() && !runNumbers.at(1).empty()) - { - leftSide = boost::lexical_cast(runNumbers.at(1)) - 100; + startRange = boost::lexical_cast(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(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(runNumbers.at(1)); + // Has the user input an end range... + if (!runNumbers.at(1).empty()) + { + endRange = boost::lexical_cast(runNumbers.at(1)); + + // If they have not chosen a start range ("-4449"); + if (startRange == 0) + { + startRange = boost::lexical_cast(runNumbers.at(1)); + } + } } - else if (runNumbers.at(1).empty() && !runNumbers.at(0).empty()) + + if (startRange > endRange) { - rightSide = boost::lexical_cast(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"); diff --git a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/ICatSearch2.ui b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/ICatSearch2.ui index 3f618f715ae2..73e0b6f3288e 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/ICatSearch2.ui +++ b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/ICatSearch2.ui @@ -421,14 +421,17 @@ + + <html><head/><body><p>Enter a start range, end range, or both seperated by a hyphen (-) or colon (:).</p></body></html> + Qt::ImhDigitsOnly - 999999-999999; + - - +