[Kst] branches/work/kst/portto4/kst/src/datasources

Mike Fenton mike at staikos.net
Thu Sep 27 20:25:26 CEST 2007


SVN commit 717919 by fenton:

Port of dirfile and inclusion in build.


 M  +2 -2      datasources.pro  
 M  +116 -27   dirfile/dirfile.cpp  
 M  +52 -3     dirfile/dirfile.h  
 A             dirfile/dirfile.pro  


--- branches/work/kst/portto4/kst/src/datasources/datasources.pro #717918:717919
@@ -2,9 +2,9 @@
 CONFIG += ordered
 
 SUBDIRS += \
-    ascii
+    ascii \
+    dirfile
 #     cdf \
-#     dirfile \
 #     fitsimage \
 #     frame \
 #     healpix \
--- branches/work/kst/portto4/kst/src/datasources/dirfile/dirfile.cpp #717918:717919
@@ -20,14 +20,48 @@
 #include "getdata_struct.h"
 
 
-DirFileSource::DirFileSource(KConfig *cfg, const QString& filename, const QString& type)
-: KstDataSource(cfg, filename, type) {
-  if (init()) {
-    _valid = true;
+class DirFileSource::Config {
+  public:
+    Config() {
+    }
+
+    void read(QSettings *cfg, const QString& fileName = QString::null) {
+      Q_UNUSED(fileName);
+      cfg->beginGroup("Directory of Binary Files");
+      cfg->endGroup();
+    }
+
+    void save(QXmlStreamWriter& s) {
+      Q_UNUSED(s);
+    }
+
+    void load(const QDomElement& e) {
+      Q_UNUSED(e);
+    }
+};
+
+
+DirFileSource::DirFileSource(QSettings *cfg, const QString& filename, const QString& type, const QDomElement& e)
+: KstDataSource(cfg, filename, type), _rowIndex(0L), _config(0L), _tmpBuf(0L), _tmpBufSize(0) {
+  _valid = false;
+  _haveHeader = false;
+  _fieldListComplete = false;
+  if (!type.isEmpty() && type != "Directory of Binary Files") {
+    return;
   }
+
+  _config = new DirFileSource::Config;
+  _config->read(cfg, filename);
+  if (!e.isNull()) {
+    _config->load(e);
+  }
+
+  _valid = true;
+  update();
 }
 
 
+
 DirFileSource::~DirFileSource() {
 }
 
@@ -152,38 +186,52 @@
 }
 
 
-void DirFileSource::save(QTextStream &ts, const QString& indent) {
-  KstDataSource::save(ts, indent);
+void DirFileSource::save(QXmlStreamWriter &streamWriter) {
+  KstDataSource::save(streamWriter);
 }
 
-//#include <kdebug.h>
 
-extern "C" {
-KstDataSource *create_dirfile(KConfig *cfg, const QString& filename, const QString& type) {
-  return new DirFileSource(cfg, filename, type);
-}
+QString DirFilePlugin::pluginName() const { return "DirFile Reader"; }
 
-QStringList provides_dirfile() {
-  QStringList rc;
-  rc += "Directory of Binary Files";
-  return rc;
+
+KstDataSource *DirFilePlugin::create(QSettings *cfg,
+                                            const QString &filename,
+                                            const QString &type,
+                                            const QDomElement &element) const {
+
+  return new DirFileSource(cfg, filename, type, element);
 }
 
-int understands_dirfile(KConfig*, const QString& filename) {
-  // FIXME: GetNFrames causes a memory error here.  I think it is due to
-  // the lfilename parameter.
-  int err = 0;
-  int frameCount = GetNFrames(filename.toLatin1(), &err, 0L);
-  if (frameCount > 0 && err == GD_E_OK) {
-    return 98;
+
+
+QStringList DirFilePlugin::matrixList(QSettings *cfg,
+                                             const QString& filename,
+                                             const QString& type,
+                                             QString *typeSuggestion,
+                                             bool *complete) const {
+
+
+  if (typeSuggestion) {
+    *typeSuggestion = "Directory of Binary Files";
   }
-
-  //kdDebug() << "Don't understand.  filename = [" << filename << "] FrameCount=" << frameCount << " err=" << err << endl;
-  return 0;
+  if ((!type.isEmpty() && !provides().contains(type)) ||
+      0 == understands(cfg, filename)) {
+    if (complete) {
+      *complete = false;
+    }
+    return QStringList();
+  }
+  return QStringList();
 }
 
 
-QStringList fieldList_dirfile(KConfig*, const QString& filename, const QString& type, QString *typeSuggestion, bool *complete) {
+QStringList DirFilePlugin::fieldList(QSettings *cfg,
+                                            const QString& filename,
+                                            const QString& type,
+                                            QString *typeSuggestion,
+                                            bool *complete) const {
+
+  Q_UNUSED(cfg);
   Q_UNUSED(type)
   int err = 0;
   struct FormatType *ft = GetFormat(filename.toLatin1(), &err);
@@ -224,10 +272,51 @@
     }
   }
   return fieldList;
+
 }
 
+
+
+int DirFilePlugin::understands(QSettings *cfg, const QString& filename) const {
+  // FIXME: GetNFrames causes a memory error here.  I think it is due to
+  // the lfilename parameter.
+  Q_UNUSED(cfg);
+  int err = 0;
+  int frameCount = GetNFrames(filename.toLatin1(), &err, 0L);
+  if (frameCount > 0 && err == GD_E_OK) {
+    return 98;
+  }
+
+  //kdDebug() << "Don't understand.  filename = [" << filename << "] FrameCount=" << frameCount << " err=" << err << endl;
+  return 0;
 }
 
-KST_KEY_DATASOURCE_PLUGIN(dirfile)
 
+
+bool DirFilePlugin::supportsTime(QSettings *cfg, const QString& filename) const {
+  //FIXME
+  Q_UNUSED(cfg)
+  Q_UNUSED(filename)
+  return true;
+}
+
+
+QStringList DirFilePlugin::provides() const {
+  QStringList rc;
+  rc += "Directory of Binary Files";
+  return rc;
+}
+
+
+KstDataSourceConfigWidget *DirFilePlugin::configWidget(QSettings *cfg, const QString& filename) const {
+
+  Q_UNUSED(cfg)
+  Q_UNUSED(filename)
+  return 0;;
+
+}
+
+Q_EXPORT_PLUGIN2(kstdata_dirfile, DirFilePlugin)
+
+
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/datasources/dirfile/dirfile.h #717918:717919
@@ -19,11 +19,11 @@
 #define DIRFILE_H
 
 #include <kstdatasource.h>
+#include <kstdataplugin.h>
 
-
 class DirFileSource : public KstDataSource {
   public:
-    DirFileSource(KConfig *cfg, const QString& filename, const QString& type);
+    DirFileSource(QSettings *cfg, const QString& filename, const QString& type, const QDomElement& e);
 
     ~DirFileSource();
 
@@ -43,16 +43,65 @@
 
     QString fileType() const;
 
-    void save(QTextStream &ts, const QString& indent = QString::null);
+    void save(QXmlStreamWriter &streamWriter);
 
     bool isEmpty() const;
 
     bool reset();
 
+    class Config;
+
   private:
     int _frameCount;
+    int *_rowIndex;
+    int _numLinesAlloc;
+    int _numFrames;
+    int _byteLength;
+    mutable QStringList _fields;
+    mutable Config *_config;
+    char *_tmpBuf;
+    uint _tmpBufSize;
+    bool _haveHeader;
+    mutable bool _fieldListComplete;
 };
 
 
+class DirFilePlugin : public QObject, public KstDataSourcePluginInterface {
+    Q_OBJECT
+    Q_INTERFACES(KstDataSourcePluginInterface)
+  public:
+    virtual ~DirFilePlugin() {}
+
+    virtual QString pluginName() const;
+
+    virtual bool hasConfigWidget() const { return false; }
+
+    virtual KstDataSource *create(QSettings *cfg,
+                                  const QString &filename,
+                                  const QString &type,
+                                  const QDomElement &element) const;
+
+    virtual QStringList matrixList(QSettings *cfg,
+                                  const QString& filename,
+                                  const QString& type,
+                                  QString *typeSuggestion,
+                                  bool *complete) const;
+
+    virtual QStringList fieldList(QSettings *cfg,
+                                  const QString& filename,
+                                  const QString& type,
+                                  QString *typeSuggestion,
+                                  bool *complete) const;
+
+    virtual int understands(QSettings *cfg, const QString& filename) const;
+
+    virtual bool supportsTime(QSettings *cfg, const QString& filename) const;
+
+    virtual QStringList provides() const;
+
+    virtual KstDataSourceConfigWidget *configWidget(QSettings *cfg, const QString& filename) const;
+};
+
+
 #endif
 // vim: ts=2 sw=2 et


More information about the Kst mailing list