[Kst] branches/work/kst/pluginify/kst/src

Adam Treat treat at kde.org
Tue Sep 19 22:28:38 CEST 2006


SVN commit 586506 by treat:

* Set the propertyString() directly via the desktop file
and throw an assert for necessary desktop file properties
if they are empty.
* Style fixes


 M  +49 -49    libkstmath/kstbasicplugin.h  
 M  +13 -0     libkstmath/kstdataobject.cpp  
 M  +22 -0     libkstmath/kstdataobject.h  
 M  +0 -2      plugins/linefit/linefit.h  
 M  +0 -2      plugins/testplugin/testplugin.h  


--- branches/work/kst/pluginify/kst/src/libkstmath/kstbasicplugin.h #586505:586506
@@ -22,69 +22,69 @@
 #include "kst_export.h"
 
 class KST_EXPORT KstBasicPlugin : public KstDataObject {
-public:
-  KstBasicPlugin();
-  KstBasicPlugin(const QDomElement &e);
-  virtual ~KstBasicPlugin();
+  public:
+    KstBasicPlugin();
+    KstBasicPlugin(const QDomElement &e);
+    virtual ~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;
+    //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;
+    //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;
 
-  //Pure virtual methods inherited from KstDataObject
-  //This _must_ equal the 'Name' entry in the .desktop file of
-  //the plugin
-  virtual QString propertyString() const = 0;
+    //Pure virtual methods inherited from KstDataObject
+    //This _must_ equal the 'Name' entry in the .desktop file of
+    //the plugin
+    QString propertyString() const { return name(); } //no longer virtual
 
-  //Provide an impl...
-  virtual KstDataObjectPtr makeDuplicate(KstDataObjectDataObjectMap&);
+    //Provide an impl...
+    virtual KstDataObjectPtr makeDuplicate(KstDataObjectDataObjectMap&);
 
   public slots:
-  //Pure virtual slots from KstDataObject
-  //Each plugin can provide an implementation or use the default
-  virtual void showNewDialog();
-  virtual void showEditDialog();
+    //Pure virtual slots from KstDataObject
+    //Each plugin can provide an implementation or use the default
+    virtual void showNewDialog();
+    virtual void showEditDialog();
 
   public:
-  //Returns the respective input object for name
-  KstVectorPtr inputVector(const QString& name) const;
-  KstScalarPtr inputScalar(const QString& name) const;
-  KstStringPtr inputString(const QString& name) const;
+    //Returns the respective input object for name
+    KstVectorPtr inputVector(const QString& name) const;
+    KstScalarPtr inputScalar(const QString& name) const;
+    KstStringPtr inputString(const QString& name) const;
 
-  //Returns the respective output object for name
-  KstVectorPtr outputVector(const QString& name) const;
-  KstScalarPtr outputScalar(const QString& name) const;
-  KstStringPtr outputString(const QString& name) const;
+    //Returns the respective output object for name
+    KstVectorPtr outputVector(const QString& name) const;
+    KstScalarPtr outputScalar(const QString& name) const;
+    KstStringPtr outputString(const QString& name) const;
 
-  void setInputVector(const QString &type, KstVectorPtr ptr);
-  void setInputScalar(const QString &type, KstScalarPtr ptr);
-  void setInputString(const QString &type, KstStringPtr ptr);
-  void setOutputVector(const QString &type, const QString &name);
-  void setOutputScalar(const QString &type, const QString &name);
-  void setOutputString(const QString &type, const QString &name);
+    void setInputVector(const QString &type, KstVectorPtr ptr);
+    void setInputScalar(const QString &type, KstScalarPtr ptr);
+    void setInputString(const QString &type, KstStringPtr ptr);
+    void setOutputVector(const QString &type, const QString &name);
+    void setOutputScalar(const QString &type, const QString &name);
+    void setOutputString(const QString &type, const QString &name);
 
-  //Pure virtual methods inherited from KstDataObject
-  //We do this one ourselves for benefit of all plugins...
-  KstObject::UpdateType update(int updateCounter = -1);
+    //Pure virtual methods inherited from KstDataObject
+    //We do this one ourselves for benefit of all plugins...
+    KstObject::UpdateType update(int updateCounter = -1);
 
-  //Regular virtual methods from KstDataObject
-  void load(const QDomElement &e);
-  void save(QTextStream& ts, const QString& indent = QString::null);
+    //Regular virtual methods from KstDataObject
+    void load(const QDomElement &e);
+    void save(QTextStream& ts, const QString& indent = QString::null);
 
   private:
-  bool inputsExist() const;
-  bool updateInput(int updateCounter, bool force) const;
-  void updateOutput(int updateCounter) const;
+    bool inputsExist() const;
+    bool updateInput(int updateCounter, bool force) const;
+    void updateOutput(int updateCounter) const;
 };
 
 typedef KstSharedPtr<KstBasicPlugin> KstBasicPluginPtr;
--- branches/work/kst/pluginify/kst/src/libkstmath/kstdataobject.cpp #586505:586506
@@ -103,6 +103,19 @@
       KParts::ComponentFactory::createInstanceFromService<KstDataObject>(service, 0, "",
       QStringList(), &err);
   if (object) {
+    const QString name = service->property("Name").toString();
+    const QString author = service->property("Author").toString();
+    const QString description = service->property("Comment").toString();
+    const QString version = service->property("X-Kst-Plugin-Version").toString();
+    const QString library = service->property("X-Kst-Plugin-Library").toString();
+    Q_ASSERT( !name.isEmpty() );
+    Q_ASSERT( !library.isEmpty() );
+    object->setName(name);
+    object->setAuthor(author);
+    object->setDescription(description);
+    object->setVersion(version);
+    object->setLibrary(library);
+
     KstDebug::self()->log(i18n("Loaded data-object plugin %1.").arg(service->name()));
   }
   else {
--- branches/work/kst/pluginify/kst/src/libkstmath/kstdataobject.h #586505:586506
@@ -105,6 +105,13 @@
 
     virtual bool uses(KstObjectPtr p) const;
 
+    //These are generally only valid for plugins...
+    QString name() const { return _name; }
+    QString author() const { return _author; }
+    QString description() const { return _description; }
+    QString version() const { return _version; }
+    QString library() const { return _library; }
+
   protected slots:
     virtual void showNewDialog() = 0;
     virtual void showEditDialog() = 0;
@@ -113,6 +120,14 @@
     
     double *vectorRealloced(KstVectorPtr v, double *memptr, int newSize) const;
 
+    //The plugin infrastructure will read the desktop file and set these
+    //Other objects that inherit can set the ones that apply if desired...
+    void setName(const QString &str) { _name = str; }
+    void setAuthor(const QString &str) { _author = str; }
+    void setDescription(const QString &str) { _description = str; }
+    void setVersion(const QString &str) { _version = str; }
+    void setLibrary(const QString &str) { _library = str; }
+
     KstVectorMap _inputVectors;
     KstVectorMap _outputVectors;
     KstScalarMap _inputScalars;
@@ -131,6 +146,13 @@
     KstCurveHintList *_curveHints;
 
   private:
+    QString _name;
+    QString _author;
+    QString _description;
+    QString _version;
+    QString _library;
+
+  private:
     static void scanPlugins();
     static KstDataObjectPtr createPlugin( KService::Ptr );
 };
--- branches/work/kst/pluginify/kst/src/plugins/linefit/linefit.h #586505:586506
@@ -35,8 +35,6 @@
   virtual QStringList outputVectorList() const;
   virtual QStringList outputScalarList() const;
   virtual QStringList outputStringList() const;
-
-  virtual QString propertyString() const { return "Line Fit"; }
 };
 
 #endif
--- branches/work/kst/pluginify/kst/src/plugins/testplugin/testplugin.h #586505:586506
@@ -33,8 +33,6 @@
     virtual QStringList outputVectorList() const;
     virtual QStringList outputScalarList() const;
     virtual QStringList outputStringList() const;
-
-    virtual QString propertyString() const { return "Test Plugin"; }
 };
 
 #endif


More information about the Kst mailing list