The following sections describe the steps that are required to create a plugin which derives from ContextFreePlugin. For simplicity, a separate project is created and the generated binary will to be copied to the plugin directory of the given cube installation.
To create a cube plugins, a makefile and source files have to be generated. The makefile can be generated automatically from a Qt project file
First we specify the path to the "cube-config" script of the cube installation. This script delivers correct flags for compiling and linking.
qmake && make will build the first plugin example libContextFreeExamplePlugin.so. The plugin will be copied to the plugin directory, e.g. /opt/cube/lib64/plugins.
The example describes a minimal context free plugin. The plugin becames active, if Cube is started without an input file, or if the cube file is closed.
The complete source of the example can be found in
A context free plugin has to derive from ContextFreePlugin. To use Qt's signal and slot mechanism it also has to derive from QObject.
The class header is followed by the following macro definitions:
Q_OBJECT is required to handle signals and slots.
Q_INTERFACES( ContextFreePlugin ) tells Qt that the class implements the ContextFreePlugin interface and generates the method
qt_metacast(char*) to cast the plugin object to ContextFreePlugin using the class name given as as character array.
Q_PLUGIN_METADATA()macro. The unique plugin name "ContextFreePlugin" is assigned. For Qt versions < 5.0,
Q_EXPORT_PLUGIN2has be be used (see Section 'ContextFreeExample.cpp' ).
The class ContextFreePluginExample has to implement all pure virtual methods from ContextFreePlugin.
For Qt versions < 5.0,
Q_EXPORT_PLUGIN2 is used to export the plugin. The first argument is a unique name for the plugin, the second the name of the plugin class.
opened(ContextFreeServices* service) is the starting point of our plugin. With
service->getWidget() we get a widget on Cube's main screen, in which we can place the GUI elements of our plugin. In this example, only one button will be placed on the main screen. Activation of this button will call the slot function
closed() is called if the plugin gets inactive because a cube file is loaded or the Cube GUI is closed. All resources which have been allocated in
opened() have to be deleted here.
This function is called, if the user clicks on the Button "Load cube file". Usually, a context free plugin will create cube data. In this small example, it simply loads the cube file which is choosen from a file dialog.
Each plugin has to set a version number. If several plugins with the same identifier (see function
name()) exist, the one with the highest version number will be loaded.
This function returns the unique plugin name. Only one plugin with this name will be loaded.
The following function returns a text to describe the plugin. It will be used by help menu of the cube GUI.
|Copyright © 1998–2015 Forschungszentrum Jülich, Jülich Supercomputing Centre|