Mantid
Loading...
Searching...
No Matches
FileFinderWidget.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10
18
19#include <Poco/File.h>
20#include <QDragEnterEvent>
21#include <QDropEvent>
22#include <QFileInfo>
23#include <QHash>
24#include <QMimeData>
25#include <QStringList>
26#include <QUrl>
27#include <QtConcurrentRun>
28
29#include <boost/algorithm/string.hpp>
30#include <boost/regex.hpp>
31
32using namespace Mantid::Kernel;
33using namespace Mantid::API;
34using namespace MantidQt::API;
36
38// FileFinderWidget
40
42 : MantidWidget(parent), m_findRunFiles(true), m_isForDirectory(false), m_allowMultipleFiles(false),
43 m_isOptional(false), m_multiEntry(false), m_buttonOpt(Text), m_fileProblem(""), m_entryNumProblem(""),
44 m_algorithmProperty(""), m_fileExtensions(), m_extsAsSingleOption(true), m_liveButtonState(Hide),
45 m_showValidator(true), m_foundFiles(), m_lastFoundFiles(), m_lastDir(), m_fileFilter(), m_pool(), m_dialog(),
46 m_useNativeDialog(true) {
47
48 m_uiForm.setupUi(this);
49
50 connect(m_uiForm.fileEditor, SIGNAL(textChanged(const QString &)), this, SIGNAL(fileTextChanged(const QString &)));
51 connect(m_uiForm.fileEditor, SIGNAL(editingFinished()), this, SIGNAL(fileEditingFinished()));
52 connect(m_uiForm.browseBtn, SIGNAL(clicked()), this, SLOT(browseClicked()));
53 connect(m_uiForm.browseIco, SIGNAL(clicked()), this, SLOT(browseClicked()));
54
55 connect(this, SIGNAL(fileEditingFinished()), this, SLOT(findFiles()));
56 connect(m_uiForm.entryNum, SIGNAL(textChanged(const QString &)), this, SLOT(checkEntry()));
57 connect(m_uiForm.entryNum, SIGNAL(editingFinished()), this, SLOT(checkEntry()));
58
59 m_uiForm.fileEditor->clear();
60
61 if (m_multiEntry) {
62 m_uiForm.entryNum->show();
63 m_uiForm.numEntries->show();
64 } else {
65 m_uiForm.entryNum->hide();
66 m_uiForm.numEntries->hide();
67 }
68
70
72 connect(m_uiForm.liveButton, SIGNAL(toggled(bool)), this, SIGNAL(liveButtonPressed(bool)));
73
74 setFocusPolicy(Qt::StrongFocus);
75 setFocusProxy(m_uiForm.fileEditor);
76
77 // First try default save directory
78 m_lastDir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory"));
79
80 // If that fails pick the first data search directory
81 if (m_lastDir.isEmpty()) {
82 QStringList dataDirs =
83 QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("datasearch.directories"))
84 .split(";", Qt::SkipEmptyParts);
85
86 if (!dataDirs.isEmpty())
87 m_lastDir = dataDirs[0];
88 }
89
90 // this for accepts drops, but the underlying text input does not.
91 this->setAcceptDrops(true);
92 m_uiForm.fileEditor->setAcceptDrops(false);
93}
94
100
105void FileFinderWidget::isForRunFiles(const bool mode) { m_findRunFiles = mode; }
106
112
117void FileFinderWidget::isForDirectory(const bool mode) {
118 clear();
119 m_isForDirectory = mode;
120}
121
126QString FileFinderWidget::getLabelText() const { return m_uiForm.textLabel->text(); }
127
132void FileFinderWidget::setLabelText(const QString &text) {
133 m_uiForm.textLabel->setText(text);
134 m_uiForm.textLabel->setVisible(!text.isEmpty());
135}
136
140void FileFinderWidget::setLabelMinWidth(const int width) { m_uiForm.textLabel->setMinimumWidth(width); }
141
148
155 m_allowMultipleFiles = allow;
156 findFiles();
157}
158
163
168void FileFinderWidget::isOptional(const bool optional) {
170 findFiles();
171}
172
178
186 if (buttonOpt == None) {
187 m_uiForm.browseBtn->hide();
188 m_uiForm.browseIco->hide();
189 } else if (buttonOpt == Text) {
190 m_uiForm.browseBtn->show();
191 m_uiForm.browseIco->hide();
192 } else if (buttonOpt == Icon) {
193 m_uiForm.browseBtn->hide();
194 m_uiForm.browseIco->show();
195 }
196}
197
204
209void FileFinderWidget::doMultiEntry(const bool multiEntry) {
211 if (m_multiEntry) {
212 m_uiForm.entryNum->show();
213 m_uiForm.numEntries->show();
214 } else {
215 m_uiForm.entryNum->hide();
216 m_uiForm.numEntries->hide();
217 }
219}
220
226
237const QStringList &FileFinderWidget::getFileExtensions() const { return m_fileExtensions; }
238
239std::vector<std::string> FileFinderWidget::getStringFileExtensions() const {
240 std::vector<std::string> extensions;
241 std::transform(m_fileExtensions.begin(), m_fileExtensions.end(), std::back_inserter(extensions),
242 [](const QString &extension) { return extension.toStdString(); });
243
244 return extensions;
245}
246
252void FileFinderWidget::setFileExtensions(const QStringList &extensions) {
253 m_fileExtensions = extensions;
254 m_fileFilter.clear();
255}
256
263
271
274
276 m_liveButtonState = option;
277 if (m_liveButtonState == Hide) {
278 m_uiForm.liveButton->hide();
279 } else if (m_liveButtonState == Show) {
280 m_uiForm.liveButton->show();
281 }
282}
283
284void FileFinderWidget::liveButtonSetChecked(const bool checked) { m_uiForm.liveButton->setChecked(checked); }
285
286bool FileFinderWidget::liveButtonIsChecked() const { return m_uiForm.liveButton->isChecked(); }
287
292bool FileFinderWidget::isValid() const { return m_uiForm.valid->isHidden(); }
293
299
304const QStringList &FileFinderWidget::getFilenames() const { return m_foundFiles; }
305
314 if (m_foundFiles.isEmpty())
315 return "";
316 else
317 return m_foundFiles[0];
318}
319
323bool FileFinderWidget::isEmpty() const { return m_uiForm.fileEditor->text().isEmpty(); }
324
328QString FileFinderWidget::getText() const { return m_uiForm.fileEditor->text(); }
329
335 if (m_uiForm.entryNum->text().isEmpty() || (!m_multiEntry)) {
336 return ALL_ENTRIES;
337 }
338 if (isValid()) {
339 bool isANumber;
340 const int period = m_uiForm.entryNum->text().toInt(&isANumber);
341 if (isANumber) {
342 return period;
343 }
344 }
345 return NO_ENTRY_NUM;
346}
347
351void FileFinderWidget::setEntryNum(const int num) { m_uiForm.entryNum->setText(QString::number(num)); }
352
360QVariant FileFinderWidget::getUserInput() const { return QVariant(m_valueForProperty); }
361
370void FileFinderWidget::setText(const QString &value) { m_uiForm.fileEditor->setText(value); }
371
383 m_uiForm.fileEditor->setText(value.toString());
384 m_uiForm.fileEditor->setModified(true);
385 emit fileEditingFinished(); // Which is connected to slot findFiles()
386}
387
395void FileFinderWidget::setFileProblem(const QString &message) {
396 m_fileProblem = message;
398}
399
404const QString &FileFinderWidget::getFileProblem() const { return m_fileProblem; }
405
406void FileFinderWidget::saveSettings(QSettings &settings, const FileFinderSettings &values) const {
407 MantidQt::MantidWidgets::QSettingsChangeAware(settings).setValue("last_directory", values.lastDirectory());
408}
409
416 const QString total = number > 0 ? QString::number(number) : "?";
417 {
418 m_uiForm.numEntries->setText("/" + total);
419 }
420}
421
429void FileFinderWidget::setLiveAlgorithm(const IAlgorithm_sptr &monitorLiveData) { m_monitorLiveData = monitorLiveData; }
430
441
453void FileFinderWidget::setInstrumentOverride(const QString &instName) {
454 m_defaultInstrumentName = instName;
455 findFiles(true);
456}
457
469 findFiles();
470}
476 m_uiForm.fileEditor->setText(text);
477 m_uiForm.fileEditor->setModified(true);
478}
479
484 m_foundFiles.clear();
485 m_uiForm.fileEditor->setText("");
486}
487
491void FileFinderWidget::findFiles() { findFiles(m_uiForm.fileEditor->isModified()); }
492
496void FileFinderWidget::findFiles(bool isModified) {
497 auto searchText = m_uiForm.fileEditor->text();
498 if (m_isForDirectory) {
499 m_foundFiles.clear();
500 if (searchText.isEmpty()) {
501 if (!m_isOptional)
502 setFileProblem("A directory must be provided");
503 else
504 setFileProblem("");
505 } else {
506 setFileProblem("");
507 m_foundFiles.append(searchText);
508 }
509 return;
510 }
511
512 if (isModified) {
513 // Reset modified flag.
514 m_uiForm.fileEditor->setModified(false);
515 searchText = findFilesGetSearchText(searchText);
516 runFindFiles(searchText);
517 } else {
518 // Make sure errors are correctly set if we didn't run
520 }
521}
522
528const QString FileFinderWidget::findFilesGetSearchText(QString &searchText) {
529 // If we have an override instrument then add it in appropriate places to
530 // the search text
531 if (!m_defaultInstrumentName.isEmpty()) {
532 // Regex to match a selection of run numbers as defined here:
533 // mantidproject.org/MultiFileLoading
534 // Also allowing spaces between delimiters as this seems to work fine
535 const std::string runNumberString = "([0-9]+)([:+-] ?[0-9]+)? ?(:[0-9]+)?";
536 boost::regex runNumberExp(runNumberString, boost::regex::extended);
537 // Regex to match a list of run numbers delimited by commas
538 const std::string runListString = "(" + runNumberString + ")(, ?(" + runNumberString + "))*";
539 boost::regex runNumberListExp(runListString, boost::regex::extended);
540
541 // See if we can just prepend the instrument and be done
542 if (boost::regex_match(searchText.toStdString(), runNumberExp)) {
543 searchText = m_defaultInstrumentName + searchText;
544 }
545 // If it is a list we need to prepend the instrument to all run numbers
546 else if (boost::regex_match(searchText.toStdString(), runNumberListExp)) {
547 QStringList runNumbers = searchText.split(",", Qt::SkipEmptyParts);
548 QStringList newRunNumbers;
549
550 for (const auto &runNumber : runNumbers)
551 newRunNumbers << m_defaultInstrumentName + runNumber.simplified();
552
553 searchText = newRunNumbers.join(",");
554 }
555 }
556 return searchText;
557}
558
563void FileFinderWidget::runFindFiles(const QString &searchText) {
564 emit findingFiles();
565
566 const auto parameters = createFindFilesSearchParameters(searchText.toStdString());
567 m_pool.createWorker(this, parameters);
568}
569
577 IAlgorithm_const_sptr theAlgorithmBeingCancelled = m_monitorLiveData;
578 if (m_monitorLiveData && m_monitorLiveData->isRunning()) {
579 m_monitorLiveData->cancel();
580 m_monitorLiveData.reset();
581 }
582 return theAlgorithmBeingCancelled;
583}
584
590 // Update caches before we might exit early
591 m_cachedResults = results;
592 m_valueForProperty = QString::fromStdString(results.valueForProperty);
593 m_foundFiles.clear();
594 m_lastFoundFiles.clear();
595
596 // Early exit on failure
597 if (!results.error.empty()) {
598 setFileProblem(QString::fromStdString(results.error));
600 return;
601 }
602
603 for (const auto &filename : results.filenames) {
604 m_foundFiles.append(QString::fromStdString(filename));
605 }
606 if (m_foundFiles.isEmpty() && !isOptional()) {
607 setFileProblem("No files found. Check search paths and instrument selection.");
608 } else if (m_foundFiles.count() > 1 && this->allowMultipleFiles() == false) {
609 setFileProblem("Multiple files specified.");
610 } else {
611 setFileProblem("");
612 }
613
615
616 // Only emit the signal if file(s) were found
617 if (!m_foundFiles.isEmpty())
618 emit filesFound();
620 emit filesFoundChanged();
621}
622
624 auto lastDirectory = settings.value("last_directory", "").toString();
625
626 if (lastDirectory.isEmpty()) {
627 QStringList datadirs =
628 QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("datasearch.directories"))
629 .split(";", Qt::SkipEmptyParts);
630 if (!datadirs.isEmpty())
631 lastDirectory = datadirs[0];
632 }
633
634 return FileFinderSettings(lastDirectory);
635}
636
638
640
646 QStringList fileExts;
647 if (m_algorithmProperty.isEmpty()) {
648 if (!m_fileExtensions.isEmpty()) {
649 fileExts = m_fileExtensions;
650 } else if (isForRunFiles()) {
651 std::vector<std::string> exts = ConfigService::Instance().getFacility().extensions();
652 for (const auto &ext : exts) {
653 fileExts.append(QString::fromStdString(ext));
654 }
655 } else {
656 }
657 } else {
658 QStringList elements = m_algorithmProperty.split("|");
659 if (elements.size() == 2) {
660 fileExts = getFileExtensionsFromAlgorithm(elements[0], elements[1]);
661 }
662 }
663
664 QString allFiles("All Files (*)");
665 if (!fileExts.isEmpty()) {
666
667 // The list may contain upper and lower cased versions, ensure these are on
668 // the same line
669 // I want this ordered
671 QStringListIterator sitr(fileExts);
672 QString ext = sitr.next();
673 finalIndex.append(std::make_pair(ext.toUpper(), QStringList(ext)));
674 while (sitr.hasNext()) {
675 ext = sitr.next();
676 QString key = ext.toUpper();
677 const auto it = std::find_if(finalIndex.begin(), finalIndex.end(),
678 [&key](const std::pair<QString, QStringList> &pair) { return pair.first == key; });
679 if (it != finalIndex.end()) {
680 it->second.append(ext);
681 } else {
682 finalIndex.append(std::make_pair(key, QStringList(ext)));
683 }
684 }
685
686 // The file filter consists of three parts, which we will combine to create
687 // the
688 // complete file filter:
689 QString dataFiles("Data Files (");
690 QString individualFiles("");
691
692 if (extsAsSingleOption()) {
693 QListIterator<std::pair<QString, QStringList>> itr(finalIndex);
694 while (itr.hasNext()) {
695 const QStringList values = itr.next().second;
696
697 individualFiles += "*" + values.join(" *") + ";;";
698 dataFiles += "*" + values.join(" *") + " ";
699 }
700 // Don't remove final ;; from individualFiles as we are going to tack on
701 // allFiles anyway
702 dataFiles.chop(1); // Remove last space
703 dataFiles += ");;";
704 } else {
705 QListIterator<std::pair<QString, QStringList>> itr(finalIndex);
706 while (itr.hasNext()) {
707 const QStringList values = itr.next().second;
708 dataFiles += "*" + values.join(" *") + ";;";
709 }
710 }
711 return dataFiles + individualFiles + allFiles;
712 } else {
713 return allFiles;
714 }
715}
716
723QStringList FileFinderWidget::getFileExtensionsFromAlgorithm(const QString &algName, const QString &propName) {
725 Mantid::API::AlgorithmManager::Instance().createUnmanaged(algName.toStdString());
726 QStringList fileExts;
727 if (!algorithm)
728 return fileExts;
729 algorithm->initialize();
730 Property *prop = algorithm->getProperty(propName.toStdString());
731 FileProperty *fileProp = dynamic_cast<FileProperty *>(prop);
732 auto *multiFileProp = dynamic_cast<MultipleFileProperty *>(prop);
733
734 std::vector<std::string> allowed;
735 QString preferredExt;
736
737 if (fileProp) {
738 allowed = fileProp->allowedValues();
739 preferredExt = QString::fromStdString(fileProp->getDefaultExt());
740 } else if (multiFileProp) {
741 allowed = multiFileProp->allowedValues();
742 preferredExt = QString::fromStdString(multiFileProp->getDefaultExt());
743 } else {
744 return fileExts;
745 }
746
747 std::vector<std::string>::const_iterator iend = allowed.end();
748 int index(0);
749 for (std::vector<std::string>::const_iterator it = allowed.begin(); it != iend; ++it) {
750 if (!it->empty()) {
751 QString ext = QString::fromStdString(*it);
752 fileExts.append(ext);
753 if (ext == preferredExt) {
754 fileExts.move(index, 0);
755 }
756 ++index;
757 }
758 }
759
760 return fileExts;
761}
762
768 QStringList filenames;
769 QString dir;
770
771 auto prevFileNames = getText().split(",", Qt::SkipEmptyParts);
772 for (auto &prevFileName : prevFileNames)
773 prevFileName = prevFileName.trimmed();
774
775 if (!prevFileNames.empty() && QFileInfo(prevFileNames[0]).isAbsolute()) {
776 if (QFileInfo(prevFileNames[0]).isFile()) {
777 dir = QFileInfo(prevFileNames[0]).absoluteDir().path();
778 } else {
779 dir = prevFileNames[0];
780 }
781 } else {
782 dir = m_lastDir;
783 }
784
785 if (m_fileFilter.isEmpty()) {
787 }
788
789 if (!m_useNativeDialog) {
790 if (m_isForDirectory) {
791 m_dialog.setOption(QFileDialog::DontResolveSymlinks, false);
792 m_dialog.setFileMode(QFileDialog::Directory);
793 } else {
794 m_dialog.setNameFilter(m_fileFilter);
795 m_dialog.setOption(QFileDialog::DontResolveSymlinks);
797 m_dialog.setFileMode(QFileDialog::ExistingFiles);
798 else
799 m_dialog.setFileMode(QFileDialog::ExistingFile);
800 }
801 m_dialog.setDirectory(dir);
802 if (m_dialog.exec())
803 filenames = m_dialog.selectedFiles();
804 } else {
805 if (m_isForDirectory) {
806 QString file = QFileDialog::getExistingDirectory(this, "Select directory", dir);
807 if (!file.isEmpty())
808 filenames.append(file);
809 } else if (m_allowMultipleFiles) {
810 filenames = QFileDialog::getOpenFileNames(this, "Open file", dir, m_fileFilter, nullptr,
811 QFileDialog::DontResolveSymlinks);
812 } else {
813 QString file =
814 QFileDialog::getOpenFileName(this, "Open file", dir, m_fileFilter, nullptr, QFileDialog::DontResolveSymlinks);
815 if (!file.isEmpty())
816 filenames.append(file);
817 }
818 }
819
820 if (filenames.isEmpty()) {
821 return "";
822 }
823 m_lastDir = QFileInfo(filenames.front()).absoluteDir().path();
824 return filenames.join(", ");
825}
826
832void FileFinderWidget::setEntryNumProblem(const QString &message) {
833 m_entryNumProblem = message;
835}
836
842 if (m_showValidator) {
843 if (!m_fileProblem.isEmpty()) {
844 m_uiForm.valid->setToolTip(m_fileProblem);
845 m_uiForm.valid->show();
846 } else if (!m_entryNumProblem.isEmpty() && m_multiEntry) {
847 m_uiForm.valid->setToolTip(m_entryNumProblem);
848 m_uiForm.valid->show();
849 } else {
850 m_uiForm.valid->hide();
851 }
852 } else {
853 m_uiForm.valid->hide();
854 }
855}
856
860 QString uFile = openFileDialog();
861 if (uFile.trimmed().isEmpty())
862 return;
863
864 m_uiForm.fileEditor->setText(uFile);
865 m_uiForm.fileEditor->setModified(true);
866
867 emit fileEditingFinished();
868}
869
874 if (m_uiForm.entryNum->text().isEmpty()) {
876 return;
877 }
878
879 bool good;
880 const int num = m_uiForm.entryNum->text().toInt(&good);
881 if (!good) {
882 setEntryNumProblem("The entry number must be an integer");
883 return;
884 }
885 if (num < 1) {
886 setEntryNumProblem("The entry number must be an integer > 0");
887 return;
888 }
889
891}
892
897void FileFinderWidget::dropEvent(QDropEvent *de) {
898 const QMimeData *mimeData = de->mimeData();
899 const auto filenames = DropEventHelper::getFileNames(de);
900 if (!filenames.empty()) {
901 m_uiForm.fileEditor->setText(filenames[0]);
902 de->acceptProposedAction();
903 } else if (mimeData->hasText()) {
904 QString text = mimeData->text();
905 m_uiForm.fileEditor->setText(text);
906 de->acceptProposedAction();
907 }
908}
909
914void FileFinderWidget::dragEnterEvent(QDragEnterEvent *de) {
915 const QMimeData *mimeData = de->mimeData();
916 if (mimeData->hasUrls()) {
917 auto listurl = mimeData->urls();
918 if (listurl.empty())
919 return;
920 if (!listurl[0].isLocalFile())
921 return;
922 de->acceptProposedAction();
923 } else if (mimeData->hasText()) {
924 QString text = mimeData->text();
925 if (text.contains(" = mtd[\""))
926 de->setDropAction(Qt::IgnoreAction);
927 else
928 de->acceptProposedAction();
929 }
930}
931
938void FileFinderWidget::setReadOnly(bool readOnly) {
939 m_uiForm.fileEditor->setReadOnly(readOnly);
940 m_uiForm.browseBtn->setEnabled(!readOnly);
941 setValidatorDisplay(!readOnly);
943}
944
952
954 FindFilesSearchParameters parameters;
955 parameters.searchText = text;
956 parameters.isOptional = isOptional();
957 parameters.isForRunFiles = isForRunFiles();
958 parameters.extensions = getStringFileExtensions();
959
960 // parse the algorithm - property name string
961 QStringList elements = m_algorithmProperty.split("|");
962 if (elements.size() == 2) {
963 parameters.algorithmName = elements[0].toStdString();
964 parameters.algorithmProperty = elements[1].toStdString();
965 }
966
967 return parameters;
968}
969
970void FileFinderWidget::setTextValidator(const QValidator *validator) { m_uiForm.fileEditor->setValidator(validator); }
971
973 m_useNativeDialog = native;
974 m_dialog.setOption(QFileDialog::DontUseNativeDialog);
975 m_dialog.setOption(QFileDialog::ReadOnly);
976}
977
978void FileFinderWidget::setProxyModel(QAbstractProxyModel *proxyModel) { m_dialog.setProxyModel(proxyModel); }
double value
The value of the point.
Definition FitMW.cpp:51
std::map< DeltaEMode::Type, std::string > index
Immutable snapshot of the persistent state used by FileFinderWidget.
const QString & lastDirectory() const
void inspectThreadResult(const FindFilesSearchResults &results=FindFilesSearchResults())
Slot called when file finding thread has finished.
QString m_fileProblem
Holds any error with the user entry for the filename, "" means no error.
void fileEditingFinished()
Emitted when the editing has finished.
QStringList m_lastFoundFiles
An array of the last valid file names found.
bool m_findRunFiles
Is the widget for run files or standard files.
void fileInspectionFinished()
Emitted when inspection of any found files is completed.
void refreshValidator()
displays the validator red star if either m_fileProblem or m_entryNumProblem are not empty
void setNumberOfEntries(int number)
Alters the text label that contains the number of entries, normally run when the file is loaded.
QFileDialog m_dialog
non-native QFileDialog
QString getLabelText() const
Return the label text on the widget.
QString openFileDialog()
Open a file dialog.
bool m_extsAsSingleOption
If true the exts are displayed as one option in the dialog.
bool allowMultipleFiles() const
Return whether this widget allows multiple files to be specified within the edit box.
void restoreSettings(const FileFinderSettings &settings)
Restore this widget from an in-memory snapshot without persistent I/O.
FindFilesThreadPoolManager m_pool
Handle to a find files thread pool manager.
void dragEnterEvent(QDragEnterEvent *) override
Called when an item is dragged onto a control.
QVariant getUserInput() const override
Overridden from base class to retrieve user input through a common interface.
void setTextValidator(const QValidator *validator)
Set an arbitrary validator on the line edit.
int getEntryNum() const
The number the user entered into the entryNum lineEdit or NO_ENTRY_NUM on error.
bool isEmpty() const
Check if any text, valid or not, has been entered into the line edit.
const QStringList & getFilenames() const
Returns the names of the files found.
std::shared_ptr< Mantid::API::IAlgorithm > m_monitorLiveData
Handle on a running instance of MonitorLiveData.
FindFilesSearchResults m_cachedResults
Handle to any results found.
void setAlgorithmProperty(const QString &name)
Sets an algorithm name that can be tied to this widget.
ButtonOpts doButtonOpt() const
Returns the preference for how the dialog control should be.
bool doMultiEntry() const
Whether to find the number of entries in the file or assume (the normal situation) of one entry.
void filesFoundChanged()
Emitted when files have been found that are different to what was found last time.
std::shared_ptr< const Mantid::API::IAlgorithm > stopLiveAlgorithm()
Calls cancel on a running instance of MonitorLiveData.
void setFileTextWithSearch(const QString &text)
Set the file text and try and find it.
FileFinderSettings captureSettings() const
Capture the current state of this widget without persistent I/O.
void setLabelText(const QString &text)
Set the text on the label.
QString m_valueForProperty
Expanded user input.
QString m_entryNumProblem
If applicable holds any error with the user in entryNum, "" means no error.
ButtonOpts
options for bringing up the load file dialog
@ None
disable the load file dialog
@ Text
use a button (normally labelled "Browse")
void fileTextChanged(const QString &)
Emitted when the file text changes.
QStringList getFileExtensionsFromAlgorithm(const QString &algName, const QString &propName)
Create an extension list from the name algorithm and property.
LiveButtonOpts liveButtonState() const
Returns whether the live button is being shown;.
QStringList m_foundFiles
An array of valid file names derived from the entries in the leNumber LineEdit.
bool m_isOptional
Whether the widget can be empty.
bool m_isForDirectory
If the widget is for directories.
void findFiles()
Find the files if the text edit field is modified.
void setText(const QString &value)
Sets a value on the widget but doesn't emit a signal to say it has changed.
QString createFileFilter()
Create a file filter from a list of extensions.
bool m_allowMultipleFiles
Allow multiple files.
@ ALL_ENTRIES
use all entries (i.e. entry number was left blank)
@ NO_ENTRY_NUM
error in the entry number setting
void saveSettings(QSettings &settings, const FileFinderSettings &values) const
Persist the supplied snapshot to mutable storage positioned at the target group.
std::vector< std::string > getStringFileExtensions() const
FindFilesSearchParameters createFindFilesSearchParameters(const std::string &text) const
Helper method to create a FindFilesSearchParameters object.
QString m_algorithmProperty
The algorithm name and property (can be empty)
void setUserInput(const QVariant &value) override
Sets a value on the widget through a common interface.
void setLiveAlgorithm(const std::shared_ptr< Mantid::API::IAlgorithm > &monitorLiveData)
Inform the widget of a running instance of MonitorLiveData to be used in stopLiveListener()
void findingFiles()
Emitted when files finding starts.
Ui::FileFinderWidget m_uiForm
The Ui form.
QString getText() const
The verbatum, unexpanded text, that was entered into the box.
const QStringList & getFileExtensions() const
Returns the list of file extensions the widget will search for.
bool m_showValidator
Whether validation red star is being shown.
bool isOptional() const
Return whether empty input is allowed.
void clear()
Clear the search from the widget.
bool isForDirectory() const
Returns if this widget is for selecting a directory or not.
void setEntryNumProblem(const QString &message)
flag a problem with the supplied entry number, an empty string means no error
void browseClicked()
Browse clicked slot.
void liveButtonPressed(bool)
Emitted when the live button is toggled.
void filesFound()
Emitted when files have been found.
void setProxyModel(QAbstractProxyModel *proxyModel)
bool isForRunFiles() const
Returns if this widget is for run file searching or not.
LiveButtonOpts
Options for the live button.
@ Hide
Don't use the live button.
@ Show
Display the live button.
void setReadOnly(bool readOnly)
Set the input read-only or not.
const QString & getAlgorithmProperty() const
Returns the algorithm name.
ButtonOpts m_buttonOpt
To use a browse button or icon or nothing at all.
bool m_multiEntry
Whether to allow the user to state an entry number.
static FileFinderSettings readSettings(const QSettings &settings)
Query last_directory from const storage without changing this widget or writing settings.
void setFileExtensions(const QStringList &extensions)
Sets the list of file extensions the dialog will search for.
void setFileTextWithoutSearch(const QString &text)
Just update the file text, useful for syncing two boxes.
bool isValid() const
Is the input within the widget valid?
QString m_fileFilter
A file filter for the file browser.
LiveButtonOpts m_liveButtonState
If or when live button will be shown.
void setValidatorDisplay(bool display)
Turn on/off display of validator red star (default is on)
QStringList m_fileExtensions
The file extensions to look for.
QString m_defaultInstrumentName
Cache the default instrument name.
void setLabelMinWidth(int)
Set the minimum width on the label widget.
void setFileProblem(const QString &message)
flag a problem with the file the user entered, an empty string means no error
bool isSearching() const
Is the widget currently searching.
void dropEvent(QDropEvent *) override
Called when an item is dropped.
bool m_useNativeDialog
flag to control use of m_dialog
FileFinderWidget(QWidget *parent=nullptr)
Default constructor.
const QString & getFileProblem() const
Get file problem, empty string means no error.
void checkEntry()
currently checks only if the entry number is any integer > 0
void runFindFiles(const QString &searchText)
handles findFiles background thread
QString getFirstFilename() const
Safer than using getRunFiles()[0] in the situation were there are no files.
const QString & getInstrumentOverride() const
Gets the instrument currently fixed to.
void setEntryNum(const int num)
Set the entry displayed in the box to this value.
void setInstrumentOverride(const QString &instName)
Overrides the value of default instrument.
QString m_lastDir
The last directory viewed by the browse dialog.
const QString findFilesGetSearchText(QString &searchText)
gets text to use for find files search parameters
void createWorker(const QObject *parent, const FindFilesSearchParameters &parameters)
Create a new worker thread. This will cancel any currently running threads.
bool isSearchRunning() const
Check if a search is already in progress.
This is the base class all customised widgets that do not wish to be tied to a specific Mantid algori...
A QSettings facade that applies only effective changes.
bool setValue(QString const &key, QVariant const &value)
Set a value only when the effective stored value differs.
A specialized class for dealing with file properties.
const std::string & getDefaultExt() const
Returns the main file extension that's used.
A property to allow a user to specify multiple files to load.
std::vector< std::string > allowedValues() const override
Returns the set of valid values for this property, if such a set exists.
Base class for properties.
Definition Property.h:94
EXPORT_OPT_MANTIDQT_COMMON QStringList getFileNames(const QDropEvent *event)
Get all filenames from a QDropEvent.
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< const IAlgorithm > IAlgorithm_const_sptr
shared pointer to Mantid::API::IAlgorithm (const version)
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.