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

0001 /***************************************************************************
0002                           datastprimitive.h  -  add datasource handling
0003                           capability to a primitive
0004                              -------------------
0005     begin                : October, 2009
0006     copyright            : (C) 2009 by cbn
0007     email                : netterfield@astro.utoronto.ca
0008  ***************************************************************************/
0009 
0010 /***************************************************************************
0011  *                                                                         *
0012  *   This program is free software; you can redistribute it and/or modify  *
0013  *   it under the terms of the GNU General Public License as published by  *
0014  *   the Free Software Foundation; either version 2 of the License, or     *
0015  *   (at your option) any later version.                                   *
0016  *                                                                         *
0017  ***************************************************************************/
0018 
0019 
0020 #ifndef DATAPRIMITIVE_H
0021 #define DATAPRIMITIVE_H
0022 
0023 #include "sharedptr.h"
0024 #include "kst_export.h"
0025 
0026 #include <QString>
0027 
0028 class QXmlStreamWriter;
0029 class QXmlStreamAttributes;
0030 
0031 namespace Kst {
0032 
0033 class DataSource;
0034 typedef SharedPtr<DataSource> DataSourcePtr;
0035 
0036 class Primitive;
0037 typedef SharedPtr<Primitive> PrimitivePtr;
0038 
0039 class KSTCORE_EXPORT DataPrimitive
0040 {
0041 public:    
0042     virtual ~DataPrimitive();
0043 
0044     /** return the name of the file */
0045     QString filename() const;
0046 
0047     /** save filename to xml stream */
0048     void saveFilename(QXmlStreamWriter&);
0049     static void saveFilename(const QString&, QXmlStreamWriter&);
0050 
0051     static QString readFilename(const QXmlStreamAttributes&);
0052 
0053 
0054     /** return the field name */
0055     const QString& field() const;
0056 
0057     /** the data source */
0058     DataSourcePtr dataSource() const;
0059     void setDataSource(const DataSourcePtr&);
0060 
0061     /** change the datasource */
0062     virtual void changeFile(DataSourcePtr file);
0063 
0064     /** return true if it has a valid file and field, or false otherwise */
0065     //virtual bool isValid() const = 0;
0066 
0067     /** file to read */
0068     QString _field;    
0069 
0070     virtual PrimitivePtr makeDuplicate() const = 0;
0071 
0072     virtual bool checkValidity(const DataSourcePtr& ds) const = 0;
0073 
0074     /** Return field used for generalized lookup */
0075     QString startUnits() {return _startUnits;}
0076     void setStartUnits(const QString &field) {_startUnits = field;}
0077     QString rangeUnits() {return _rangeUnits;}
0078     void setRangeUnits(const QString &field) {_rangeUnits = field;}
0079 
0080 
0081   protected:
0082     DataPrimitive(Primitive* primitive);
0083 
0084   private:
0085     DataPrimitive();
0086     struct Private;
0087     Private& d;
0088 
0089     /** generalized index field - empty if we are using frames. */
0090     QString _startUnits;
0091     QString _rangeUnits;
0092 
0093 
0094 };
0095 
0096 }
0097 
0098 Q_DECLARE_INTERFACE(Kst::DataPrimitive, "DataPrimitive")
0099 
0100 #endif // DATAPRIMITIVE_H