1 /*************************************************************************** 2 * * 3 * copyright : (C) 2006 The University of Toronto * 4 * netterfield@astro.utoronto.ca * 5 * * 6 * This program is free software; you can redistribute it and/or modify * 7 * it under the terms of the GNU General Public License as published by * 8 * the Free Software Foundation; either version 2 of the License, or * 9 * (at your option) any later version. * 10 * * 11 ***************************************************************************/ 12 13 #ifndef BASICPLUGIN_H 14 #define BASICPLUGIN_H 15 16 #include "dataobject.h" 17 #include "kstmath_export.h" 18 19 namespace Kst { 20 21 class ObjectStore; 22 23 class KSTMATH_EXPORT BasicPlugin : public DataObject { 24 Q_OBJECT 25 26 public: 27 static const QString staticTypeString; typeString()28 const QString& typeString() const { return staticTypeString; } 29 static const QString staticTypeTag; 30 31 //The implementation of the algorithm the plugin provides. 32 //Operates on the inputVectors, inputScalars, and inputStrings 33 //to produce the outputVectors, outputScalars, and outputStrings. 34 virtual bool algorithm() = 0; 35 36 //String lists of the names of the expected inputs. 37 virtual QStringList inputVectorList() const = 0; 38 virtual QStringList inputScalarList() const = 0; 39 virtual QStringList inputStringList() const = 0; 40 //String lists of the names of the expected outputs. 41 virtual QStringList outputVectorList() const = 0; 42 virtual QStringList outputScalarList() const = 0; 43 virtual QStringList outputStringList() const = 0; 44 45 //Pure virtual methods inherited from DataObject 46 //This _must_ equal the 'Name' entry in the .desktop file of 47 //the plugin propertyString()48 QString propertyString() const { return name(); } //no longer virtual 49 50 //Provide an impl... 51 virtual DataObjectPtr makeDuplicate() const; 52 53 virtual QString descriptionTip() const; 54 55 // Validator of plugin data. Expensive, only use to verify successful creation. isValid()56 virtual bool isValid() { return (inputsExist() && algorithm()); } errorMessage()57 QString errorMessage() { return _errorString; } 58 59 public slots: 60 //Pure virtual slots from DataObject 61 //Each plugin can provide an implementation or use the default 62 virtual void showNewDialog(); 63 virtual void showEditDialog(); 64 65 public: 66 virtual void change(DataObjectConfigWidget *configWidget) = 0; 67 68 //Returns the respective input object for name 69 VectorPtr inputVector(const QString& name) const; 70 ScalarPtr inputScalar(const QString& name) const; 71 StringPtr inputString(const QString& name) const; 72 73 void setOutputVector(const QString &type, const QString &name); 74 void setOutputScalar(const QString &type, const QString &name); 75 void setOutputString(const QString &type, const QString &name); 76 77 // for setting non primitive properties setProperty(const QString & key,const QString & val)78 virtual void setProperty(const QString &key, const QString &val) {Q_UNUSED(key) Q_UNUSED(val);} 79 80 void setPluginName(const QString &pluginName); pluginName()81 QString pluginName() { return _pluginName; } 82 83 //Regular virtual methods from DataObject 84 virtual void save(QXmlStreamWriter &s); 85 virtual void saveProperties(QXmlStreamWriter &s); 86 87 void createScalars(); 88 QString label(int precision) const; 89 90 virtual void internalUpdate(); hasParameterVector()91 virtual bool hasParameterVector() const { return _outputVectors.contains("Parameters Vector");} parameterVectorToString()92 virtual QString parameterVectorToString() const { return label(9);} 93 94 virtual ScriptInterface* createScriptInterface(); 95 96 protected: 97 BasicPlugin(ObjectStore *store); 98 virtual ~BasicPlugin(); 99 100 //Pure virtual methods inherited from DataObject 101 //We do this one ourselves for benefit of all plugins... 102 103 virtual QString parameterName(int index) const; 104 QString _errorString; 105 virtual void _initializeShortName(); 106 private: 107 bool inputsExist() const; 108 void updateOutput() const; 109 110 QString _pluginName; 111 }; 112 113 typedef SharedPtr<BasicPlugin> BasicPluginPtr; 114 typedef ObjectList<BasicPlugin> BasicPluginList; 115 116 } 117 118 #endif 119 120 // vim: ts=2 sw=2 et 121