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 +
9
17
18#include <Poco/File.h>
19#include <QDragEnterEvent>
20#include <QDropEvent>
21#include <QFileInfo>
22#include <QHash>
23#include <QMimeData>
24#include <QStringList>
25#include <QUrl>
26#include <QtConcurrentRun>
27
28#include <boost/algorithm/string.hpp>
29#include <boost/regex.hpp>
30
31using namespace Mantid::Kernel;
32using namespace Mantid::API;
33using namespace MantidQt::API;
35
37// FileFinderWidget
39
41 : MantidWidget(parent), m_findRunFiles(true), m_isForDirectory(false), m_allowMultipleFiles(false),
42 m_isOptional(false), m_multiEntry(false), m_buttonOpt(Text), m_fileProblem(""), m_entryNumProblem(""),
43 m_algorithmProperty(""), m_fileExtensions(), m_extsAsSingleOption(true), m_liveButtonState(Hide),
44 m_showValidator(true), m_foundFiles(), m_lastFoundFiles(), m_lastDir(), m_fileFilter(), m_pool(), m_dialog(),
45 m_useNativeDialog(true) {
46
47 m_uiForm.setupUi(this);
48
49 connect(m_uiForm.fileEditor, SIGNAL(textChanged(const QString &)), this, SIGNAL(fileTextChanged(const QString &)));
50 connect(m_uiForm.fileEditor, SIGNAL(editingFinished()), this, SIGNAL(fileEditingFinished()));
51 connect(m_uiForm.browseBtn, SIGNAL(clicked()), this, SLOT(browseClicked()));
52 connect(m_uiForm.browseIco, SIGNAL(clicked()), this, SLOT(browseClicked()));
53
54 connect(this, SIGNAL(fileEditingFinished()), this, SLOT(findFiles()));
55 connect(m_uiForm.entryNum, SIGNAL(textChanged(const QString &)), this, SLOT(checkEntry()));
56 connect(m_uiForm.entryNum, SIGNAL(editingFinished()), this, SLOT(checkEntry()));
57
58 m_uiForm.fileEditor->clear();
59
60 if (m_multiEntry) {
61 m_uiForm.entryNum->show();
62 m_uiForm.numEntries->show();
63 } else {
64 m_uiForm.entryNum->hide();
65 m_uiForm.numEntries->hide();
66 }
67
69
71 connect(m_uiForm.liveButton, SIGNAL(toggled(bool)), this, SIGNAL(liveButtonPressed(bool)));
72
73 setFocusPolicy(Qt::StrongFocus);
74 setFocusProxy(m_uiForm.fileEditor);
75
76 // First try default save directory
77 m_lastDir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory"));
78
79 // If that fails pick the first data search directory
80 if (m_lastDir.isEmpty()) {
81 QStringList dataDirs =
82 QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("datasearch.directories"))
83 .split(";", Qt::SkipEmptyParts);
84
85 if (!dataDirs.isEmpty())
86 m_lastDir = dataDirs[0];
87 }
88
89 // this for accepts drops, but the underlying text input does not.
90 this->setAcceptDrops(true);
91 m_uiForm.fileEditor->setAcceptDrops(false);
92}
93
99
104void FileFinderWidget::isForRunFiles(const bool mode) { m_findRunFiles = mode; }
105
111
116void FileFinderWidget::isForDirectory(const bool mode) {
117 clear();
118 m_isForDirectory = mode;
119}
120
125QString FileFinderWidget::getLabelText() const { return m_uiForm.textLabel->text(); }
126
131void FileFinderWidget::setLabelText(const QString &text) {
132 m_uiForm.textLabel->setText(text);
133 m_uiForm.textLabel->setVisible(!text.isEmpty());
134}
135
139void FileFinderWidget::setLabelMinWidth(const int width) { m_uiForm.textLabel->setMinimumWidth(width); }
140
147
154 m_allowMultipleFiles = allow;
155 findFiles();
156}
157
162
167void FileFinderWidget::isOptional(const bool optional) {
169 findFiles();
170}
171
177
185 if (buttonOpt == None) {
186 m_uiForm.browseBtn->hide();
187 m_uiForm.browseIco->hide();
188 } else if (buttonOpt == Text) {
189 m_uiForm.browseBtn->show();
190 m_uiForm.browseIco->hide();
191 } else if (buttonOpt == Icon) {
192 m_uiForm.browseBtn->hide();
193 m_uiForm.browseIco->show();
194 }
195}
196
203
208void FileFinderWidget::doMultiEntry(const bool multiEntry) {
210 if (m_multiEntry) {
211 m_uiForm.entryNum->show();
212 m_uiForm.numEntries->show();
213 } else {
214 m_uiForm.entryNum->hide();
215 m_uiForm.numEntries->hide();
216 }
218}
219
225
236const QStringList &FileFinderWidget::getFileExtensions() const { return m_fileExtensions; }
237
238std::vector<std::string> FileFinderWidget::getStringFileExtensions() const {
239 std::vector<std::string> extensions;
240 std::transform(m_fileExtensions.begin(), m_fileExtensions.end(), std::back_inserter(extensions),
241 [](const QString &extension) { return extension.toStdString(); });
242
243 return extensions;
244}
245
251void FileFinderWidget::setFileExtensions(const QStringList &extensions) {
252 m_fileExtensions = extensions;
253 m_fileFilter.clear();
254}
255
262
270
273
275 m_liveButtonState = option;
276 if (m_liveButtonState == Hide) {
277 m_uiForm.liveButton->hide();
278 } else if (m_liveButtonState == Show) {
279 m_uiForm.liveButton->show();
280 }
281}
282
283void FileFinderWidget::liveButtonSetChecked(const bool checked) { m_uiForm.liveButton->setChecked(checked); }
284
285bool FileFinderWidget::liveButtonIsChecked() const { return m_uiForm.liveButton->isChecked(); }
286
291bool FileFinderWidget::isValid() const { return m_uiForm.valid->isHidden(); }
292
298
303const QStringList &FileFinderWidget::getFilenames() const { return m_foundFiles; }
304
313 if (m_foundFiles.isEmpty())
314 return "";
315 else
316 return m_foundFiles[0];
317}
318
322bool FileFinderWidget::isEmpty() const { return m_uiForm.fileEditor->text().isEmpty(); }
323
327QString FileFinderWidget::getText() const { return m_uiForm.fileEditor->text(); }
328
334 if (m_uiForm.entryNum->text().isEmpty() || (!m_multiEntry)) {
335 return ALL_ENTRIES;
336 }
337 if (isValid()) {
338 bool isANumber;
339 const int period = m_uiForm.entryNum->text().toInt(&isANumber);
340 if (isANumber) {
341 return period;
342 }
343 }
344 return NO_ENTRY_NUM;
345}
346
350void FileFinderWidget::setEntryNum(const int num) { m_uiForm.entryNum->setText(QString::number(num)); }
351
359QVariant FileFinderWidget::getUserInput() const { return QVariant(m_valueForProperty); }
360
369void FileFinderWidget::setText(const QString &value) { m_uiForm.fileEditor->setText(value); }
370
382 m_uiForm.fileEditor->setText(value.toString());
383 m_uiForm.fileEditor->setModified(true);
384 emit fileEditingFinished(); // Which is connected to slot findFiles()
385}
386
394void FileFinderWidget::setFileProblem(const QString &message) {
395 m_fileProblem = message;
397}
398
403const QString &FileFinderWidget::getFileProblem() const { return m_fileProblem; }
404
410 QSettings settings;
411 settings.beginGroup(group);
412
413 settings.setValue("last_directory", m_lastDir);
414
415 settings.endGroup();
416}
417
424 const QString total = number > 0 ? QString::number(number) : "?";
425 {
426 m_uiForm.numEntries->setText("/" + total);
427 }
428}
429
437void FileFinderWidget::setLiveAlgorithm(const IAlgorithm_sptr &monitorLiveData) { m_monitorLiveData = monitorLiveData; }
438
449
461void FileFinderWidget::setInstrumentOverride(const QString &instName) {
462 m_defaultInstrumentName = instName;
463 findFiles(true);
464}
465
477 findFiles();
478}
484 m_uiForm.fileEditor->setText(text);
485 m_uiForm.fileEditor->setModified(true);
486}
487
492 m_foundFiles.clear();
493 m_uiForm.fileEditor->setText("");
494}
495
499void FileFinderWidget::findFiles() { findFiles(m_uiForm.fileEditor->isModified()); }
500
504void FileFinderWidget::findFiles(bool isModified) {
505 auto searchText = m_uiForm.fileEditor->text();
506 if (m_isForDirectory) {
507 m_foundFiles.clear();
508 if (searchText.isEmpty()) {
509 if (!m_isOptional)
510 setFileProblem("A directory must be provided");
511 else
512 setFileProblem("");
513 } else {
514 setFileProblem("");
515 m_foundFiles.append(searchText);
516 }
517 return;
518 }
519
520 if (isModified) {
521 // Reset modified flag.
522 m_uiForm.fileEditor->setModified(false);
523 searchText = findFilesGetSearchText(searchText);
524 runFindFiles(searchText);
525 } else {
526 // Make sure errors are correctly set if we didn't run
528 }
529}
530
536const QString FileFinderWidget::findFilesGetSearchText(QString &searchText) {
537 // If we have an override instrument then add it in appropriate places to
538 // the search text
539 if (!m_defaultInstrumentName.isEmpty()) {
540 // Regex to match a selection of run numbers as defined here:
541 // mantidproject.org/MultiFileLoading
542 // Also allowing spaces between delimiters as this seems to work fine
543 const std::string runNumberString = "([0-9]+)([:+-] ?[0-9]+)? ?(:[0-9]+)?";
544 boost::regex runNumberExp(runNumberString, boost::regex::extended);
545 // Regex to match a list of run numbers delimited by commas
546 const std::string runListString = "(" + runNumberString + ")(, ?(" + runNumberString + "))*";
547 boost::regex runNumberListExp(runListString, boost::regex::extended);
548
549 // See if we can just prepend the instrument and be done
550 if (boost::regex_match(searchText.toStdString(), runNumberExp)) {
551 searchText = m_defaultInstrumentName + searchText;
552 }
553 // If it is a list we need to prepend the instrument to all run numbers
554 else if (boost::regex_match(searchText.toStdString(), runNumberListExp)) {
555 QStringList runNumbers = searchText.split(",", Qt::SkipEmptyParts);
556 QStringList newRunNumbers;
557
558 for (const auto &runNumber : runNumbers)
559 newRunNumbers << m_defaultInstrumentName + runNumber.simplified();
560
561 searchText = newRunNumbers.join(",");
562 }
563 }
564 return searchText;
565}
566
571void FileFinderWidget::runFindFiles(const QString &searchText) {
572 emit findingFiles();
573
574 const auto parameters = createFindFilesSearchParameters(searchText.toStdString());
575 m_pool.createWorker(this, parameters);
576}
577
585 IAlgorithm_const_sptr theAlgorithmBeingCancelled = m_monitorLiveData;
586 if (m_monitorLiveData && m_monitorLiveData->isRunning()) {
587 m_monitorLiveData->cancel();
588 m_monitorLiveData.reset();
589 }
590 return theAlgorithmBeingCancelled;
591}
592
598 // Update caches before we might exit early
599 m_cachedResults = results;
600 m_valueForProperty = QString::fromStdString(results.valueForProperty);
601 m_foundFiles.clear();
602 m_lastFoundFiles.clear();
603
604 // Early exit on failure
605 if (!results.error.empty()) {
606 setFileProblem(QString::fromStdString(results.error));
608 return;
609 }
610
611 for (const auto &filename : results.filenames) {
612 m_foundFiles.append(QString::fromStdString(filename));
613 }
614 if (m_foundFiles.isEmpty() && !isOptional()) {
615 setFileProblem("No files found. Check search paths and instrument selection.");
616 } else if (m_foundFiles.count() > 1 && this->allowMultipleFiles() == false) {
617 setFileProblem("Multiple files specified.");
618 } else {
619 setFileProblem("");
620 }
621
623
624 // Only emit the signal if file(s) were found
625 if (!m_foundFiles.isEmpty())
626 emit filesFound();
628 emit filesFoundChanged();
629}
630
636 QSettings settings;
637 settings.beginGroup(group);
638 m_lastDir = settings.value("last_directory", "").toString();
639
640 if (m_lastDir == "") {
641 QStringList datadirs =
642 QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("datasearch.directories"))
643 .split(";", Qt::SkipEmptyParts);
644 if (!datadirs.isEmpty())
645 m_lastDir = datadirs[0];
646 }
647
648 settings.endGroup();
649}
650
656 QStringList fileExts;
657 if (m_algorithmProperty.isEmpty()) {
658 if (!m_fileExtensions.isEmpty()) {
659 fileExts = m_fileExtensions;
660 } else if (isForRunFiles()) {
661 std::vector<std::string> exts = ConfigService::Instance().getFacility().extensions();
662 for (const auto &ext : exts) {
663 fileExts.append(QString::fromStdString(ext));
664 }
665 } else {
666 }
667 } else {
668 QStringList elements = m_algorithmProperty.split("|");
669 if (elements.size() == 2) {
670 fileExts = getFileExtensionsFromAlgorithm(elements[0], elements[1]);
671 }
672 }
673
674 QString allFiles("All Files (*)");
675 if (!fileExts.isEmpty()) {
676
677 // The list may contain upper and lower cased versions, ensure these are on
678 // the same line
679 // I want this ordered
681 QStringListIterator sitr(fileExts);
682 QString ext = sitr.next();
683 finalIndex.append(qMakePair(ext.toUpper(), QStringList(ext)));
684 while (sitr.hasNext()) {
685 ext = sitr.next();
686 QString key = ext.toUpper();
687 const auto it = std::find_if(finalIndex.begin(), finalIndex.end(),
688 [&key](const QPair<QString, QStringList> &pair) { return pair.first == key; });
689 if (it != finalIndex.end()) {
690 it->second.append(ext);
691 } else {
692 finalIndex.append(qMakePair(key, QStringList(ext)));
693 }
694 }
695
696 // The file filter consists of three parts, which we will combine to create
697 // the
698 // complete file filter:
699 QString dataFiles("Data Files (");
700 QString individualFiles("");
701
702 if (extsAsSingleOption()) {
703 QListIterator<QPair<QString, QStringList>> itr(finalIndex);
704 while (itr.hasNext()) {
705 const QStringList values = itr.next().second;
706
707 individualFiles += "*" + values.join(" *") + ";;";
708 dataFiles += "*" + values.join(" *") + " ";
709 }
710 // Don't remove final ;; from individualFiles as we are going to tack on
711 // allFiles anyway
712 dataFiles.chop(1); // Remove last space
713 dataFiles += ");;";
714 } else {
715 QListIterator<QPair<QString, QStringList>> itr(finalIndex);
716 while (itr.hasNext()) {
717 const QStringList values = itr.next().second;
718 dataFiles += "*" + values.join(" *") + ";;";
719 }
720 }
721 return dataFiles + individualFiles + allFiles;
722 } else {
723 return allFiles;
724 }
725}
726
733QStringList FileFinderWidget::getFileExtensionsFromAlgorithm(const QString &algName, const QString &propName) {
735 Mantid::API::AlgorithmManager::Instance().createUnmanaged(algName.toStdString());
736 QStringList fileExts;
737 if (!algorithm)
738 return fileExts;
739 algorithm->initialize();
740 Property *prop = algorithm->getProperty(propName.toStdString());
741 FileProperty *fileProp = dynamic_cast<FileProperty *>(prop);
742 auto *multiFileProp = dynamic_cast<MultipleFileProperty *>(prop);
743
744 std::vector<std::string> allowed;
745 QString preferredExt;
746
747 if (fileProp) {
748 allowed = fileProp->allowedValues();
749 preferredExt = QString::fromStdString(fileProp->getDefaultExt());
750 } else if (multiFileProp) {
751 allowed = multiFileProp->allowedValues();
752 preferredExt = QString::fromStdString(multiFileProp->getDefaultExt());
753 } else {
754 return fileExts;
755 }
756
757 std::vector<std::string>::const_iterator iend = allowed.end();
758 int index(0);
759 for (std::vector<std::string>::const_iterator it = allowed.begin(); it != iend; ++it) {
760 if (!it->empty()) {
761 QString ext = QString::fromStdString(*it);
762 fileExts.append(ext);
763 if (ext == preferredExt) {
764 fileExts.move(index, 0);
765 }
766 ++index;
767 }
768 }
769
770 return fileExts;
771}
772
778 QStringList filenames;
779 QString dir;
780
781 auto prevFileNames = getText().split(",", Qt::SkipEmptyParts);
782 for (auto &prevFileName : prevFileNames)
783 prevFileName = prevFileName.trimmed();
784
785 if (!prevFileNames.empty() && QFileInfo(prevFileNames[0]).isAbsolute()) {
786 if (QFileInfo(prevFileNames[0]).isFile()) {
787 dir = QFileInfo(prevFileNames[0]).absoluteDir().path();
788 } else {
789 dir = prevFileNames[0];
790 }
791 } else {
792 dir = m_lastDir;
793 }
794
795 if (m_fileFilter.isEmpty()) {
797 }
798
799 if (!m_useNativeDialog) {
800 if (m_isForDirectory) {
801 m_dialog.setOption(QFileDialog::DontResolveSymlinks, false);
802 m_dialog.setFileMode(QFileDialog::Directory);
803 } else {
804 m_dialog.setNameFilter(m_fileFilter);
805 m_dialog.setOption(QFileDialog::DontResolveSymlinks);
807 m_dialog.setFileMode(QFileDialog::ExistingFiles);
808 else
809 m_dialog.setFileMode(QFileDialog::ExistingFile);
810 }
811 m_dialog.setDirectory(dir);
812 if (m_dialog.exec())
813 filenames = m_dialog.selectedFiles();
814 } else {
815 if (m_isForDirectory) {
816 QString file = QFileDialog::getExistingDirectory(this, "Select directory", dir);
817 if (!file.isEmpty())
818 filenames.append(file);
819 } else if (m_allowMultipleFiles) {
820 filenames = QFileDialog::getOpenFileNames(this, "Open file", dir, m_fileFilter, nullptr,
821 QFileDialog::DontResolveSymlinks);
822 } else {
823 QString file =
824 QFileDialog::getOpenFileName(this, "Open file", dir, m_fileFilter, nullptr, QFileDialog::DontResolveSymlinks);
825 if (!file.isEmpty())
826 filenames.append(file);
827 }
828 }
829
830 if (filenames.isEmpty()) {
831 return "";
832 }
833 m_lastDir = QFileInfo(filenames.front()).absoluteDir().path();
834 return filenames.join(", ");
835}
836
842void FileFinderWidget::setEntryNumProblem(const QString &message) {
843 m_entryNumProblem = message;
845}
846
852 if (m_showValidator) {
853 if (!m_fileProblem.isEmpty()) {
854 m_uiForm.valid->setToolTip(m_fileProblem);
855 m_uiForm.valid->show();
856 } else if (!m_entryNumProblem.isEmpty() && m_multiEntry) {
857 m_uiForm.valid->setToolTip(m_entryNumProblem);
858 m_uiForm.valid->show();
859 } else {
860 m_uiForm.valid->hide();
861 }
862 } else {
863 m_uiForm.valid->hide();
864 }
865}
866
870 QString uFile = openFileDialog();
871 if (uFile.trimmed().isEmpty())
872 return;
873
874 m_uiForm.fileEditor->setText(uFile);
875 m_uiForm.fileEditor->setModified(true);
876
877 emit fileEditingFinished();
878}
879
884 if (m_uiForm.entryNum->text().isEmpty()) {
886 return;
887 }
888
889 bool good;
890 const int num = m_uiForm.entryNum->text().toInt(&good);
891 if (!good) {
892 setEntryNumProblem("The entry number must be an integer");
893 return;
894 }
895 if (num < 1) {
896 setEntryNumProblem("The entry number must be an integer > 0");
897 return;
898 }
899
901}
902
907void FileFinderWidget::dropEvent(QDropEvent *de) {
908 const QMimeData *mimeData = de->mimeData();
909 const auto filenames = DropEventHelper::getFileNames(de);
910 if (!filenames.empty()) {
911 m_uiForm.fileEditor->setText(filenames[0]);
912 de->acceptProposedAction();
913 } else if (mimeData->hasText()) {
914 QString text = mimeData->text();
915 m_uiForm.fileEditor->setText(text);
916 de->acceptProposedAction();
917 }
918}
919
924void FileFinderWidget::dragEnterEvent(QDragEnterEvent *de) {
925 const QMimeData *mimeData = de->mimeData();
926 if (mimeData->hasUrls()) {
927 auto listurl = mimeData->urls();
928 if (listurl.empty())
929 return;
930 if (!listurl[0].isLocalFile())
931 return;
932 de->acceptProposedAction();
933 } else if (mimeData->hasText()) {
934 QString text = mimeData->text();
935 if (text.contains(" = mtd[\""))
936 de->setDropAction(Qt::IgnoreAction);
937 else
938 de->acceptProposedAction();
939 }
940}
941
948void FileFinderWidget::setReadOnly(bool readOnly) {
949 m_uiForm.fileEditor->setReadOnly(readOnly);
950 m_uiForm.browseBtn->setEnabled(!readOnly);
951 setValidatorDisplay(!readOnly);
953}
954
962
964 FindFilesSearchParameters parameters;
965 parameters.searchText = text;
966 parameters.isOptional = isOptional();
967 parameters.isForRunFiles = isForRunFiles();
968 parameters.extensions = getStringFileExtensions();
969
970 // parse the algorithm - property name string
971 QStringList elements = m_algorithmProperty.split("|");
972 if (elements.size() == 2) {
973 parameters.algorithmName = elements[0].toStdString();
974 parameters.algorithmProperty = elements[1].toStdString();
975 }
976
977 return parameters;
978}
979
980void FileFinderWidget::setTextValidator(const QValidator *validator) { m_uiForm.fileEditor->setValidator(validator); }
981
983 m_useNativeDialog = native;
984 m_dialog.setOption(QFileDialog::DontUseNativeDialog);
985 m_dialog.setOption(QFileDialog::ReadOnly);
986}
987
988void 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
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.
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.
void saveSettings(const QString &group)
Save settings in the given group.
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.
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
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.
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
void readSettings(const QString &group)
Read settings from the given group.
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 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.