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 bool found(false);
688 const int itemCount = finalIndex.count();
689 for (int i = 0; i < itemCount; ++i) {
690 if (key == finalIndex[i].first) {
691 finalIndex[i].second.append(ext);
692 found = true;
693 break;
694 }
695 }
696 if (!found) {
697 finalIndex.append(qMakePair(key, QStringList(ext)));
698 }
699 }
700
701 // The file filter consists of three parts, which we will combine to create
702 // the
703 // complete file filter:
704 QString dataFiles("Data Files (");
705 QString individualFiles("");
706
707 if (extsAsSingleOption()) {
708 QListIterator<QPair<QString, QStringList>> itr(finalIndex);
709 while (itr.hasNext()) {
710 const QStringList values = itr.next().second;
711
712 individualFiles += "*" + values.join(" *") + ";;";
713 dataFiles += "*" + values.join(" *") + " ";
714 }
715 // Don't remove final ;; from individualFiles as we are going to tack on
716 // allFiles anyway
717 dataFiles.chop(1); // Remove last space
718 dataFiles += ");;";
719 } else {
720 QListIterator<QPair<QString, QStringList>> itr(finalIndex);
721 while (itr.hasNext()) {
722 const QStringList values = itr.next().second;
723 dataFiles += "*" + values.join(" *") + ";;";
724 }
725 }
726 return dataFiles + individualFiles + allFiles;
727 } else {
728 return allFiles;
729 }
730}
731
738QStringList FileFinderWidget::getFileExtensionsFromAlgorithm(const QString &algName, const QString &propName) {
740 Mantid::API::AlgorithmManager::Instance().createUnmanaged(algName.toStdString());
741 QStringList fileExts;
742 if (!algorithm)
743 return fileExts;
744 algorithm->initialize();
745 Property *prop = algorithm->getProperty(propName.toStdString());
746 FileProperty *fileProp = dynamic_cast<FileProperty *>(prop);
747 auto *multiFileProp = dynamic_cast<MultipleFileProperty *>(prop);
748
749 std::vector<std::string> allowed;
750 QString preferredExt;
751
752 if (fileProp) {
753 allowed = fileProp->allowedValues();
754 preferredExt = QString::fromStdString(fileProp->getDefaultExt());
755 } else if (multiFileProp) {
756 allowed = multiFileProp->allowedValues();
757 preferredExt = QString::fromStdString(multiFileProp->getDefaultExt());
758 } else {
759 return fileExts;
760 }
761
762 std::vector<std::string>::const_iterator iend = allowed.end();
763 int index(0);
764 for (std::vector<std::string>::const_iterator it = allowed.begin(); it != iend; ++it) {
765 if (!it->empty()) {
766 QString ext = QString::fromStdString(*it);
767 fileExts.append(ext);
768 if (ext == preferredExt) {
769 fileExts.move(index, 0);
770 }
771 ++index;
772 }
773 }
774
775 return fileExts;
776}
777
783 QStringList filenames;
784 QString dir;
785
786 auto prevFileNames = getText().split(",", Qt::SkipEmptyParts);
787 for (auto &prevFileName : prevFileNames)
788 prevFileName = prevFileName.trimmed();
789
790 if (!prevFileNames.empty() && QFileInfo(prevFileNames[0]).isAbsolute()) {
791 if (QFileInfo(prevFileNames[0]).isFile()) {
792 dir = QFileInfo(prevFileNames[0]).absoluteDir().path();
793 } else {
794 dir = prevFileNames[0];
795 }
796 } else {
797 dir = m_lastDir;
798 }
799
800 if (m_fileFilter.isEmpty()) {
802 }
803
804 if (!m_useNativeDialog) {
805 if (m_isForDirectory) {
806 m_dialog.setOption(QFileDialog::DontResolveSymlinks, false);
807 m_dialog.setFileMode(QFileDialog::Directory);
808 } else {
809 m_dialog.setNameFilter(m_fileFilter);
810 m_dialog.setOption(QFileDialog::DontResolveSymlinks);
812 m_dialog.setFileMode(QFileDialog::ExistingFiles);
813 else
814 m_dialog.setFileMode(QFileDialog::ExistingFile);
815 }
816 m_dialog.setDirectory(dir);
817 if (m_dialog.exec())
818 filenames = m_dialog.selectedFiles();
819 } else {
820 if (m_isForDirectory) {
821 QString file = QFileDialog::getExistingDirectory(this, "Select directory", dir);
822 if (!file.isEmpty())
823 filenames.append(file);
824 } else if (m_allowMultipleFiles) {
825 filenames = QFileDialog::getOpenFileNames(this, "Open file", dir, m_fileFilter, nullptr,
826 QFileDialog::DontResolveSymlinks);
827 } else {
828 QString file =
829 QFileDialog::getOpenFileName(this, "Open file", dir, m_fileFilter, nullptr, QFileDialog::DontResolveSymlinks);
830 if (!file.isEmpty())
831 filenames.append(file);
832 }
833 }
834
835 if (filenames.isEmpty()) {
836 return "";
837 }
838 m_lastDir = QFileInfo(filenames.front()).absoluteDir().path();
839 return filenames.join(", ");
840}
841
847void FileFinderWidget::setEntryNumProblem(const QString &message) {
848 m_entryNumProblem = message;
850}
851
857 if (m_showValidator) {
858 if (!m_fileProblem.isEmpty()) {
859 m_uiForm.valid->setToolTip(m_fileProblem);
860 m_uiForm.valid->show();
861 } else if (!m_entryNumProblem.isEmpty() && m_multiEntry) {
862 m_uiForm.valid->setToolTip(m_entryNumProblem);
863 m_uiForm.valid->show();
864 } else {
865 m_uiForm.valid->hide();
866 }
867 } else {
868 m_uiForm.valid->hide();
869 }
870}
871
875 QString uFile = openFileDialog();
876 if (uFile.trimmed().isEmpty())
877 return;
878
879 m_uiForm.fileEditor->setText(uFile);
880 m_uiForm.fileEditor->setModified(true);
881
882 emit fileEditingFinished();
883}
884
889 if (m_uiForm.entryNum->text().isEmpty()) {
891 return;
892 }
893
894 bool good;
895 const int num = m_uiForm.entryNum->text().toInt(&good);
896 if (!good) {
897 setEntryNumProblem("The entry number must be an integer");
898 return;
899 }
900 if (num < 1) {
901 setEntryNumProblem("The entry number must be an integer > 0");
902 return;
903 }
904
906}
907
912void FileFinderWidget::dropEvent(QDropEvent *de) {
913 const QMimeData *mimeData = de->mimeData();
914 const auto filenames = DropEventHelper::getFileNames(de);
915 if (!filenames.empty()) {
916 m_uiForm.fileEditor->setText(filenames[0]);
917 de->acceptProposedAction();
918 } else if (mimeData->hasText()) {
919 QString text = mimeData->text();
920 m_uiForm.fileEditor->setText(text);
921 de->acceptProposedAction();
922 }
923}
924
929void FileFinderWidget::dragEnterEvent(QDragEnterEvent *de) {
930 const QMimeData *mimeData = de->mimeData();
931 if (mimeData->hasUrls()) {
932 auto listurl = mimeData->urls();
933 if (listurl.empty())
934 return;
935 if (!listurl[0].isLocalFile())
936 return;
937 de->acceptProposedAction();
938 } else if (mimeData->hasText()) {
939 QString text = mimeData->text();
940 if (text.contains(" = mtd[\""))
941 de->setDropAction(Qt::IgnoreAction);
942 else
943 de->acceptProposedAction();
944 }
945}
946
953void FileFinderWidget::setReadOnly(bool readOnly) {
954 m_uiForm.fileEditor->setReadOnly(readOnly);
955 m_uiForm.browseBtn->setEnabled(!readOnly);
956 setValidatorDisplay(!readOnly);
958}
959
967
969 FindFilesSearchParameters parameters;
970 parameters.searchText = text;
971 parameters.isOptional = isOptional();
972 parameters.isForRunFiles = isForRunFiles();
973 parameters.extensions = getStringFileExtensions();
974
975 // parse the algorithm - property name string
976 QStringList elements = m_algorithmProperty.split("|");
977 if (elements.size() == 2) {
978 parameters.algorithmName = elements[0].toStdString();
979 parameters.algorithmProperty = elements[1].toStdString();
980 }
981
982 return parameters;
983}
984
985void FileFinderWidget::setTextValidator(const QValidator *validator) { m_uiForm.fileEditor->setValidator(validator); }
986
988 m_useNativeDialog = native;
989 m_dialog.setOption(QFileDialog::DontUseNativeDialog);
990 m_dialog.setOption(QFileDialog::ReadOnly);
991}
992
993void 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.