16#include <QApplication>
17#include <boost/algorithm/string.hpp>
32 : QRunnable(), m_parameters(
std::move(parameters)) {
33 qRegisterMetaType<MantidQt::API::FindFilesSearchResults>(
"FindFilesSearchResults");
51 std::vector<std::string> filenames;
52 QString valueForProperty;
58 error =
"No files specified.";
72 filenames = std::get<0>(searchResult);
73 valueForProperty = QString::fromStdString(std::get<1>(searchResult));
78 std::transform(paths.begin(), paths.end(), std::back_inserter(filenames),
79 [](
const auto &p) { return p.string(); });
80 valueForProperty =
"";
81 for (
auto const &filename : filenames) {
82 valueForProperty += QString::fromStdString(filename) +
",";
84 valueForProperty.chop(1);
90 std::vector<std::string> filestext;
94 auto it = filestext.begin();
95 for (; it != filestext.end(); ++it) {
96 boost::algorithm::trim(*it);
98 if ((!result.empty()) && std::filesystem::exists(result)) {
99 filenames.emplace_back(*it);
100 valueForProperty += QString::fromStdString(*it) +
",";
102 throw std::invalid_argument(
"File \"" + (*it) +
"\" not found");
105 valueForProperty.chop(1);
107 }
catch (std::exception &exc) {
111 error =
"An unknown error occurred while trying to locate the file(s). "
112 "Please contact the development team";
127 std::vector<std::string> filenames;
134 algorithm->initialize();
138 Property *prop = algorithm->getProperty(propName);
139 std::string valueForProperty = prop->
value();
145 filenames.emplace_back(fileProp->value());
146 }
else if (multiFileProp) {
150 std::vector<std::vector<std::string>> propertyFilenames = algorithm->getProperty(propName);
154 return std::make_pair(filenames, valueForProperty);
166 QCoreApplication::processEvents();
168 QCoreApplication::sendPostedEvents();
182 const std::vector<std::string> &filenames,
183 const std::string &valueForProperty) {
FindFilesWorker(FindFilesSearchParameters parameters)
Constructor.
std::pair< std::vector< std::string >, std::string > getFilesFromAlgorithm()
Use the specified algorithm and property to find files instead of using the FileFinder.
FindFilesSearchParameters m_parameters
Struct to hold the parameters of the search.
void finished(const FindFilesSearchResults &)
Signal emitted after the search is finished, regardless of whether any file was found.
FindFilesSearchResults createFindFilesSearchResult(const std::string &error, const std::vector< std::string > &filenames, const std::string &valueForProperty)
Helper method to create a search result object.
virtual void run() override
Override parent class run().
void finishSearching(const FindFilesSearchResults &result)
Emit search result if required.
This class finds data files given an instrument name (optionally) and a run number.
std::filesystem::path getFullPath(const std::string &filename, const bool ignoreDirs=false) const
Return the full path to the file given its name.
std::vector< std::filesystem::path > findRuns(const std::string &hintstr, const std::vector< std::string > &exts={}, const bool useExtsOnly=false) const
Find a list of files file given a hint.
A specialized class for dealing with file properties.
A property to allow a user to specify multiple files to load.
Base class for properties.
virtual std::string value() const =0
Returns the value of the property as a string.
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::vector< T > flattenVector(const std::vector< std::vector< T > > &v)
A convenience function to "flatten" the given vector of vectors into a single vector.
POD struct to hold details about the parameters of a file search.
bool isForRunFiles
Whether the search is for experimental run data.
std::string algorithmName
The name of the algorithm to load files with.
std::vector< std::string > extensions
any additional extensions that we want to consider
bool isOptional
Whether the search is optional (i.e. a failed search means no error).
std::string algorithmProperty
The name of the property on the algorithm to use for searching.
std::string searchText
The text to use as a hint to search for files.
POD struct to hold details about the results of a file search.
std::vector< std::string > filenames
A list of filenames that matched the search hint.
std::string valueForProperty
The value to set the algorithm property to.
std::string error
A string repsresenting the error message. Empty if the search succeded.