Debian Codegraph @

avogadro/qtgui/interfacewidget.h

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #ifndef AVOGADRO_QTGUI_INTERFACEWIDGET_H
7 #define AVOGADRO_QTGUI_INTERFACEWIDGET_H
8
9 #include "avogadroqtguiexport.h"
10
11 #include <QtCore/QJsonObject>
12 #include <QtCore/QMap>
13 #include <QtWidgets/QWidget>
14
15 #include "interfacescript.h"
16 #include "jsonwidget.h"
17
18 class QJsonValue;
19 class QTextEdit;
20 class QWidget;
21
22 namespace Avogadro {
23 namespace QtGui {
24 class Molecule;
25
26 /**
27 * @class InterfaceWidget interfacewidget.h
28 * <avogadro/qtgui/interfacewidget.h>
29 * @brief The InterfaceWidget class provides a user interface for
30 * running external scripts
31 * @sa InterfaceScript
32 *
33 * The InterfaceWidget creates a GUI to represent the options given by an
34 * script, turning JSON from the script into a form and passing the results
35 * back to the script via command-line
36 */
37 class AVOGADROQTGUI_EXPORT InterfaceWidget : public JsonWidget
38 {
39 Q_OBJECT
40
41 public:
42 /**
43 * Construct a widget that dynamically generates a GUI to configure the
44 * script specified by scriptFilePath. Pass an empty string to create
45 * without loading a script (configure via interfaceScript() then call
46 * reloadOptions()).
47 */
48 explicit InterfaceWidget(const QString& scriptFilePath,
49 QWidget* parent_ = nullptr);
50
51 ~InterfaceWidget() override;
52
53 /**
54 * Use the script pointed to by scriptFilePath.
55 * @param scriptFilePath Absolute path to script.
56 */
57 void setInterfaceScript(const QString& scriptFilePath);
58
59 /**
60 * Re-fetch options from the underlying script and rebuild the GUI.
61 * Call this after configuring the interpreter (e.g. for package mode).
62 */
63 void reloadOptions();
64
65 /**
66 * Access to the underlying input script object. @{
67 */
68 QtGui::InterfaceScript& interfaceScript() { return m_interfaceScript; }
69 const QtGui::InterfaceScript& interfaceScript() const
70 {
71 return m_interfaceScript;
72 }
73 /** @} */
74
75 private slots:
76 /**
77 * Triggered when the user resets the default values.
78 */
79 void defaultsClicked();
80
81 /**
82 * Show the user an warning. These are messages returned by the input
83 * script.
84 */
85 void setWarningText(const QString& warn);
86
87 /**
88 * Show the warning text.
89 */
90 QString warningText() const;
91
92 /**
93 * Show the user an error message. These are errors that have occurred
94 * in this extension, not necessarily in the input generator script.
95 */
96 void showError(const QString& err);
97
98 private:
99 /**
100 * Generate a QSettings key with the given identifier that is unique to this
101 * input generator's display name.
102 * @param identifier Setting key, e.g. "outputPath"
103 * @return Script-specific key, e.g. "quantumInput/GAMESS/outputPath"
104 * @todo Display names are not necessarily unique, but paths are too long.
105 * Maybe add a namespace qualifier to the script display names?
106 */
107 QString settingsKey(const QString& identifier) const;
108
109 QtGui::Molecule* m_molecule;
110 QtGui::InterfaceScript m_interfaceScript;
111 };
112
113 } // namespace QtGui
114 } // namespace Avogadro
115
116 #endif // AVOGADRO_QTGUI_INTERFACEWIDGET_H