Mantid
Loading...
Searching...
No Matches
FileFinderWidget.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2009 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 +
7#pragma once
8
12#include "ui_FileFinderWidget.h"
13#include <QComboBox>
14#include <QFileDialog>
15#include <QMessageBox>
16#include <QSettings>
17#include <QString>
18#include <QStringList>
19#include <memory>
20
21namespace Mantid {
22namespace API {
23class IAlgorithm;
24}
25} // namespace Mantid
26
27namespace MantidQt {
28// namespace MantidWidgets {
29// class DataSelector;
30// }
31namespace API {
32
43 Q_OBJECT
44
45 Q_PROPERTY(bool findRunFiles READ isForRunFiles WRITE isForRunFiles)
46 Q_PROPERTY(bool findDirectory READ isForDirectory WRITE isForDirectory)
47 Q_PROPERTY(QString label READ getLabelText WRITE setLabelText)
48 Q_PROPERTY(bool multipleFiles READ allowMultipleFiles WRITE allowMultipleFiles)
49 Q_PROPERTY(bool optional READ isOptional WRITE isOptional)
50 Q_PROPERTY(bool multiEntry READ doMultiEntry WRITE doMultiEntry)
51 Q_PROPERTY(ButtonOpts buttonOpt READ doButtonOpt WRITE doButtonOpt)
52 Q_PROPERTY(QString algorithmAndProperty READ getAlgorithmProperty WRITE setAlgorithmProperty)
53 Q_PROPERTY(QStringList fileExtensions READ getFileExtensions WRITE setFileExtensions)
54 Q_PROPERTY(bool extsAsSingleOption READ extsAsSingleOption WRITE extsAsSingleOption)
55 Q_PROPERTY(LiveButtonOpts liveButton READ liveButtonState WRITE liveButtonState)
56 Q_PROPERTY(QString instrumentOverride READ getInstrumentOverride WRITE setInstrumentOverride)
57 Q_ENUMS(ButtonOpts)
58 Q_ENUMS(LiveButtonOpts)
59
60public:
65 None
66 };
68 enum {
69 NO_ENTRY_NUM = -1,
70 ALL_ENTRIES = -2
71 };
76 };
77
79 FileFinderWidget(QWidget *parent = nullptr);
80
81 // property accessors/modifiers
82 bool isForRunFiles() const;
83 void isForRunFiles(bool /*mode*/);
84 bool isForDirectory() const;
85 void isForDirectory(bool /*mode*/);
86 QString getLabelText() const;
87 void setLabelText(const QString &text);
88 void setLabelMinWidth(int /*width*/);
89 bool allowMultipleFiles() const;
90 void allowMultipleFiles(bool /*allow*/);
91 bool isOptional() const;
92 void isOptional(bool /*optional*/);
93 ButtonOpts doButtonOpt() const;
94 void doButtonOpt(ButtonOpts buttonOpt);
95 bool doMultiEntry() const;
96 void doMultiEntry(bool /*multiEntry*/);
97 QString getAlgorithmProperty() const;
98 void setAlgorithmProperty(const QString &name);
99 QStringList getFileExtensions() const;
100 std::vector<std::string> getStringFileExtensions() const;
101 void setFileExtensions(const QStringList &extensions);
102 bool extsAsSingleOption() const;
103 void extsAsSingleOption(bool value);
104 LiveButtonOpts liveButtonState() const;
105 void liveButtonState(LiveButtonOpts /*option*/);
106
107 // Standard setters/getters
108 void liveButtonSetChecked(bool /*checked*/);
109 bool liveButtonIsChecked() const;
110 bool isEmpty() const;
111 QString getText() const;
112
113 bool isValid() const;
114 bool isSearching() const;
115 QStringList getFilenames() const;
116 QString getFirstFilename() const;
117 int getEntryNum() const;
118 void setEntryNum(const int num);
121 QVariant getUserInput() const override;
123 void setUserInput(const QVariant &value) override;
125 void setText(const QString &value);
128 void setFileProblem(const QString &message);
130 QString getFileProblem();
132 void readSettings(const QString &group);
134 void saveSettings(const QString &group);
137 void setNumberOfEntries(int number);
140 void setLiveAlgorithm(const std::shared_ptr<Mantid::API::IAlgorithm> &monitorLiveData);
142 QString getInstrumentOverride();
144 void setInstrumentOverride(const QString &instName);
146 void setReadOnly(bool readOnly);
148 QString getLastDirectory() { return m_lastDir; }
150 void setLastDirectory(const QString &lastDir) { m_lastDir = lastDir; }
152 void setTextValidator(const QValidator *validator);
153 void setUseNativeWidget(bool /*native*/);
154 void setProxyModel(QAbstractProxyModel *proxyModel);
155
156signals:
158 void fileTextChanged(const QString & /*_t1*/);
172 void liveButtonPressed(bool /*_t1*/);
175
176public slots:
178 void setFileTextWithSearch(const QString &text);
180 void setFileTextWithoutSearch(const QString &text);
182 void clear();
184 void findFiles();
186 void findFiles(bool isModified);
187 std::shared_ptr<const Mantid::API::IAlgorithm> stopLiveAlgorithm();
188
189public:
190 // Method for handling drop events
191 void dropEvent(QDropEvent * /*unused*/) override;
192 // called when a drag event enters the class
193 void dragEnterEvent(QDragEnterEvent * /*unused*/) override;
194
195private:
197 QString createFileFilter();
199 QStringList getFileExtensionsFromAlgorithm(const QString &algName, const QString &propName);
201 QStringList getFilesFromAlgorithm(const QString &algName, const QString &propName, const QString &filename);
203 QString openFileDialog();
206 void setEntryNumProblem(const QString &message);
209 void refreshValidator();
211 void setValidatorDisplay(bool display);
213 const QString findFilesGetSearchText(QString &searchText);
215 void runFindFiles(const QString &searchText);
217 FindFilesSearchParameters createFindFilesSearchParameters(const std::string &text) const;
218
219private slots:
221 void browseClicked();
223 void checkEntry();
225 void inspectThreadResult(const FindFilesSearchResults &results = FindFilesSearchResults());
226
227private:
247 QStringList m_fileExtensions;
253 std::shared_ptr<Mantid::API::IAlgorithm> m_monitorLiveData;
257 Ui::FileFinderWidget m_uiForm;
260 QStringList m_foundFiles;
262 QStringList m_lastFoundFiles;
264 QString m_lastDir;
276 QFileDialog m_dialog;
279};
280
281} // namespace API
282} // namespace MantidQt
283
#define EXPORT_OPT_MANTIDQT_COMMON
Definition: DllOption.h:15
double value
The value of the point.
Definition: FitMW.cpp:51
This class defines a widget for file searching.
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.
QFileDialog m_dialog
non-native QFileDialog
bool m_extsAsSingleOption
If true the exts are displayed as one option in the dialog.
FindFilesThreadPoolManager m_pool
Handle to a find files thread pool manager.
QStringList getFilesFromAlgorithm(const QString &algName, const QString &propName, const QString &filename)
Create an extension list from the name algorithm and property.
QString getLastDirectory()
Get the last directory.
std::shared_ptr< Mantid::API::IAlgorithm > m_monitorLiveData
Handle on a running instance of MonitorLiveData.
FindFilesSearchResults m_cachedResults
Handle to any results found.
void filesFoundChanged()
Emitted when files have been found that are different to what was found last time.
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
@ Text
use a button (normally labelled "Browse")
void fileTextChanged(const QString &)
Emitted when the file text changes.
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.
bool m_allowMultipleFiles
Allow multiple files.
QString m_algorithmProperty
The algorithm name and property (can be empty)
void findingFiles()
Emitted when files finding starts.
Ui::FileFinderWidget m_uiForm
The Ui form.
bool m_showValidator
Whether validation red star is being shown.
void liveButtonPressed(bool)
Emitted when the live button is toggled.
void filesFound()
Emitted when files have been found.
LiveButtonOpts
Options for the live button.
@ Hide
Don't use the live button.
@ Show
Display the live button.
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.
QString m_fileFilter
A file filter for the file browser.
LiveButtonOpts m_liveButtonState
If or when live button will be shown.
QStringList m_fileExtensions
The file extensions to look for.
QString m_defaultInstrumentName
Cache the default instrument name.
void setLastDirectory(const QString &lastDir)
Set the last directory.
bool m_useNativeDialog
flag to control use of m_dialog
void fileFindingFinished()
Emitted when file finding is finished (files may or may not have been found).
QString m_lastDir
The last directory viewed by the browse dialog.
A small helper class to hold a handle to a static thread pool.
This is the base class all customised widgets that do not wish to be tied to a specific Mantid algori...
Definition: MantidWidget.h:27
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
Helper class which provides the Collimation Length for SANS instruments.
POD struct to hold details about the parameters of a file search.
POD struct to hold details about the results of a file search.