File indexing completed on 2024-12-22 04:17:53

0001 /***************************************************************************
0002                    dataobject.h: base class for data objects
0003                              -------------------
0004     begin                : May 20, 2003
0005     copyright            : (C) 2003 by C. Barth Netterfield
0006     email                : netterfield@astro.utoronto.ca
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #ifndef DATAOBJECT_H
0019 #define DATAOBJECT_H
0020 
0021 #include "curvehint.h"
0022 #include "string_kst.h"
0023 #include "object.h"
0024 #include "objectlist.h"
0025 #include "vector.h"
0026 #include "matrix.h"
0027 #include "kstmath_export.h"
0028 
0029 #include <QWidget>
0030 #include <QSettings>
0031 
0032 class QXmlStreamReader;
0033 class QXmlStreamWriter;
0034 
0035 namespace Kst {
0036 
0037 class DataObject;
0038 class Relation;
0039 class DataObjectConfigWidget;
0040 
0041 typedef SharedPtr<DataObject> DataObjectPtr;
0042 typedef ObjectList<DataObject> DataObjectList;
0043 typedef QMap<DataObjectPtr, DataObjectPtr> DataObjectDataObjectMap;
0044 
0045 class KSTMATH_EXPORT DataObject : public Object
0046 {
0047     Q_OBJECT
0048 
0049   public:
0050     //enum Kind { GenericPlugin, PrimitivePlugin, FitPlugin, FilterPlugin };
0051 
0052     virtual void attach();
0053 
0054     // These static methods are not for plugins to use
0055     static void init();
0056     static void cleanupForExit();
0057     static void initPlugins();
0058     /** Returns a list of object plugins found on the system. */
0059     static QStringList pluginList();
0060     static QStringList dataObjectPluginList();
0061     static QStringList filterPluginList();
0062     static QStringList fitsPluginList();
0063 
0064     //     static QWidget* pluginWidget(const QString& name, ObjectPtr objectPtr = 0, VectorPtr vector = 0);
0065     static DataObjectPtr createPlugin(const QString& name, ObjectStore *store, VectorPtr vector);
0066     static DataObjectConfigWidget* pluginWidget(const QString& name);
0067     static DataObjectPtr createPlugin(const QString& name, ObjectStore *store, DataObjectConfigWidget *configWidget, bool setupInputsOutputs = true);
0068     static QString pluginDescription(const QString &name);
0069     static int pluginType(const QString &name);
0070 
0071     virtual const QString& typeString() const { return _typeString; }
0072     virtual QString propertyString() const = 0;
0073     virtual const QString& type() const { return _type; }
0074 
0075     virtual int sampleCount() const { return 0; }
0076 
0077     // If you use these, you must lock() and unlock() the object as long as you
0078     // hold the reference
0079     const VectorMap& inputVectors()  const { return _inputVectors;  }
0080     const VectorMap& outputVectors() const { return _outputVectors; }
0081     VectorMap& inputVectors() { return _inputVectors;  }
0082     VectorMap& outputVectors() { return _outputVectors; }
0083 
0084     const ScalarMap& inputScalars()  const { return _inputScalars;  }
0085     const ScalarMap& outputScalars() const { return _outputScalars; }
0086     ScalarMap& inputScalars() { return _inputScalars;  }
0087     ScalarMap& outputScalars() { return _outputScalars; }
0088 
0089     const StringMap& inputStrings()  const { return _inputStrings;  }
0090     const StringMap& outputStrings() const { return _outputStrings; }
0091     StringMap& inputStrings() { return _inputStrings;  }
0092     StringMap& outputStrings() { return _outputStrings; }
0093 
0094     const MatrixMap& inputMatrices() const { return _inputMatrices; }
0095     const MatrixMap& outputMatrices() const { return _outputMatrices; }
0096     MatrixMap& inputMatrices() { return _inputMatrices; }
0097     MatrixMap& outputMatrices() { return _outputMatrices; }
0098 
0099     VectorPtr outputVector(const QString& name) const;
0100     ScalarPtr outputScalar(const QString& name) const;
0101     StringPtr outputString(const QString& name) const;
0102 
0103     void setInputVector(const QString &type, VectorPtr ptr);
0104     void setInputScalar(const QString &type, ScalarPtr ptr);
0105     void setInputString(const QString &type, StringPtr ptr);
0106 
0107     virtual PrimitiveList inputPrimitives() const;
0108     PrimitiveList outputPrimitives(bool include_descendants = true) const;
0109 
0110     virtual void load(const QXmlStreamReader& s);
0111     virtual void save(QXmlStreamWriter& s);
0112 
0113     virtual int getUsage() const;
0114 
0115     virtual void readLock() const;
0116     virtual void writeLock() const;
0117     virtual void unlock() const;
0118 
0119     virtual bool isValid();
0120 
0121     virtual const CurveHintList* curveHints() const;
0122 
0123     virtual void deleteDependents();
0124 
0125     virtual DataObjectPtr makeDuplicate() const = 0;
0126 
0127     virtual void replaceInput(PrimitivePtr p, PrimitivePtr new_p);
0128 
0129     virtual bool uses(ObjectPtr p) const;
0130 
0131     //These are generally only valid for plugins...
0132     const QString& name() const { return _name; }
0133     const QString& author() const { return _author; }
0134     const QString& description() const { return _description; }
0135     const QString& version() const { return _version; }
0136     const QString& library() const { return _library; }
0137 
0138     void showDialog(bool isNew = true);
0139 
0140     // used for sorting dataobjects by Document::sortedDataObjectList()
0141     void setOutputFlags(bool flag);
0142     bool inputFlagsSet() const;
0143 
0144     // this is reimplemented but must not be virtual.
0145     QByteArray scriptInterface(QList<QByteArray>&command);
0146 
0147 
0148   protected slots:
0149     virtual void showNewDialog() = 0;
0150     virtual void showEditDialog() = 0;
0151 
0152   protected:
0153     DataObject(ObjectStore *store);
0154     virtual ~DataObject();
0155 
0156 //    double *vectorRealloced(VectorPtr v, double *memptr, int newSize) const;
0157 
0158     //The plugin infrastructure will read the desktop file and set these
0159     //Other objects that inherit can set the ones that apply if desired...
0160     void setName(const QString& str) { _name = str; }
0161     void setAuthor(const QString& str) { _author = str; }
0162     void setDescription(const QString& str) { _description = str; }
0163     void setVersion(const QString& str) { _version = str; }
0164     void setLibrary(const QString& str) { _library = str; }
0165 
0166     virtual void writeLockInputsAndOutputs() const;
0167     virtual void unlockInputsAndOutputs() const;
0168 
0169     VectorMap _inputVectors;
0170     VectorMap _outputVectors;
0171     ScalarMap _inputScalars;
0172     ScalarMap _outputScalars;
0173     StringMap _inputStrings;
0174     StringMap _outputStrings;
0175     MatrixMap _inputMatrices;
0176     MatrixMap _outputMatrices;
0177 
0178     QString _typeString, _type;
0179 
0180     CurveHintList *_curveHints;
0181 
0182     virtual qint64 minInputSerial() const;
0183     virtual qint64 maxInputSerialOfLastChange() const;
0184 
0185   private:
0186     QString _name;
0187     QString _author;
0188     QString _description;
0189     QString _version;
0190     QString _library;
0191 
0192   private:
0193     static QSettings& settingsObject();
0194     static QMap<QString,QString> url_map;
0195     static void scanPlugins();
0196 };
0197 
0198 
0199 class KSTMATH_EXPORT DataObjectConfigWidget : public QWidget
0200 {
0201     Q_OBJECT
0202 
0203   public:
0204     explicit DataObjectConfigWidget(QSettings*); // will be reparented later
0205     virtual ~DataObjectConfigWidget();
0206 
0207     virtual void setupFromObject(Object* dataObject);
0208     virtual void setupSlots(QWidget* dialog);
0209 
0210     virtual void setVectorX(VectorPtr vector);
0211     virtual void setVectorY(VectorPtr vector);
0212     virtual void setVectorsLocked(bool locked = true);
0213 
0214     virtual bool configurePropertiesFromXml(ObjectStore *store, QXmlStreamAttributes& attrs);
0215 
0216     void setInstance(DataObjectPtr inst);
0217     DataObjectPtr instance() const;
0218 
0219     virtual void setObjectStore(ObjectStore* store);
0220 
0221   public slots:
0222     virtual void load();
0223     virtual void save();
0224 
0225   protected:
0226     QSettings *_cfg;
0227 
0228   private:
0229     friend class DataObject;
0230 };
0231 
0232 
0233 }
0234 
0235 Q_DECLARE_METATYPE(Kst::DataObject*)
0236 
0237 #endif
0238 // vim: ts=2 sw=2 et