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

Peter Kümmel syntheticpp at gmx.net
Tue Jul 27 11:31:14 CEST 2010


SVN commit 1155406 by kuemmel:

AsciiPlugin: split out filedname to column function

 M  +22 -18    asciisource.cpp  
 M  +2 -0      asciisource.h  


--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1155405:1155406
@@ -303,6 +303,26 @@
 */
 
 
+int AsciiSource::columnOfField(const QString& field) const
+{
+  if (_fieldList.contains(field)) {
+    return _fieldList.indexOf(field);
+  } 
+  
+  if (_fieldListComplete) {
+    return -1;
+  }
+
+  bool ok = false;
+  int col = field.toInt(&ok);
+  if (ok) {
+    return col;
+  }
+
+  return -1;
+}
+
+
 //-------------------------------------------------------------------------------------------
 int AsciiSource::readField(double *v, const QString& field, int s, int n) 
 {
@@ -320,29 +340,13 @@
     return n;
   }
 
-  QStringList fieldList = _fieldList;
-  int col = 0;
-  for (QStringList::ConstIterator i = fieldList.begin(); i != fieldList.end(); ++i) {
-    if (*i == field) {
-      break;
-    }
-    ++col;
-  }
-
-  if (col + 1 > fieldList.count()) {
-    if (_fieldListComplete) {
+  int col = columnOfField(field);
+  if (col == -1) {
       return 0;
     }
-    bool ok = false;
-    col = field.toInt(&ok);
-    if (!ok) {
-      return 0;
-    }
-  }
 
   int bufstart = _rowIndex[s];
   int bufread = _rowIndex[s + n] - bufstart;
-
   if (bufread <= 0) {
     return 0;
   }
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.h #1155405:1155406
@@ -88,6 +88,8 @@
     QStringList _stringList;
     QStringList _fieldList;
 
+    int columnOfField(const QString& field) const;
+
     DataInterfaceAsciiVector* iv;
 
     bool openValidFile(QFile &file);


More information about the Kst mailing list