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

George Staikos staikos at kde.org
Wed Jan 5 05:43:05 CET 2005


CVS commit by staikos: 

start to implement field list caching, and partially fix comment detection


  M +10 -6     ascii.cpp   1.30
  M +1 -0      ascii.h   1.12


--- kdeextragear-2/kst/kst/datasources/ascii/ascii.cpp  #1.29:1.30
@@ -84,4 +84,6 @@ KstObject::UpdateType AsciiSource::updat
   }
 
+  _fields.clear(); // FIXME: only clear if the fields have changed
+
   if (file.exists()) {
     if (uint(_byteLength) != file.size() || !_valid) {
@@ -335,5 +337,5 @@ bool AsciiSource::isEmpty() const {
 
 
-static QStringList fieldListFor(const QString& filename) {
+static QStringList fieldListFor(const QString& filename, const QString& del) {
   QStringList rc;
   QFile file(filename);
@@ -345,5 +347,5 @@ static QStringList fieldListFor(const QS
   }
 
-  QRegExp re("^\\s*[#/c!].*");
+  QRegExp re(QString("^\\s*[%1].*").arg(del));
   while (!file.atEnd() && !done) {
       int rc = file.readLine(line, 1000);
@@ -365,8 +367,10 @@ static QStringList fieldListFor(const QS
 
 
-// FIXME: refactor to cache the number of columns and just update it in
-//        ::update() as needed
 QStringList AsciiSource::fieldList() const {
-  return fieldListFor(_filename);
+  if (_fields.isEmpty()) {
+    _fields = fieldListFor(_filename, _delimiters);
+  }
+
+  return _fields;
 }
 
@@ -464,5 +468,5 @@ QStringList fieldList_ascii(KConfig *cfg
   }
 
-  return fieldListFor(filename);
+  return fieldListFor(filename, "#/c!;");
 }
 

--- kdeextragear-2/kst/kst/datasources/ascii/ascii.h  #1.11:1.12
@@ -56,4 +56,5 @@ class AsciiSource : public KstDataSource
     int _byteLength;
     QString _delimiters;
+    mutable QStringList _fields;
 };
 




More information about the Kst mailing list