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

Peter Kümmel syntheticpp at gmx.net
Thu Jan 27 15:23:20 CET 2011


SVN commit 1217483 by kuemmel:

fix QDomElement parser

 M  +15 -35    asciisourceconfig.cpp  
 M  +7 -3      namedparameter.h  


--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisourceconfig.cpp #1217482:1217483
@@ -176,46 +176,26 @@
 
 
 void AsciiSourceConfig::load(const QDomElement& e) {
-  // TODO use tags, isn't this code torally buggy, because trings and tags doesn't match?
    QDomNode n = e.firstChild();
    while (!n.isNull()) {
-     QDomElement e = n.toElement();
-     if (!e.isNull()) {
-       if (e.tagName() == "index") {
-         if (e.hasAttribute("vector")) {
-           _indexVector = e.attribute("vector");
+    QDomElement elem = n.toElement();
+    if (!elem.isNull()) {
+      if (elem.tagName() == "properties") {
+        _fileNamePattern << elem;
+        _indexVector << elem;
+        _delimiters << elem;
+        _indexInterpretation << elem;
+        _columnType << elem;
+        _columnDelimiter << elem;
+        _columnWidth << elem;
+        _dataLine << elem;
+        _readFields << elem;
+        _useDot << elem;
+        _fieldsLine << elem;
+        _columnWidthIsConst << elem;
          }
-         if (e.hasAttribute("interpretation")) {
-           _indexInterpretation = Interpretation(e.attribute("interpretation").toInt());
          }
-       } else if (e.tagName() == "comment") {
-         if (e.hasAttribute("delimiters")) {
-           _delimiters = e.attribute("delimiters").toLatin1();
-         }
-       } else if (e.tagName() == "columns") {
-         if (e.hasAttribute("type")) {
-           _columnType = ColumnType(e.attribute("type").toInt());
-         }
-         if (e.hasAttribute("width")) {
-           _columnWidth = e.attribute("width").toInt();
-         }
-         if (e.hasAttribute(Key_columnWidthIsConst)) {
-           _columnWidthIsConst = e.attribute(Key_columnWidthIsConst).toInt();
-         }
-         if (e.hasAttribute("delimiters")) {
-           _columnDelimiter = e.attribute("delimiters").toLatin1();
-         }
-       } else if (e.tagName() == "header") {
-         if (e.hasAttribute("start")) {
-           _dataLine = e.attribute("start").toInt();
-         }
-         if (e.hasAttribute("fields")) {
-           _fieldsLine = e.attribute("fields").toInt();
-         }
-       }
-     }
      n = n.nextSibling();
    }
 }
 
-
--- branches/work/kst/portto4/kst/src/datasources/ascii/namedparameter.h #1217482:1217483
@@ -20,10 +20,8 @@
 #include <QSettings>
 #include <QXmlStreamWriter>
 #include <QXmlStreamAttributes>
-#include <QDebug>
+#include <QDomElement>
 
-
-
 template<class T, const char* Key, const char* Tag>
 class NamedParameter
 {
@@ -55,6 +53,12 @@
     setValue(QVariant(att.value(Tag).toString()).value<T>());
   }
 
+  void operator<<(const QDomElement& e) {
+    if (e.hasAttribute(Tag)) {
+      setValue(QVariant(e.attribute(Tag)).value<T>());
+    }
+  }
+
   void setValue(const T& t) {
     _value = t;
     _value_set = true;


More information about the Kst mailing list