Mantid
Loading...
Searching...
No Matches
AlgorithmDialog.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
9/* Used to register classes into the factory. creates a global object in an
10 * anonymous namespace. The object itself does nothing, but the comma operator
11 * is used in the call to its constructor to effect a call to the factory's
12 * subscribe method.
13 */
14
15#define DECLARE_DIALOG(classname) \
16 namespace { \
17 Mantid::Kernel::RegistrationHelper register_dialog_##classname( \
18 ((MantidQt::API::AlgorithmDialogFactory::Instance().subscribe<classname>(#classname)), 0)); \
19 }
20
21//----------------------------------
22// Includes
23//----------------------------------
25#include "DllOption.h"
26
27// Could have forward declared this but it makes it easier to use from
28// inheriting classes if it is included here
31
32#include <QDialog>
33#include <QHash>
34#include <QString>
35#include <QTimer>
36#include <QVBoxLayout>
37
38//----------------------------------
39// Qt Forward declarations
40//----------------------------------
41class QLabel;
42class QLineEdit;
43class QComboBox;
44class QCheckBox;
45class QPushButton;
46class QHBoxLayout;
47class QSignalMapper;
48class QLayout;
49
50//----------------------------------
51// Mantid Forward declarations
52//----------------------------------
53namespace Mantid {
54namespace Kernel {
55class Property;
56}
57} // namespace Mantid
58
59// Top-level namespace for this library
60namespace MantidQt {
61
62namespace API {
63
64//----------------------------------
65// Forward declarations
66//----------------------------------
68
76
77 Q_OBJECT
78
79public:
81 AlgorithmDialog(QWidget *parent = nullptr);
83 ~AlgorithmDialog() override;
84
86 void setShowKeepOpen(const bool showOption);
87
89 bool isShowKeepOpen() const;
90
92 void initializeLayout();
93
95 bool isInitialized() const;
96
97protected:
101 virtual void initLayout() = 0;
102
107 virtual void parseInput();
108
110 virtual void saveInput();
112
114 // InterfaceManager needs to be able to reset the algorithm as I can't pass it
115 // in use a
116 // constructor
117 friend class InterfaceManager;
118
120 Mantid::API::IAlgorithm_sptr getAlgorithm() const;
121
123 Mantid::Kernel::Property *getAlgorithmProperty(const QString &propName) const;
125 bool requiresUserInput(const QString &propName) const;
126
128 QString getInputValue(const QString &propName) const;
130 QLabel *getValidatorMarker(const QString &propname);
131
133 void storePropertyValue(const QString &name, const QString &value);
134
136 void removePropertyValue(const QString &name);
137
139 bool setPropertyValues(const QStringList &skipList = QStringList());
140 bool setPropertyValue(const QString &pName, bool validateOthers);
141
142 void showValidators();
144
148 const QString &getOptionalMessage() const;
149
151 void addOptionalMessage(QVBoxLayout *mainLay);
152
154 bool isForScript() const;
155
157 bool isMessageAvailable() const;
158
160 bool isWidgetEnabled(const QString &propName) const;
162
166 QWidget *tie(QWidget *widget, const QString &property, QLayout *parent_layout = nullptr, bool readHistory = true);
167
169 void untie(const QString &property);
170
172 QString openFileDialog(const QString &propName);
173
175 QStringList openMultipleFileDialog(const QString &propName);
176
178 void fillAndSetComboBox(const QString &propName, QComboBox *optionsBox) const;
179
181 void fillLineEdit(const QString &propName, QLineEdit *field);
182
184 QLayout *createDefaultButtonLayout(const QString &helpText = QString("?"), const QString &loadText = QString("Run"),
185 const QString &cancelText = QString("Close"),
186 const QString &keepOpenText = QString("Keep Open"));
187
189 QPushButton *createHelpButton(const QString &helpText = QString("?")) const;
190
192 void flagInputWS(QWidget *inputWidget);
194
196 QString getValue(QWidget *widget);
197
198signals:
201
203
204protected slots:
205
207 void accept() override;
208
210 void reject() override;
211
213 virtual void helpClicked();
214
216 virtual void keepOpenChanged(int state);
217
219 virtual void algorithmCompleted();
220
222 virtual void executeAlgorithmAsync();
224 virtual void removeAlgorithmFromManager();
226 void enableExitButton();
227
228protected:
230 void parse();
232 bool requestedToKeepEnabled(const QString &propName) const;
237 QString getPreviousValue(const QString &propName) const;
239 void setPreviousValue(QWidget *widget, const QString &property);
241 void finishHandle(const Mantid::API::IAlgorithm *alg) override;
243 void errorHandle(const Mantid::API::IAlgorithm *alg, const std::string &what) override;
244 void closeEvent(QCloseEvent *evt) override;
245
248public:
250 void setAlgorithm(const Mantid::API::IAlgorithm_sptr & /*alg*/);
252 void setPresetValues(const QHash<QString, QString> &presetValues);
254 void isForScript(bool forScript);
256 void executeOnAccept(bool on);
258 void setOptionalMessage(const QString &message);
260 void addEnabledAndDisableLists(const QStringList &enabled, const QStringList &disabled);
262 void addAlgorithmObserver(Mantid::API::AlgorithmObserver *observer);
263
264protected:
269
271 QString m_algName;
273 QStringList m_algProperties;
274
277
280
286 QStringList m_enabled;
289 QStringList m_disabled;
296
301
304
308
310 QStringList m_noValidation;
311
313 QVector<QWidget *> m_inputws_opts;
314
316 QVector<QLineEdit *> m_outputws_fields;
317
320
321 // the keep open checkbox control
323
324 QPushButton *m_okButton, *m_exitButton;
325
327 std::vector<Mantid::API::AlgorithmObserver *> m_observers;
328
334};
335} // namespace API
336} // namespace MantidQt
#define EXPORT_OPT_MANTIDQT_COMMON
Definition: DllOption.h:15
double value
The value of the point.
Definition: FitMW.cpp:51
This class should be the basis for all customised algorithm dialogs.
QStringList m_enabled
A list of property names that should have their widgets enabled.
void algCompletedSignal()
Emitted when alg completes and dialog is staying open.
bool m_statusTracked
A flag to track whether the status of the algorithm is being tracked.
QStringList m_python_arguments
A list of property names that have been passed from Python.
QString m_strMessage
The message string to be displayed at the top of the widget; if it exists.
QHash< QString, QWidget * > m_tied_properties
A list pointers to the widget for each property.
QVector< QWidget * > m_inputws_opts
Store a list of the names of input workspace boxes.
QStringList m_disabled
A list of property names that the user has requested to be disabled (overrides those in enabled)
bool m_forScript
A boolean indicating whether this is for a script or not.
virtual void initLayout()=0
This does the work and must be overridden in each deriving class.
bool m_autoParseOnInit
Flag if the input should be parsed automatically on initialization.
Mantid::API::IAlgorithm_sptr m_algorithm
The algorithm associated with this dialog.
bool m_msgAvailable
Is the message string empty or not.
QHash< QString, QString > m_errors
A map where key = property name; value = the error for this property (i.e.
QHash< QString, QString > m_propertyValueMap
A map of property <name, value> pairs that have been taken from the dialog.
QString m_algName
The name of the algorithm.
bool m_keepOpen
Whether to keep the dialog box open after alg execution.
std::vector< Mantid::API::AlgorithmObserver * > m_observers
A list of AlgorithmObservers to add to the algorithm prior to execution.
QStringList openMultipleFileDialog(const QString &propName)
Open a file dialog to select many file.
QVector< QLineEdit * > m_outputws_fields
Store a list of output workspace text edits.
QTimer m_btnTimer
Enable the close button when the timer fires.
QStringList m_algProperties
The properties associated with this dialog.
QStringList m_noValidation
A list of property names whose widgets handle their own validation.
bool m_isInitialized
Whether the layout has been initialized.
QHash< QPushButton *, int > m_wsbtn_tracker
A map to keep track of replace workspace button presses.
QHash< QString, QLabel * > m_validators
A list of labels to use as validation markers.
This class is responsible for creating the correct dialog for an algorithm.
Observes Algorithm notifications: start,progress,finish,error.
IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:45
Base class for properties.
Definition: Property.h:94
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
Helper class which provides the Collimation Length for SANS instruments.