Warning, /graphics/kst-plot/devel-docs/plugins/KstBasicPlugins is written in an unsupported language. File is not indexed.

0001 KstBasicPlugin Plugins
0002 ----------------------
0003 
0004 The purpose of a KstBasicPlugin plugin is to provide an implementation of the
0005 virtual class "KstDataObject" via the abstract class "KstBasicPlugin."  Plugin
0006 writers need to provide a class that inherits "KstBasicPlugin" and a .desktop
0007 file.
0008 
0009 Here is an example of the .desktop file named 'kstobject_myplugin.desktop':
0010 
0011     [Desktop Entry]
0012     Encoding=UTF-8
0013     Type=Service
0014     ServiceTypes=Kst Data Object
0015     X-KDE-ModuleType=Plugin
0016     X-KDE-Library=kstobject_fooplugin
0017     X-Kst-Plugin-Author=Your Name
0018     X-Kst-Plugin-Version=0.1
0019     Name=Foo
0020     Comment=A plugin that provides Foo algorithm.
0021 
0022 Your C++ class should inherit KstBasicPlugin and provide implementations of the
0023 pure virtual methods found in KstBasicPlugin:
0024 
0025     //The implementation of the algorithm the plugin provides.
0026     //Operates on the inputVectors, inputScalars, and inputStrings
0027     //to produce the outputVectors, outputScalars, and outputStrings.
0028     virtual bool algorithm() = 0;
0029 
0030     //String lists of the names of the expected inputs.
0031     virtual QStringList inputVectorList() const = 0;
0032     virtual QStringList inputScalarList() const = 0;
0033     virtual QStringList inputStringList() const = 0;
0034 
0035     //String lists of the names of the expected outputs.
0036     virtual QStringList outputVectorList() const = 0;
0037     virtual QStringList outputScalarList() const = 0;
0038     virtual QStringList outputStringList() const = 0;
0039 
0040 Here is an example of a plugins header file:
0041 
0042 #ifndef FOOPLUGIN_H
0043 #define FOOPLUGIN_H
0044 
0045 #include <kstbasicplugin.h>
0046 
0047 class FooPlugin : public KstBasicPlugin {
0048   Q_OBJECT
0049   public:
0050     FooPlugin(QObject *parent, const char *name, const QStringList &args);
0051     virtual ~FooPlugin();
0052 
0053     virtual bool algorithm();
0054 
0055     virtual QStringList inputVectorList() const;
0056     virtual QStringList inputScalarList() const;
0057     virtual QStringList inputStringList() const;
0058     virtual QStringList outputVectorList() const;
0059     virtual QStringList outputScalarList() const;
0060     virtual QStringList outputStringList() const;
0061 };
0062 
0063 And here is an example of a plugins cpp file:
0064 
0065 #include "fooplugin.h"
0066 
0067 #include <kgenericfactory.h>
0068 
0069 static const QString& VECTOR_IN = KGlobal::staticQString("Vector In");
0070 static const QString& SCALAR_IN = KGlobal::staticQString("Scalar In");
0071 static const QString& STRING_IN = KGlobal::staticQString("String In");
0072 static const QString& VECTOR_OUT = KGlobal::staticQString("Vector Out");
0073 static const QString& SCALAR_OUT = KGlobal::staticQString("Scalar Out");
0074 static const QString& STRING_OUT = KGlobal::staticQString("String Out");
0075 
0076 K_EXPORT_COMPONENT_FACTORY( kstobject_fooplugin,
0077     KGenericFactory<FooPlugin>( "kstobject_fooplugin" ) )
0078 
0079 FooPlugin::FooPlugin( QObject */*parent*/, const char */*name*/, const QStringList &/*args*/ )
0080     : KstBasicPlugin() {
0081 }
0082 
0083 
0084 FooPlugin::~FooPlugin() {
0085 }
0086 
0087 
0088 bool FooPlugin::algorithm() {
0089   //Do something...
0090   return true;
0091 }
0092 
0093 
0094 QStringList FooPlugin::inputVectorList() const {
0095   return QStringList( VECTOR_IN );
0096 }
0097 
0098 
0099 QStringList FooPlugin::inputScalarList() const {
0100   return QStringList( SCALAR_IN );
0101 }
0102 
0103 
0104 QStringList FooPlugin::inputStringList() const {
0105   return QStringList( STRING_IN );
0106 }
0107 
0108 
0109 QStringList FooPlugin::outputVectorList() const {
0110   return QStringList( VECTOR_OUT );
0111 }
0112 
0113 
0114 QStringList FooPlugin::outputScalarList() const {
0115   return QStringList( SCALAR_OUT );
0116 }
0117 
0118 
0119 QStringList FooPlugin::outputStringList() const {
0120   return QStringList( STRING_OUT );
0121 }
0122 
0123 #include "fooplugin.moc"
0124 
0125 The KstBasicPlugin takes care of providing almost everything, including the
0126 configuration widget for your plugin.  The one thing it doesn't do is provide
0127 the actual algorithm or the names of the inputs/outputs.
0128 
0129 See the Line Fit plugin for an example implementation.