Newer
Older
Gigg, Martyn Anthony
committed
#ifndef MANTIDQT_API_ALGORITHMDIALOG_H_
#define MANTIDQT_API_ALGORITHMDIALOG_H_
/* Used to register classes into the factory. creates a global object in an
* anonymous namespace. The object itself does nothing, but the comma operator
* is used in the call to its constructor to effect a call to the factory's
* subscribe method.
*/
Gigg, Martyn Anthony
committed
#define DECLARE_DIALOG(classname) \
namespace { \
Mantid::Kernel::RegistrationHelper register_dialog_##classname(( \
(MantidQt::API::AlgorithmDialogFactory::Instance().subscribe<classname>( \
#classname)), \
0)); \
Gigg, Martyn Anthony
committed
}
//----------------------------------
// Includes
//----------------------------------
#include "DllOption.h"
Gigg, Martyn Anthony
committed
#include "InterfaceFactory.h"
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
// Could have forward declared this but it makes it easier to use from
// inheriting classes if it is included here
#include "MantidAPI/AlgorithmObserver.h"
Gigg, Martyn Anthony
committed
#include <QDialog>
Gigg, Martyn Anthony
committed
#include <QString>
#include <QVBoxLayout>
Gigg, Martyn Anthony
committed
//----------------------------------
// Qt Forward declarations
//----------------------------------
class QLabel;
Gigg, Martyn Anthony
committed
class QLineEdit;
Gigg, Martyn Anthony
committed
class QComboBox;
class QCheckBox;
class QPushButton;
class QHBoxLayout;
Gigg, Martyn Anthony
committed
class QSignalMapper;
Gigg, Martyn Anthony
committed
class QLayout;
Gigg, Martyn Anthony
committed
//----------------------------------
// Mantid Forward declarations
//----------------------------------
namespace Mantid {
namespace Kernel {
class Property;
}
Gigg, Martyn Anthony
committed
// Top-level namespace for this library
namespace MantidQt {
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
//----------------------------------
// Forward declarations
//----------------------------------
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
This class should be the basis for all customised algorithm dialogs.
Gigg, Martyn Anthony
committed
@author Martyn Gigg, Tessella Support Services plc
@date 24/02/2009
Copyright © 2009 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
Gigg, Martyn Anthony
committed
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
Gigg, Martyn Anthony
committed
*/
class EXPORT_OPT_MANTIDQT_COMMON AlgorithmDialog
: public QDialog,
Mantid::API::AlgorithmObserver {
Gigg, Martyn Anthony
committed
Q_OBJECT
public:
/// DefaultConstructor
AlgorithmDialog(QWidget *parent = nullptr);
Gigg, Martyn Anthony
committed
/// Destructor
~AlgorithmDialog() override;
Gigg, Martyn Anthony
committed
/// Set if the keep open option is shown.
void setShowKeepOpen(const bool showOption);
/// Set if the keep open option is shown.
bool isShowKeepOpen() const;
Gigg, Martyn Anthony
committed
/// Create the layout of the widget. Can only be called once.
void initializeLayout();
/// Is this dialog initialized
bool isInitialized() const;
protected:
Gigg, Martyn Anthony
committed
/** @name Virtual functions */
//@{
Gigg, Martyn Anthony
committed
/// This does the work and must be overridden in each deriving class
virtual void initLayout() = 0;
/// Parse out the values entered into the dialog boxes. Use
/// storePropertyValue()
/// to store the <name, value> pair in the base class so that they can be
/// retrieved later
Gigg, Martyn Anthony
committed
virtual void parseInput();
Gigg, Martyn Anthony
committed
/// Save the input history of an accepted dialog
virtual void saveInput();
Gigg, Martyn Anthony
committed
//@}
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
/** @name Algorithm information */
// InterfaceManager needs to be able to reset the algorithm as I can't pass it
// in use a
Gigg, Martyn Anthony
committed
// constructor
Gigg, Martyn Anthony
committed
/// Get the algorithm pointer
Mantid::API::IAlgorithm_sptr getAlgorithm() const;
Gigg, Martyn Anthony
committed
/// Get a pointer to the named property
Mantid::Kernel::Property *getAlgorithmProperty(const QString &propName) const;
Gigg, Martyn Anthony
committed
/// Return a true if the given property requires user input
bool requiresUserInput(const QString &propName) const;
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
/// Get an input value from the form, dealing with blank inputs etc
QString getInputValue(const QString &propName) const;
Gigg, Martyn Anthony
committed
/// Get a property validator label
QLabel *getValidatorMarker(const QString &propname);
Gigg, Martyn Anthony
committed
/// Adds a property (name,value) pair to the stored map
void storePropertyValue(const QString &name, const QString &value);
Gigg, Martyn Anthony
committed
/// Removes a property (name, value) pair from the stored map
void removePropertyValue(const QString &name);
Gigg, Martyn Anthony
committed
/// Set properties on this algorithm by pulling values from the tied widgets
bool setPropertyValues(const QStringList &skipList = QStringList());
Janik Zikovsky
committed
bool setPropertyValue(const QString pName, bool validateOthers);
Gigg, Martyn Anthony
committed
//@}
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
/** @name Dialog information */
//@{
Gigg, Martyn Anthony
committed
/// Get the message string
const QString &getOptionalMessage() const;
Gigg, Martyn Anthony
committed
/// Add the optional message to the given layout.
void addOptionalMessage(QVBoxLayout *mainLay);
Gigg, Martyn Anthony
committed
/// Get the usage boolean value
bool isForScript() const;
Gigg, Martyn Anthony
committed
/// Is there a message string available
bool isMessageAvailable() const;
Gigg, Martyn Anthony
committed
/// Check is a given property should have its control enabled or not
bool isWidgetEnabled(const QString &propName) const;
Gigg, Martyn Anthony
committed
//@}
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
/** @name Helper functions */
//@{
/// Tie a widget to a property
QWidget *tie(QWidget *widget, const QString &property,
QLayout *parent_layout = nullptr, bool readHistory = true);
/// Untie a widget to a property
void untie(const QString &property);
Lynch, Vickie
committed
Gigg, Martyn Anthony
committed
/// Open a file dialog to select a file.
QString openFileDialog(const QString &propName);
Gigg, Martyn Anthony
committed
Janik Zikovsky
committed
/// Open a file dialog to select many file.
QStringList openMultipleFileDialog(const QString &propName);
Janik Zikovsky
committed
Gigg, Martyn Anthony
committed
/// Fill a combo box for the named algorithm's allowed values
void fillAndSetComboBox(const QString &propName, QComboBox *optionsBox) const;
Gigg, Martyn Anthony
committed
/// Fill in the necessary input for a text field
void fillLineEdit(const QString &propName, QLineEdit *field);
Gigg, Martyn Anthony
committed
/// Create a row layout of buttons with specified text
QLayout *
createDefaultButtonLayout(const QString &helpText = QString("?"),
const QString &loadText = QString("Run"),
const QString &cancelText = QString("Close"),
const QString &keepOpenText = QString("Keep Open"));
Gigg, Martyn Anthony
committed
/// Create a help button for this algorithm
QPushButton *createHelpButton(const QString &helpText = QString("?")) const;
Gigg, Martyn Anthony
committed
/// Flag an input workspace combobox with its property name
Gigg, Martyn Anthony
committed
void flagInputWS(QWidget *inputWidget);
Gigg, Martyn Anthony
committed
//@}
Janik Zikovsky
committed
/// Retrieve a text value for a property from a widget
QString getValue(QWidget *widget);
signals:
/// Emitted when alg completes and dialog is staying open
void algCompletedSignal();
Janik Zikovsky
committed
protected slots:
Gigg, Martyn Anthony
committed
/// A default slot that can be used for an OK button.
void accept() override;
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
/// Help button clicked;
Gigg, Martyn Anthony
committed
virtual void helpClicked();
Gigg, Martyn Anthony
committed
/// Keep open checkbox clicked;
virtual void keepOpenChanged(int state);
/// Keep the running algorithm has completed
virtual void algorithmCompleted();
/// Executes the algorithm in a separate thread
virtual void executeAlgorithmAsync();
/// Removes the algorithm from the manager.
virtual void removeAlgorithmFromManager();
/// Enable to exit button
void enableExitButton();
Gigg, Martyn Anthony
committed
/// Parse out the input from the dialog
void parse();
Gigg, Martyn Anthony
committed
/// Test if the given name's widget has been explicity asked to be enabled
bool requestedToKeepEnabled(const QString &propName) const;
/// Get the property value from either the previous input store or from Python
/// argument
/// @param propName :: Name of the property
/// @return Previous value. If there is no value, empty string is returned
QString getPreviousValue(const QString &propName) const;
/// Set a value based on any old input that we have
void setPreviousValue(QWidget *widget, const QString &property);
/// Handle completion of algorithm started while staying open
void finishHandle(const Mantid::API::IAlgorithm *alg) override;
/// Handle completion of algorithm started while staying open
void errorHandle(const Mantid::API::IAlgorithm *alg,
const std::string &what) override;
void closeEvent(QCloseEvent *evt) override;
/// The following methods were made public for testing in
/// GenericDialogDemo.cpp
public:
/// Set the algorithm associated with this dialog
void setAlgorithm(Mantid::API::IAlgorithm_sptr);
/// Set a list of suggested values
void setPresetValues(const QHash<QString, QString> &presetValues);
Gigg, Martyn Anthony
committed
/// Set whether this is intended for use from a script or not
void isForScript(bool forScript);
/// If true then execute the algorithm on acceptance
void executeOnAccept(bool on);
Gigg, Martyn Anthony
committed
/// Set an optional message to be displayed at the top of the dialog
void setOptionalMessage(const QString &message);
/// Set comma-separated-list of enabled parameter names
void addEnabledAndDisableLists(const QStringList &enabled,
const QStringList &disabled);
/// Add an AlgorithmObserver to the algorithm
void addAlgorithmObserver(Mantid::API::AlgorithmObserver *observer);
Janik Zikovsky
committed
protected:
Gigg, Martyn Anthony
committed
/** @name Member variables. */
//@{
/// The algorithm associated with this dialog
Mantid::API::IAlgorithm_sptr m_algorithm;
Gigg, Martyn Anthony
committed
/// The name of the algorithm
Gigg, Martyn Anthony
committed
QString m_algName;
Gigg, Martyn Anthony
committed
/// The properties associated with this dialog
QStringList m_algProperties;
Janik Zikovsky
committed
Gigg, Martyn Anthony
committed
/// A map of property <name, value> pairs that have been taken from the dialog
Gigg, Martyn Anthony
committed
QHash<QString, QString> m_propertyValueMap;
Janik Zikovsky
committed
/// A list pointers to the widget for each property
QHash<QString, QWidget *> m_tied_properties;
Janik Zikovsky
committed
Gigg, Martyn Anthony
committed
/// A boolean indicating whether this is for a script or not
Gigg, Martyn Anthony
committed
bool m_forScript;
Gigg, Martyn Anthony
committed
/// A list of property names that have been passed from Python
QStringList m_python_arguments;
Gigg, Martyn Anthony
committed
/// A list of property names that should have their widgets enabled
Gigg, Martyn Anthony
committed
QStringList m_enabled;
/// A list of property names that the user has requested to be disabled
/// (overrides those in enabled)
Gigg, Martyn Anthony
committed
QStringList m_disabled;
Gigg, Martyn Anthony
committed
/// The message string to be displayed at the top of the widget; if it exists.
/// Whether to keep the dialog box open after alg execution
bool m_keepOpen;
Gigg, Martyn Anthony
committed
/// Is the message string empty or not
bool m_msgAvailable;
/// Whether the layout has been initialized
Gigg, Martyn Anthony
committed
bool m_isInitialized;
/// Flag if the input should be parsed automatically on initialization
bool m_autoParseOnInit;
Gigg, Martyn Anthony
committed
/// A list of labels to use as validation markers
QHash<QString, QLabel *> m_validators;
Janik Zikovsky
committed
/// A map where key = property name; value = the error for this property (i.e.
/// it is not valid).
QHash<QString, QString> m_errors;
Janik Zikovsky
committed
Gigg, Martyn Anthony
committed
/// A list of property names whose widgets handle their own validation
QStringList m_noValidation;
Gigg, Martyn Anthony
committed
/// Store a list of the names of input workspace boxes
QVector<QWidget *> m_inputws_opts;
Gigg, Martyn Anthony
committed
/// Store a list of output workspace text edits
QVector<QLineEdit *> m_outputws_fields;
Gigg, Martyn Anthony
committed
Gigg, Martyn Anthony
committed
/// A map to keep track of replace workspace button presses
QHash<QPushButton *, int> m_wsbtn_tracker;
// the keep open checkbox control
QCheckBox *m_keepOpenCheckBox;
QPushButton *m_okButton, *m_exitButton;
/// A list of AlgorithmObservers to add to the algorithm prior to execution
std::vector<Mantid::API::AlgorithmObserver *> m_observers;
/// Enable the close button when the timer fires
QTimer m_btnTimer;
/// A flag to track whether the status of the algorithm is being tracked
bool m_statusTracked;
Gigg, Martyn Anthony
committed
//@}
};
} // namespace API
} // namespace MantidQt
#endif // MANTIDQT_API_ALGORITHMDIALOG_H_