Debian Codegraph @

avogadro/qtgui/extensionplugin.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_EXTENSIONPLUGIN_H
7 #define AVOGADRO_QTGUI_EXTENSIONPLUGIN_H
8
9 #include "avogadroqtguiexport.h"
10
11 #include <avogadro/qtplugins/pluginfactory.h>
12
13 #include <QtCore/QObject>
14
15 class QAction;
16
17 namespace Avogadro {
18
19 namespace QtGui {
20 class Molecule;
21 }
22
23 namespace Rendering {
24 class Camera;
25 class Scene;
26 } // namespace Rendering
27
28 namespace Io {
29 class FileFormat;
30 }
31
32 namespace QtGui {
33
34 /**
35 * @class ExtensionPlugin extensionplugin.h <avogadro/qtgui/extensionplugin.h>
36 * @brief The base class for extension plugin factories in Avogadro.
37 * @author Marcus D. Hanwell
38 */
39 class AVOGADROQTGUI_EXPORT ExtensionPlugin : public QObject
40 {
41 Q_OBJECT
42
43 public:
44 explicit ExtensionPlugin(QObject* parent = nullptr);
45 ~ExtensionPlugin() override;
46
47 /**
48 * The name of the extension plugin, will be displayed in the user interface.
49 */
50 virtual QString name() const = 0;
51
52 /**
53 * A description of the extension plugin, may be displayed in the user
54 * interface.
55 */
56 virtual QString description() const = 0;
57
58 /**
59 * @return The QActions for this extension (should be at least one).
60 */
61 virtual QList<QAction*> actions() const = 0;
62
63 /**
64 * @return The menu path of the supplied action. This can be empty if the
65 * action was not recognized, or contain two or more strings (top level, plus
66 * name, e.g. File, &Open).
67 */
68 virtual QStringList menuPath(QAction* action = nullptr) const = 0;
69
70 /**
71 * @return A list of file format readers/writers.
72 *
73 * The caller takes ownership of the objects in the returned list.
74 */
75 virtual QList<Io::FileFormat*> fileFormats() const;
76
77 /**
78 * If the extension plugin has script commands, this method
79 * should be implemented to emit the registerCommand signals.
80 */
81 virtual void registerCommands() {}
82
83 public slots:
84 /**
85 * Called when the current molecule changes.
86 */
87 virtual void setMolecule(QtGui::Molecule* mol) = 0;
88
89 /**
90 * Call this slot when the moleculeReady signal indicated that a molecule is
91 * ready to be read. The @p molecule will have the data read into it. The slot
92 * will @return true if a molecule was successfully read in.
93 */
94 virtual bool readMolecule(QtGui::Molecule& mol);
95
96 /**
97 * Called when the current scene changes.
98 */
99 virtual void setScene(Rendering::Scene* scene);
100
101 /**
102 * Called when the active camera for the view changes.
103 */
104 virtual void setCamera(Rendering::Camera* camera);
105
106 /**
107 * Called when the active widget changes. This must be used carefully, and
108 * should check that the widget has been cast if used.
109 */
110 virtual void setActiveWidget(QWidget* widget);
111
112 /**
113 * Called by the app to handle a command registered by the extension.
114 * (e.g., "renderMovie" or "generateSurface", etc.)
115 *
116 * The app will turn the command into a string and pass it to the extension.
117 * and any options will go from a JSON dictionary to a QVariantMap.
118 *
119 * @return true if the command was handled, false otherwise.
120 */
121 virtual bool handleCommand(const QString& command,
122 const QVariantMap& options);
123
124 signals:
125 /**
126 * Signal that the extension has a new molecule that is ready to be loaded.
127 * The application must call readMolecule in order to actually read the
128 * molecule(s).
129 */
130 void moleculeReady(int numberOfMolecules);
131
132 /**
133 * Signal that the extension has file formats that are ready to be registered.
134 * If emitted the application should call fileFormats to get the formats the
135 * extension is registering.
136 */
137 void fileFormatsReady();
138
139 /**
140 * Signal to request a particular tool is set as the active tool. This is
141 * useful when loading a structure outside of the normal file API and setting
142 * "Navigator" to active instead of "Editor" (the default).
143 */
144 void requestActiveTool(QString toolName);
145
146 /**
147 * Request a specific display type (or types) are made active.
148 * This can be useful when loading a specific type of data that
149 * would be most readily viewed with a specialized view.
150 */
151 void requestActiveDisplayTypes(QStringList displayTypes);
152
153 /**
154 * Register a new command with the application. The command will be available
155 * through scripting (e.g., "renderMovie" or "generateSurface", etc.)
156 *
157 * @param command The name of the command to register.
158 * @param description A description of the command.
159 *
160 * @sa handleCommand
161 */
162 void registerCommand(QString command, QString description);
163
164 /**
165 * Indicate that a particular script command is finished.
166 * (e.g., from handleCommand)
167 * @param message An optional message to the script or user
168 */
169 void commandFinished(const QString& message = QString());
170
171 /**
172 * Indicate that the list of actions for this extension has changed.
173 * The application should rebuild menus to reflect the new action list.
174 */
175 void actionsChanged();
176 };
177
178 /**
179 * @class ExtensionPluginFactory extensionplugin.h
180 * <avogadro/qtgui/extensionplugin.h>
181 * @brief The base class for extension plugin factories in Avogadro.
182 * @author Marcus D. Hanwell
183 */
184 class AVOGADROQTGUI_EXPORT ExtensionPluginFactory
185 : public QtPlugins::PluginFactory<ExtensionPlugin>
186 {
187 public:
188 ~ExtensionPluginFactory() override;
189 };
190
191 } // namespace QtGui
192 } // namespace Avogadro
193
194 Q_DECLARE_INTERFACE(Avogadro::QtGui::ExtensionPluginFactory,
195 "org.openchemistry.avogadro.ExtensionPluginFactory")
196
197 #endif // AVOGADRO_QTGUI_EXTENSIONPLUGIN_H