1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
KstBasicPlugin Plugins
----------------------
The purpose of a KstBasicPlugin plugin is to provide an implementation of the
virtual class "KstDataObject" via the abstract class "KstBasicPlugin." Plugin
writers need to provide a class that inherits "KstBasicPlugin" and a .desktop
file.
Here is an example of the .desktop file named 'kstobject_myplugin.desktop':
[Desktop Entry]
Encoding=UTF-8
Type=Service
ServiceTypes=Kst Data Object
X-KDE-ModuleType=Plugin
X-KDE-Library=kstobject_fooplugin
X-Kst-Plugin-Author=Your Name
X-Kst-Plugin-Version=0.1
Name=Foo
Comment=A plugin that provides Foo algorithm.
Your C++ class should inherit KstBasicPlugin and provide implementations of the
pure virtual methods found in KstBasicPlugin:
//The implementation of the algorithm the plugin provides.
//Operates on the inputVectors, inputScalars, and inputStrings
//to produce the outputVectors, outputScalars, and outputStrings.
virtual bool algorithm() = 0;
//String lists of the names of the expected inputs.
virtual QStringList inputVectorList() const = 0;
virtual QStringList inputScalarList() const = 0;
virtual QStringList inputStringList() const = 0;
//String lists of the names of the expected outputs.
virtual QStringList outputVectorList() const = 0;
virtual QStringList outputScalarList() const = 0;
virtual QStringList outputStringList() const = 0;
Here is an example of a plugins header file:
#ifndef FOOPLUGIN_H
#define FOOPLUGIN_H
#include <kstbasicplugin.h>
class FooPlugin : public KstBasicPlugin {
Q_OBJECT
public:
FooPlugin(QObject *parent, const char *name, const QStringList &args);
virtual ~FooPlugin();
virtual bool algorithm();
virtual QStringList inputVectorList() const;
virtual QStringList inputScalarList() const;
virtual QStringList inputStringList() const;
virtual QStringList outputVectorList() const;
virtual QStringList outputScalarList() const;
virtual QStringList outputStringList() const;
};
And here is an example of a plugins cpp file:
#include "fooplugin.h"
#include <kgenericfactory.h>
static const QString& VECTOR_IN = KGlobal::staticQString("Vector In");
static const QString& SCALAR_IN = KGlobal::staticQString("Scalar In");
static const QString& STRING_IN = KGlobal::staticQString("String In");
static const QString& VECTOR_OUT = KGlobal::staticQString("Vector Out");
static const QString& SCALAR_OUT = KGlobal::staticQString("Scalar Out");
static const QString& STRING_OUT = KGlobal::staticQString("String Out");
K_EXPORT_COMPONENT_FACTORY( kstobject_fooplugin,
KGenericFactory<FooPlugin>( "kstobject_fooplugin" ) )
FooPlugin::FooPlugin( QObject */*parent*/, const char */*name*/, const QStringList &/*args*/ )
: KstBasicPlugin() {
}
FooPlugin::~FooPlugin() {
}
bool FooPlugin::algorithm() {
//Do something...
return true;
}
QStringList FooPlugin::inputVectorList() const {
return QStringList( VECTOR_IN );
}
QStringList FooPlugin::inputScalarList() const {
return QStringList( SCALAR_IN );
}
QStringList FooPlugin::inputStringList() const {
return QStringList( STRING_IN );
}
QStringList FooPlugin::outputVectorList() const {
return QStringList( VECTOR_OUT );
}
QStringList FooPlugin::outputScalarList() const {
return QStringList( SCALAR_OUT );
}
QStringList FooPlugin::outputStringList() const {
return QStringList( STRING_OUT );
}
#include "fooplugin.moc"
The KstBasicPlugin takes care of providing almost everything, including the
configuration widget for your plugin. The one thing it doesn't do is provide
the actual algorithm or the names of the inputs/outputs.
See the Line Fit plugin for an example implementation.
|