File indexing completed on 2025-07-06 04:09:53
0001 /*************************************************************************** 0002 * * 0003 * copyright : (C) 2006 The University of Toronto * 0004 * netterfield@astro.utoronto.ca * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 ***************************************************************************/ 0012 0013 #ifndef BASICPLUGIN_H 0014 #define BASICPLUGIN_H 0015 0016 #include "dataobject.h" 0017 #include "kstmath_export.h" 0018 0019 namespace Kst { 0020 0021 class ObjectStore; 0022 0023 class KSTMATH_EXPORT BasicPlugin : public DataObject { 0024 Q_OBJECT 0025 0026 public: 0027 static const QString staticTypeString; 0028 const QString& typeString() const { return staticTypeString; } 0029 static const QString staticTypeTag; 0030 0031 //The implementation of the algorithm the plugin provides. 0032 //Operates on the inputVectors, inputScalars, and inputStrings 0033 //to produce the outputVectors, outputScalars, and outputStrings. 0034 virtual bool algorithm() = 0; 0035 0036 //String lists of the names of the expected inputs. 0037 virtual QStringList inputVectorList() const = 0; 0038 virtual QStringList inputScalarList() const = 0; 0039 virtual QStringList inputStringList() const = 0; 0040 //String lists of the names of the expected outputs. 0041 virtual QStringList outputVectorList() const = 0; 0042 virtual QStringList outputScalarList() const = 0; 0043 virtual QStringList outputStringList() const = 0; 0044 0045 //Pure virtual methods inherited from DataObject 0046 //This _must_ equal the 'Name' entry in the .desktop file of 0047 //the plugin 0048 QString propertyString() const { return name(); } //no longer virtual 0049 0050 //Provide an impl... 0051 virtual DataObjectPtr makeDuplicate() const; 0052 0053 virtual QString descriptionTip() const; 0054 0055 // Validator of plugin data. Expensive, only use to verify successful creation. 0056 virtual bool isValid() { return (inputsExist() && algorithm()); } 0057 QString errorMessage() { return _errorString; } 0058 0059 public slots: 0060 //Pure virtual slots from DataObject 0061 //Each plugin can provide an implementation or use the default 0062 virtual void showNewDialog(); 0063 virtual void showEditDialog(); 0064 0065 public: 0066 virtual void change(DataObjectConfigWidget *configWidget) = 0; 0067 0068 //Returns the respective input object for name 0069 VectorPtr inputVector(const QString& name) const; 0070 ScalarPtr inputScalar(const QString& name) const; 0071 StringPtr inputString(const QString& name) const; 0072 0073 void setOutputVector(const QString &type, const QString &name); 0074 void setOutputScalar(const QString &type, const QString &name); 0075 void setOutputString(const QString &type, const QString &name); 0076 0077 // for setting non primitive properties 0078 virtual void setProperty(const QString &key, const QString &val) {Q_UNUSED(key) Q_UNUSED(val);} 0079 0080 void setPluginName(const QString &pluginName); 0081 QString pluginName() { return _pluginName; } 0082 0083 //Regular virtual methods from DataObject 0084 virtual void save(QXmlStreamWriter &s); 0085 virtual void saveProperties(QXmlStreamWriter &s); 0086 0087 void createScalars(); 0088 QString label(int precision) const; 0089 0090 virtual void internalUpdate(); 0091 virtual bool hasParameterVector() const { return _outputVectors.contains("Parameters Vector");} 0092 virtual QString parameterVectorToString() const { return label(9);} 0093 0094 virtual ScriptInterface* createScriptInterface(); 0095 0096 protected: 0097 BasicPlugin(ObjectStore *store); 0098 virtual ~BasicPlugin(); 0099 0100 //Pure virtual methods inherited from DataObject 0101 //We do this one ourselves for benefit of all plugins... 0102 0103 virtual QString parameterName(int index) const; 0104 QString _errorString; 0105 virtual void _initializeShortName(); 0106 private: 0107 bool inputsExist() const; 0108 void updateOutput() const; 0109 0110 QString _pluginName; 0111 }; 0112 0113 typedef SharedPtr<BasicPlugin> BasicPluginPtr; 0114 typedef ObjectList<BasicPlugin> BasicPluginList; 0115 0116 } 0117 0118 #endif 0119 0120 // vim: ts=2 sw=2 et