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

Adam Treat treat at kde.org
Thu Jun 28 16:43:21 CEST 2007


SVN commit 681312 by treat:

* Cleanup


 M  +21 -125   ascii.cpp  
 M  +3 -3      ascii.h  


--- branches/work/kst/portto4/kst/src/datasources/ascii/ascii.cpp #681311:681312
@@ -897,122 +897,10 @@
 };
 
 
-extern "C" {
-KstDataSource *create_ascii(KConfig *cfg, const QString& filename, const QString& type) {
-  return new AsciiSource(cfg, filename, type);
-}
+QString AsciiPlugin::pluginName() const { return "ASCII File Reader"; }
 
-KstDataSource *load_ascii(KConfig *cfg, const QString& filename, const QString& type, const QDomElement& e) {
-  return new AsciiSource(cfg, filename, type, e);
-}
 
-QStringList provides_ascii() {
-  QStringList rc;
-  rc += "ASCII";
-  return rc;
-}
-
-int understands_ascii(KConfig *cfg, const QString& filename) {
-  AsciiSource::Config config;
-  config.read(cfg, filename);
-
-  if (!config._fileNamePattern.isEmpty()) {
-    QRegExp filenamePattern(config._fileNamePattern);
-    filenamePattern.setPatternSyntax(QRegExp::Wildcard);
-    if (filenamePattern.exactMatch(filename)) {
-      return 100;
-    }
-  }
-
-  if (!QFile::exists(filename) || QFileInfo(filename).isDir()) {
-    return 0;
-  }
-
-  QFile f(filename);
-  if (f.open(QIODevice::ReadOnly)) {
-    QByteArray s;
-    qint64 rc = 0;
-    bool done = false;
-
-    QRegExp commentRE, dataRE;
-    if (config._columnType == AsciiSource::Config::Custom && !config._columnDelimiter.isEmpty()) {
-      commentRE.setPattern(QString("^[%1]*[%2].*").arg(QRegExp::escape(config._columnDelimiter)).arg(config._delimiters));
-      dataRE.setPattern(QString("^[%1]*(([Nn][Aa][Nn]|(\\-\\+)?[Ii][Nn][Ff]|[0-9\\+\\-\\.eE]+)[\\s]*)+").arg(QRegExp::escape(config._columnDelimiter)));
-    } else {
-      commentRE.setPattern(QString("^\\s*[%1].*").arg(config._delimiters));
-      dataRE.setPattern(QString("^[\\s]*(([Nn][Aa][Nn]|(\\-\\+)?[Ii][Nn][Ff]|[0-9\\+\\-\\.eE]+)[\\s]*)+"));
-    }
-
-    int skip = config._dataLine;
-
-    while (!done) {
-      rc = AsciiSource::readFullLine(f, s);
-      if (skip > 0) {
-        --skip;
-        if (rc <= 0) {
-          done = true;
-        }
-        continue;
-      }
-      if (rc <= 0) {
-        done = true;
-      } else if (rc == 1) {
-        // empty line; do nothing
-      } else if (commentRE.exactMatch(s)) {
-        // comment; do nothing
-      } else if (dataRE.exactMatch(s)) {
-        // a number - this may be an ascii file - assume that it is
-        // This line checks for an indirect file and gives that a chance too.
-        // Indirect files look like ascii files.
-        return QFile::exists(s.trimmed()) ? 49 : 75;
-      } else {
-        return 20;
-      }
-    }
-  } else {
-    return 0;
-  }
-
-  return 1; // still might be ascii - ex: header with no data yet.
-}
-
-
-QStringList fieldList_ascii(KConfig *cfg, const QString& filename, const QString& type, QString *typeSuggestion, bool *complete) {
-  if ((!type.isEmpty() && !provides_ascii().contains(type)) ||
-      0 == understands_ascii(cfg, filename)) {
-    if (complete) {
-      *complete = false;
-    }
-    return QStringList();
-  }
-
-  if (typeSuggestion) {
-    *typeSuggestion = "ASCII";
-  }
-
-  AsciiSource::Config config;
-  config.read(cfg, filename);
-  QStringList rc = AsciiSource::fieldListFor(filename, &config);
-
-  if (complete) {
-    *complete = rc.count() > 1;
-  }
-
-  return rc;
-}
-
-
-QWidget *widget_ascii(const QString& filename) {
-  Q_UNUSED(filename)
-  return new ConfigWidgetAscii;
-}
-
-}
-
-
-QString AsciiPluginInterface::pluginName() const { return "ASCII File Reader"; }
-
-KstDataSource *AsciiPluginInterface::create(KConfig *cfg,
+KstDataSource *AsciiPlugin::create(KConfig *cfg,
                                             const QString &filename,
                                             const QString &type,
                                             const QDomElement &element) const {
@@ -1020,7 +908,7 @@
   return new AsciiSource(cfg, filename, type, element);
 }
 
-QStringList AsciiPluginInterface::matrixList(KConfig *cfg,
+QStringList AsciiPlugin::matrixList(KConfig *cfg,
                                              const QString& filename,
                                              const QString& type,
                                              QString *typeSuggestion,
@@ -1030,8 +918,8 @@
   if (typeSuggestion) {
     *typeSuggestion = "ASCII";
   }
-  if ((!type.isEmpty() && !provides_ascii().contains(type)) ||
-      0 == understands_ascii(cfg, filename)) {
+  if ((!type.isEmpty() && !provides().contains(type)) ||
+      0 == understands(cfg, filename)) {
     if (complete) {
       *complete = false;
     }
@@ -1040,14 +928,15 @@
   return QStringList();
 }
 
-QStringList AsciiPluginInterface::fieldList(KConfig *cfg,
+
+QStringList AsciiPlugin::fieldList(KConfig *cfg,
                                             const QString& filename,
                                             const QString& type,
                                             QString *typeSuggestion,
                                             bool *complete) const {
 
-  if ((!type.isEmpty() && !provides_ascii().contains(type)) ||
-      0 == understands_ascii(cfg, filename)) {
+  if ((!type.isEmpty() && !provides().contains(type)) ||
+      0 == understands(cfg, filename)) {
     if (complete) {
       *complete = false;
     }
@@ -1070,7 +959,8 @@
 
 }
 
-int AsciiPluginInterface::understands(KConfig *cfg, const QString& filename) const {
+
+int AsciiPlugin::understands(KConfig *cfg, const QString& filename) const {
   AsciiSource::Config config;
   config.read(cfg, filename);
 
@@ -1134,24 +1024,30 @@
   return 1; // still might be ascii - ex: header with no data yet.
 }
 
-bool AsciiPluginInterface::supportsTime(KConfig *cfg, const QString& filename) const {
+
+bool AsciiPlugin::supportsTime(KConfig *cfg, const QString& filename) const {
+  //FIXME
+  Q_UNUSED(cfg)
+  Q_UNUSED(filename)
   return true;
 }
 
-QStringList AsciiPluginInterface::provides() const {
+
+QStringList AsciiPlugin::provides() const {
   QStringList rc;
   rc += "ASCII";
   return rc;
 }
 
-KstDataSourceConfigWidget *AsciiPluginInterface::configWidget(KConfig *cfg, const QString& filename) const {
 
+KstDataSourceConfigWidget *AsciiPlugin::configWidget(KConfig *cfg, const QString& filename) const {
+
+  Q_UNUSED(cfg)
   Q_UNUSED(filename)
   return new ConfigWidgetAscii;
 
 }
 
-// KST_KEY_DATASOURCE_PLUGIN(ascii)
 #include "ascii.moc"
 
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/datasources/ascii/ascii.h #681311:681312
@@ -86,11 +86,11 @@
 };
 
 
-class AsciiPluginInterface : public QObject, public KstDataSourcePluginInterface {
+class AsciiPlugin : public QObject, public KstDataSourcePluginInterface {
     Q_OBJECT
     Q_INTERFACES(KstDataSourcePluginInterface)
   public:
-    virtual ~AsciiPluginInterface() {}
+    virtual ~AsciiPlugin() {}
 
     virtual QString pluginName() const;
 
@@ -120,7 +120,7 @@
     virtual KstDataSourceConfigWidget *configWidget(KConfig *cfg, const QString& filename) const;
 };
 
-Q_EXPORT_PLUGIN2(kstdata_ascii, AsciiPluginInterface)
+Q_EXPORT_PLUGIN2(kstdata_ascii, AsciiPlugin)
 
 #endif
 // vim: ts=2 sw=2 et


More information about the Kst mailing list