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 // When first used try to starting directory better than the directory
77 // MantidPlot is installed in
78 // First try default save directory
79 m_lastDir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory"));
80
81 // If that fails pick the first data search directory
82 if (m_lastDir.isEmpty()) {
83 QStringList dataDirs =
84 QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("datasearch.directories"))
85 .split(";", Qt::SkipEmptyParts);
86
87 if (!dataDirs.isEmpty())
88 m_lastDir = dataDirs[0];
89 }
90
91 // this for accepts drops, but the underlying text input does not.
92 this->setAcceptDrops(true);
93 m_uiForm.fileEditor->setAcceptDrops(false);
94}
95
101
106void FileFinderWidget::isForRunFiles(const bool mode) { m_findRunFiles = mode; }
107
113
118void FileFinderWidget::isForDirectory(const bool mode) {
119 clear();
120 m_isForDirectory = mode;
121}
122
127QString FileFinderWidget::getLabelText() const { return m_uiForm.textLabel->text(); }
128
133void FileFinderWidget::setLabelText(const QString &text) {
134 m_uiForm.textLabel->setText(text);
135 m_uiForm.textLabel->setVisible(!text.isEmpty());
136}
137
141void FileFinderWidget::setLabelMinWidth(const int width) { m_uiForm.textLabel->setMinimumWidth(width); }
142
149
156 m_allowMultipleFiles = allow;
157 findFiles();
158}
159
164
169void FileFinderWidget::isOptional(const bool optional) {
171 findFiles();
172}
173
179
187 if (buttonOpt == None) {
188 m_uiForm.browseBtn->hide();
189 m_uiForm.browseIco->hide();
190 } else if (buttonOpt == Text) {
191 m_uiForm.browseBtn->show();
192 m_uiForm.browseIco->hide();
193 } else if (buttonOpt == Icon) {
194 m_uiForm.browseBtn->hide();
195 m_uiForm.browseIco->show();
196 }
197}
198
205
210void FileFinderWidget::doMultiEntry(const bool multiEntry) {
212 if (m_multiEntry) {
213 m_uiForm.entryNum->show();
214 m_uiForm.numEntries->show();
215 } else {
216 m_uiForm.entryNum->hide();
217 m_uiForm.numEntries->hide();
218 }
220}
221
227
239
240std::vector<std::string> FileFinderWidget::getStringFileExtensions() const {
241 std::vector<std::string> extensions;
242 std::transform(m_fileExtensions.begin(), m_fileExtensions.end(), std::back_inserter(extensions),
243 [](const QString &extension) { return extension.toStdString(); });
244
245 return extensions;
246}
247
253void FileFinderWidget::setFileExtensions(const QStringList &extensions) {
254 m_fileExtensions = extensions;
255 m_fileFilter.clear();
256}
257
264
272
275
277 m_liveButtonState = option;
278 if (m_liveButtonState == Hide) {
279 m_uiForm.liveButton->hide();
280 } else if (m_liveButtonState == Show) {
281 m_uiForm.liveButton->show();
282 }
283}
284
285void FileFinderWidget::liveButtonSetChecked(const bool checked) { m_uiForm.liveButton->setChecked(checked); }
286
287bool FileFinderWidget::liveButtonIsChecked() const { return m_uiForm.liveButton->isChecked(); }
288
293bool FileFinderWidget::isValid() const { return m_uiForm.valid->isHidden(); }
294
300
305QStringList FileFinderWidget::getFilenames() const { return m_foundFiles; }
306
315 if (m_foundFiles.isEmpty())
316 return "";
317 else
318 return m_foundFiles[0];
319}
320
324bool FileFinderWidget::isEmpty() const { return m_uiForm.fileEditor->text().isEmpty(); }
325
329QString FileFinderWidget::getText() const { return m_uiForm.fileEditor->text(); }
330
336 if (m_uiForm.entryNum->text().isEmpty() || (!m_multiEntry)) {
337 return ALL_ENTRIES;
338 }
339 if (isValid()) {
340 bool isANumber;
341 const int period = m_uiForm.entryNum->text().toInt(&isANumber);
342 if (isANumber) {
343 return period;
344 }
345 }
346 return NO_ENTRY_NUM;
347}
348
352void FileFinderWidget::setEntryNum(const int num) { m_uiForm.entryNum->setText(QString::number(num)); }
353
361QVariant FileFinderWidget::getUserInput() const { return QVariant(m_valueForProperty); }
362
371void FileFinderWidget::setText(const QString &value) { m_uiForm.fileEditor->setText(value); }
372
384 m_uiForm.fileEditor->setText(value.toString());
385 m_uiForm.fileEditor->setModified(true);
386 emit fileEditingFinished(); // Which is connected to slot findFiles()
387}
388
396void FileFinderWidget::setFileProblem(const QString &message) {
397 m_fileProblem = message;
399}
400
406
411void FileFinderWidget::saveSettings(const QString &group) {
412 QSettings settings;
413 settings.beginGroup(group);
414
415 settings.setValue("last_directory", m_lastDir);
416
417 settings.endGroup();
418}
419
426 const QString total = number > 0 ? QString::number(number) : "?";
427 { m_uiForm.numEntries->setText("/" + total); }
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 setFileProblem("A directory must be provided");
510 } else {
511 setFileProblem("");
512 m_foundFiles.append(searchText);
513 }
514 return;
515 }
516
517 if (isModified) {
518 // Reset modified flag.
519 m_uiForm.fileEditor->setModified(false);
520 searchText = findFilesGetSearchText(searchText);
521 runFindFiles(searchText);
522 } else {
523 // Make sure errors are correctly set if we didn't run
525 }
526}
527
533const QString FileFinderWidget::findFilesGetSearchText(QString &searchText) {
534 // If we have an override instrument then add it in appropriate places to
535 // the search text
536 if (!m_defaultInstrumentName.isEmpty()) {
537 // Regex to match a selection of run numbers as defined here:
538 // mantidproject.org/MultiFileLoading
539 // Also allowing spaces between delimiters as this seems to work fine
540 const std::string runNumberString = "([0-9]+)([:+-] ?[0-9]+)? ?(:[0-9]+)?";
541 boost::regex runNumberExp(runNumberString, boost::regex::extended);
542 // Regex to match a list of run numbers delimited by commas
543 const std::string runListString = "(" + runNumberString + ")(, ?(" + runNumberString + "))*";
544 boost::regex runNumberListExp(runListString, boost::regex::extended);
545
546 // See if we can just prepend the instrument and be done
547 if (boost::regex_match(searchText.toStdString(), runNumberExp)) {
548 searchText = m_defaultInstrumentName + searchText;
549 }
550 // If it is a list we need to prepend the instrument to all run numbers
551 else if (boost::regex_match(searchText.toStdString(), runNumberListExp)) {
552 QStringList runNumbers = searchText.split(",", Qt::SkipEmptyParts);
553 QStringList newRunNumbers;
554
555 for (auto &runNumber : runNumbers)
556 newRunNumbers << m_defaultInstrumentName + runNumber.simplified();
557
558 searchText = newRunNumbers.join(",");
559 }
560 }
561 return searchText;
562}
563
568void FileFinderWidget::runFindFiles(const QString &searchText) {
569 emit findingFiles();
570
571 const auto parameters = createFindFilesSearchParameters(searchText.toStdString());
572 m_pool.createWorker(this, parameters);
573}
574
582 IAlgorithm_const_sptr theAlgorithmBeingCancelled = m_monitorLiveData;
583 if (m_monitorLiveData && m_monitorLiveData->isRunning()) {
584 m_monitorLiveData->cancel();
585 m_monitorLiveData.reset();
586 }
587 return theAlgorithmBeingCancelled;
588}
589
595 // Update caches before we might exit early
596 m_cachedResults = results;
597 m_valueForProperty = QString::fromStdString(results.valueForProperty);
598 m_foundFiles.clear();
599 m_lastFoundFiles.clear();
600
601 // Early exit on failure
602 if (!results.error.empty()) {
603 setFileProblem(QString::fromStdString(results.error));
605 return;
606 }
607
608 for (const auto &filename : results.filenames) {
609 m_foundFiles.append(QString::fromStdString(filename));
610 }
611 if (m_foundFiles.isEmpty() && !isOptional()) {
612 setFileProblem("No files found. Check search paths and instrument selection.");
613 } else if (m_foundFiles.count() > 1 && this->allowMultipleFiles() == false) {
614 setFileProblem("Multiple files specified.");
615 } else {
616 setFileProblem("");
617 }
618
620
621 // Only emit the signal if file(s) were found
622 if (!m_foundFiles.isEmpty())
623 emit filesFound();
625 emit filesFoundChanged();
626}
627
632void FileFinderWidget::readSettings(const QString &group) {
633 QSettings settings;
634 settings.beginGroup(group);
635 m_lastDir = settings.value("last_directory", "").toString();
636
637 if (m_lastDir == "") {
638 QStringList datadirs =
639 QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("datasearch.directories"))
640 .split(";", Qt::SkipEmptyParts);
641 if (!datadirs.isEmpty())
642 m_lastDir = datadirs[0];
643 }
644
645 settings.endGroup();
646}
647
653 QStringList fileExts;
654 if (m_algorithmProperty.isEmpty()) {
655 if (!m_fileExtensions.isEmpty()) {
656 fileExts = m_fileExtensions;
657 } else if (isForRunFiles()) {
658 std::vector<std::string> exts = ConfigService::Instance().getFacility().extensions();
659 for (auto &ext : exts) {
660 fileExts.append(QString::fromStdString(ext));
661 }
662 } else {
663 }
664 } else {
665 QStringList elements = m_algorithmProperty.split("|");
666 if (elements.size() == 2) {
667 fileExts = getFileExtensionsFromAlgorithm(elements[0], elements[1]);
668 }
669 }
670
671 QString allFiles("All Files (*)");
672 if (!fileExts.isEmpty()) {
673
674 // The list may contain upper and lower cased versions, ensure these are on
675 // the same line
676 // I want this ordered
678 QStringListIterator sitr(fileExts);
679 QString ext = sitr.next();
680 finalIndex.append(qMakePair(ext.toUpper(), QStringList(ext)));
681 while (sitr.hasNext()) {
682 ext = sitr.next();
683 QString key = ext.toUpper();
684 bool found(false);
685 const int itemCount = finalIndex.count();
686 for (int i = 0; i < itemCount; ++i) {
687 if (key == finalIndex[i].first) {
688 finalIndex[i].second.append(ext);
689 found = true;
690 break;
691 }
692 }
693 if (!found) {
694 finalIndex.append(qMakePair(key, QStringList(ext)));
695 }
696 }
697
698 // The file filter consists of three parts, which we will combine to create
699 // the
700 // complete file filter:
701 QString dataFiles("Data Files (");
702 QString individualFiles("");
703
704 if (extsAsSingleOption()) {
705 QListIterator<QPair<QString, QStringList>> itr(finalIndex);
706 while (itr.hasNext()) {
707 const QStringList values = itr.next().second;
708
709 individualFiles += "*" + values.join(" *") + ";;";
710 dataFiles += "*" + values.join(" *") + " ";
711 }
712 // Don't remove final ;; from individualFiles as we are going to tack on
713 // allFiles anyway
714 dataFiles.chop(1); // Remove last space
715 dataFiles += ");;";
716 } else {
717 QListIterator<QPair<QString, QStringList>> itr(finalIndex);
718 while (itr.hasNext()) {
719 const QStringList values = itr.next().second;
720 dataFiles += "*" + values.join(" *") + ";;";
721 }
722 }
723 return dataFiles + individualFiles + allFiles;
724 } else {
725 return allFiles;
726 }
727}
728
735QStringList FileFinderWidget::getFileExtensionsFromAlgorithm(const QString &algName, const QString &propName) {
737 Mantid::API::AlgorithmManager::Instance().createUnmanaged(algName.toStdString());
738 QStringList fileExts;
739 if (!algorithm)
740 return fileExts;
741 algorithm->initialize();
742 Property *prop = algorithm->getProperty(propName.toStdString());
743 FileProperty *fileProp = dynamic_cast<FileProperty *>(prop);
744 auto *multiFileProp = dynamic_cast<MultipleFileProperty *>(prop);
745
746 std::vector<std::string> allowed;
747 QString preferredExt;
748
749 if (fileProp) {
750 allowed = fileProp->allowedValues();
751 preferredExt = QString::fromStdString(fileProp->getDefaultExt());
752 } else if (multiFileProp) {
753 allowed = multiFileProp->allowedValues();
754 preferredExt = QString::fromStdString(multiFileProp->getDefaultExt());
755 } else {
756 return fileExts;
757 }
758
759 std::vector<std::string>::const_iterator iend = allowed.end();
760 int index(0);
761 for (std::vector<std::string>::const_iterator it = allowed.begin(); it != iend; ++it) {
762 if (!it->empty()) {
763 QString ext = QString::fromStdString(*it);
764 fileExts.append(ext);
765 if (ext == preferredExt) {
766 fileExts.move(index, 0);
767 }
768 ++index;
769 }
770 }
771
772 return fileExts;
773}
774
780 QStringList filenames;
781 QString dir;
782
783 auto prevFileNames = getText().split(",", Qt::SkipEmptyParts);
784 for (auto &prevFileName : prevFileNames)
785 prevFileName = prevFileName.trimmed();
786
787 if (!prevFileNames.empty() && QFileInfo(prevFileNames[0]).isAbsolute()) {
788 if (QFileInfo(prevFileNames[0]).isFile()) {
789 dir = QFileInfo(prevFileNames[0]).absoluteDir().path();
790 } else {
791 dir = prevFileNames[0];
792 }
793 } else {
794 dir = m_lastDir;
795 }
796
797 if (m_fileFilter.isEmpty()) {
799 }
800
801 if (!m_useNativeDialog) {
802 if (m_isForDirectory) {
803 m_dialog.setOption(QFileDialog::DontResolveSymlinks, false);
804 m_dialog.setFileMode(QFileDialog::Directory);
805 } else {
806 m_dialog.setNameFilter(m_fileFilter);
807 m_dialog.setOption(QFileDialog::DontResolveSymlinks);
809 m_dialog.setFileMode(QFileDialog::ExistingFiles);
810 else
811 m_dialog.setFileMode(QFileDialog::ExistingFile);
812 }
813 m_dialog.setDirectory(dir);
814 if (m_dialog.exec())
815 filenames = m_dialog.selectedFiles();
816 } else {
817 if (m_isForDirectory) {
818 QString file = QFileDialog::getExistingDirectory(this, "Select directory", dir);
819 if (!file.isEmpty())
820 filenames.append(file);
821 } else if (m_allowMultipleFiles) {
822 filenames = QFileDialog::getOpenFileNames(this, "Open file", dir, m_fileFilter, nullptr,
823 QFileDialog::DontResolveSymlinks);
824 } else {
825 QString file =
826 QFileDialog::getOpenFileName(this, "Open file", dir, m_fileFilter, nullptr, QFileDialog::DontResolveSymlinks);
827 if (!file.isEmpty())
828 filenames.append(file);
829 }
830 }
831
832 if (filenames.isEmpty()) {
833 return "";
834 }
835 m_lastDir = QFileInfo(filenames.front()).absoluteDir().path();
836 return filenames.join(", ");
837}
838
844void FileFinderWidget::setEntryNumProblem(const QString &message) {
845 m_entryNumProblem = message;
847}
848
854 if (m_showValidator) {
855 if (!m_fileProblem.isEmpty()) {
856 m_uiForm.valid->setToolTip(m_fileProblem);
857 m_uiForm.valid->show();
858 } else if (!m_entryNumProblem.isEmpty() && m_multiEntry) {
859 m_uiForm.valid->setToolTip(m_entryNumProblem);
860 m_uiForm.valid->show();
861 } else {
862 m_uiForm.valid->hide();
863 }
864 } else {
865 m_uiForm.valid->hide();
866 }
867}
868
872 QString uFile = openFileDialog();
873 if (uFile.trimmed().isEmpty())
874 return;
875
876 m_uiForm.fileEditor->setText(uFile);
877 m_uiForm.fileEditor->setModified(true);
878
879 emit fileEditingFinished();
880}
881
886 if (m_uiForm.entryNum->text().isEmpty()) {
888 return;
889 }
890
891 bool good;
892 const int num = m_uiForm.entryNum->text().toInt(&good);
893 if (!good) {
894 setEntryNumProblem("The entry number must be an integer");
895 return;
896 }
897 if (num < 1) {
898 setEntryNumProblem("The entry number must be an integer > 0");
899 return;
900 }
901
903}
904
909void FileFinderWidget::dropEvent(QDropEvent *de) {
910 const QMimeData *mimeData = de->mimeData();
911 const auto filenames = DropEventHelper::getFileNames(de);
912 if (!filenames.empty()) {
913 m_uiForm.fileEditor->setText(filenames[0]);
914 de->acceptProposedAction();
915 } else if (mimeData->hasText()) {
916 QString text = mimeData->text();
917 m_uiForm.fileEditor->setText(text);
918 de->acceptProposedAction();
919 }
920}
921
926void FileFinderWidget::dragEnterEvent(QDragEnterEvent *de) {
927 const QMimeData *mimeData = de->mimeData();
928 if (mimeData->hasUrls()) {
929 auto listurl = mimeData->urls();
930 if (listurl.empty())
931 return;
932 if (!listurl[0].isLocalFile())
933 return;
934 de->acceptProposedAction();
935 } else if (mimeData->hasText()) {
936 QString text = mimeData->text();
937 if (text.contains(" = mtd[\""))
938 de->setDropAction(Qt::IgnoreAction);
939 else
940 de->acceptProposedAction();
941 }
942}
943
950void FileFinderWidget::setReadOnly(bool readOnly) {
951 m_uiForm.fileEditor->setReadOnly(readOnly);
952 m_uiForm.browseBtn->setEnabled(!readOnly);
953 setValidatorDisplay(!readOnly);
955}
956
964
966 FindFilesSearchParameters parameters;
967 parameters.searchText = text;
968 parameters.isOptional = isOptional();
969 parameters.isForRunFiles = isForRunFiles();
970 parameters.extensions = getStringFileExtensions();
971
972 // parse the algorithm - property name string
973 QStringList elements = m_algorithmProperty.split("|");
974 if (elements.size() == 2) {
975 parameters.algorithmName = elements[0].toStdString();
976 parameters.algorithmProperty = elements[1].toStdString();
977 }
978
979 return parameters;
980}
981
982void FileFinderWidget::setTextValidator(const QValidator *validator) { m_uiForm.fileEditor->setValidator(validator); }
983
985 m_useNativeDialog = native;
986 m_dialog.setOption(QFileDialog::DontUseNativeDialog);
987 m_dialog.setOption(QFileDialog::ReadOnly);
988}
989
990void 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
Definition: DeltaEMode.cpp:19
QString getFileProblem()
Get file problem, empty string means no error.
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.
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
QString getAlgorithmProperty() const
Returns the algorithm name.
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.
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.
QStringList getFilenames() const
Returns the names of the files found.
void setReadOnly(bool readOnly)
Set the input read-only or not.
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.
QStringList getFileExtensions() const
Returns the list of file extensions the widget will search for.
void checkEntry()
currently checks only if the entry number is any integer > 0
QString getInstrumentOverride()
Gets the instrument currently fixed to.
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.
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...
Definition: MantidWidget.h:27
A specialized class for dealing with file properties.
Definition: FileProperty.h:42
std::string getDefaultExt() const
Returns the main file extension that's used.
Definition: FileProperty.h:90
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
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
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.