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
35public:
36 explicit FileFinderSettings(const QString &lastDirectory = {}) : m_lastDirectory(lastDirectory) {}
37
38 const QString &lastDirectory() const { return m_lastDirectory; }
39
40private:
42};
43
54 Q_OBJECT
55
56 Q_PROPERTY(bool findRunFiles READ isForRunFiles WRITE isForRunFiles)
57 Q_PROPERTY(bool findDirectory READ isForDirectory WRITE isForDirectory)
58 Q_PROPERTY(QString label READ getLabelText WRITE setLabelText)
59 Q_PROPERTY(bool multipleFiles READ allowMultipleFiles WRITE allowMultipleFiles)
60 Q_PROPERTY(bool optional READ isOptional WRITE isOptional)
61 Q_PROPERTY(bool multiEntry READ doMultiEntry WRITE doMultiEntry)
62 Q_PROPERTY(ButtonOpts buttonOpt READ doButtonOpt WRITE doButtonOpt)
63 Q_PROPERTY(QString algorithmAndProperty READ getAlgorithmProperty WRITE setAlgorithmProperty)
64 Q_PROPERTY(QStringList fileExtensions READ getFileExtensions WRITE setFileExtensions)
65 Q_PROPERTY(bool extsAsSingleOption READ extsAsSingleOption WRITE extsAsSingleOption)
66 Q_PROPERTY(LiveButtonOpts liveButton READ liveButtonState WRITE liveButtonState)
67 Q_PROPERTY(QString instrumentOverride READ getInstrumentOverride WRITE setInstrumentOverride)
68 Q_ENUMS(ButtonOpts)
69 Q_ENUMS(LiveButtonOpts)
70
71public:
76 None
77 };
79 enum {
80 NO_ENTRY_NUM = -1,
81 ALL_ENTRIES = -2
82 };
88
90 FileFinderWidget(QWidget *parent = nullptr);
91
92 // property accessors/modifiers
93 bool isForRunFiles() const;
94 void isForRunFiles(bool /*mode*/);
95 bool isForDirectory() const;
96 void isForDirectory(bool /*mode*/);
97 QString getLabelText() const;
98 void setLabelText(const QString &text);
99 void setLabelMinWidth(int /*width*/);
100 bool allowMultipleFiles() const;
101 void allowMultipleFiles(bool /*allow*/);
102 bool isOptional() const;
103 void isOptional(bool /*optional*/);
104 ButtonOpts doButtonOpt() const;
105 void doButtonOpt(ButtonOpts buttonOpt);
106 bool doMultiEntry() const;
107 void doMultiEntry(bool /*multiEntry*/);
108 const QString &getAlgorithmProperty() const;
109 void setAlgorithmProperty(const QString &name);
110 const QStringList &getFileExtensions() const;
111 std::vector<std::string> getStringFileExtensions() const;
112 void setFileExtensions(const QStringList &extensions);
113 bool extsAsSingleOption() const;
114 void extsAsSingleOption(bool value);
115 LiveButtonOpts liveButtonState() const;
116 void liveButtonState(LiveButtonOpts /*option*/);
117
118 // Standard setters/getters
119 void liveButtonSetChecked(bool /*checked*/);
120 bool liveButtonIsChecked() const;
121 bool isEmpty() const;
122 QString getText() const;
123
124 bool isValid() const;
125 bool isSearching() const;
126 const QStringList &getFilenames() const;
127 QString getFirstFilename() const;
128 int getEntryNum() const;
129 void setEntryNum(const int num);
132 QVariant getUserInput() const override;
134 void setUserInput(const QVariant &value) override;
136 void setText(const QString &value);
139 void setFileProblem(const QString &message);
141 const QString &getFileProblem() const;
143 [[nodiscard]] static FileFinderSettings readSettings(const QSettings &settings);
145 void restoreSettings(const FileFinderSettings &settings);
147 [[nodiscard]] FileFinderSettings captureSettings() const;
149 void saveSettings(QSettings &settings, const FileFinderSettings &values) const;
152 void setNumberOfEntries(int number);
155 void setLiveAlgorithm(const std::shared_ptr<Mantid::API::IAlgorithm> &monitorLiveData);
157 const QString &getInstrumentOverride() const;
159 void setInstrumentOverride(const QString &instName);
161 void setReadOnly(bool readOnly);
163 const QString &getLastDirectory() const { return m_lastDir; }
165 void setLastDirectory(const QString &lastDir) { m_lastDir = lastDir; }
167 void setTextValidator(const QValidator *validator);
168 void setUseNativeWidget(bool /*native*/);
169 void setProxyModel(QAbstractProxyModel *proxyModel);
170
171signals:
173 void fileTextChanged(const QString & /*_t1*/);
187 void liveButtonPressed(bool /*_t1*/);
190
191public slots:
193 void setFileTextWithSearch(const QString &text);
195 void setFileTextWithoutSearch(const QString &text);
197 void clear();
199 void findFiles();
201 void findFiles(bool isModified);
202 std::shared_ptr<const Mantid::API::IAlgorithm> stopLiveAlgorithm();
203
204public:
205 // Method for handling drop events
206 void dropEvent(QDropEvent * /*unused*/) override;
207 // called when a drag event enters the class
208 void dragEnterEvent(QDragEnterEvent * /*unused*/) override;
209
210private:
212 QString createFileFilter();
214 QStringList getFileExtensionsFromAlgorithm(const QString &algName, const QString &propName);
216 QStringList getFilesFromAlgorithm(const QString &algName, const QString &propName, const QString &filename);
218 QString openFileDialog();
221 void setEntryNumProblem(const QString &message);
224 void refreshValidator();
226 void setValidatorDisplay(bool display);
228 const QString findFilesGetSearchText(QString &searchText);
230 void runFindFiles(const QString &searchText);
232 FindFilesSearchParameters createFindFilesSearchParameters(const std::string &text) const;
233
234private slots:
236 void browseClicked();
238 void checkEntry();
240 void inspectThreadResult(const FindFilesSearchResults &results = FindFilesSearchResults());
241
242private:
262 QStringList m_fileExtensions;
268 std::shared_ptr<Mantid::API::IAlgorithm> m_monitorLiveData;
272 Ui::FileFinderWidget m_uiForm;
275 QStringList m_foundFiles;
277 QStringList m_lastFoundFiles;
279 QString m_lastDir;
291 QFileDialog m_dialog;
294};
295
296} // namespace API
297} // namespace MantidQt
298
std::string name
Definition Run.cpp:60
#define EXPORT_OPT_MANTIDQT_COMMON
Definition DllOption.h:15
double value
The value of the point.
Definition FitMW.cpp:51
Immutable snapshot of the persistent state used by FileFinderWidget.
const QString & lastDirectory() const
FileFinderSettings(const QString &lastDirectory={})
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.
const QString & getLastDirectory() const
Get the last directory.
QStringList getFilesFromAlgorithm(const QString &algName, const QString &propName, const QString &filename)
Create an extension list from the name algorithm and property.
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...
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.