[Kst] kdeextragear-2/kst/kst/datasources/ascii

George Staikos staikos at kde.org
Wed Mar 3 20:14:22 CET 2004


CVS commit by staikos: 

hack together a quick implementation of fieldList() for ascii files


  M +35 -4     ascii.cpp   1.11
  M +2 -0      ascii.h   1.5


--- kdeextragear-2/kst/kst/datasources/ascii/ascii.cpp  #1.10:1.11
@@ -241,4 +241,35 @@ QString AsciiSource::fileType() const {
 
 
+// FIXME: refactor to cache the number of columns and just update it in
+//        ::update() as needed
+QStringList AsciiSource::fieldList() const {
+  QStringList rc;
+  QFile file(_filename);
+  bool done = false;
+  QString line;
+
+  if (!file.open(IO_ReadOnly)) {
+    return rc;
+  }
+
+  QRegExp re("^\\s*[\\#\\/\\c\\!].*");
+  while (!file.atEnd() && !done) {
+      int rc = file.readLine(line, 1000);
+      if (rc > 1 && re.exactMatch(line)) {
+        done = true;
+      }
+  }
+
+  file.close();
+
+  int cnt = QStringList::split(QRegExp("\\s"), line, false).count();
+  for (int i = 1; i <= cnt; ++i) {
+    rc += QString::number(i);
+  }
+
+  return rc;
+}
+
+
 void AsciiSource::save(QTextStream &ts) {
   // FIXME
@@ -270,11 +301,11 @@ bool understands_ascii(const QString& fi
     QString s;
     Q_LONG rc = 0;
-    bool done=false;
+    bool done = false;
 
     while (!done) {
       rc = f.readLine(s, 1000);
-      if (rc<=0) {
+      if (rc <= 0) {
         done = true;
-      } else if (rc==1) {
+      } else if (rc == 1) {
         // empty line; do nothing
       } else if (QRegExp("^\\s*[\\#\\/\\c\\!].*").exactMatch(s)) {
@@ -284,5 +315,5 @@ bool understands_ascii(const QString& fi
         return true;
       } else {
-        return (false);
+        return false;
       }
     }

--- kdeextragear-2/kst/kst/datasources/ascii/ascii.h  #1.4:1.5
@@ -42,4 +42,6 @@ public:
   virtual QString fileType() const;
 
+  virtual QStringList fieldList() const;
+
   virtual void save(QTextStream &ts);
 





More information about the Kst mailing list