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

Adam Treat treat at kde.org
Wed Jul 18 20:22:30 CEST 2007


SVN commit 689626 by treat:

* Actually create the vectors


 M  +2 -2      libkst/kstavector.cpp  
 M  +1 -1      libkst/kstavector.h  
 M  +47 -39    libkst/kstrvector.cpp  
 M  +5 -2      libkst/kstrvector.h  
 M  +2 -22     libkst/kstsvector.cpp  
 M  +1 -1      libkst/kstsvector.h  
 M  +4 -16     libkst/kstvector.cpp  
 M  +1 -1      libkst/kstvector.h  
 M  +9 -6      libkst/vectorfactory.cpp  
 M  +2 -2      libkstmath/equationfactory.cpp  


--- branches/work/kst/portto4/kst/src/libkst/kstavector.cpp #689625:689626
@@ -22,8 +22,8 @@
 #include "kstdebug.h"
 #include <qtextstream.h>
 
-KstAVector::KstAVector(const QDomElement &e)
-: KstVector(e) {
+KstAVector::KstAVector(const QString &tag, const QByteArray &data)
+: KstVector(tag, data) {
   _editable = true;
   _saveable = true;
   _saveData = true;
--- branches/work/kst/portto4/kst/src/libkst/kstavector.h #689625:689626
@@ -25,7 +25,7 @@
  */
 class KstAVector : public KstVector {
  public:
-  KST_EXPORT KstAVector(const QDomElement &e);
+  KST_EXPORT KstAVector(const QString &tag, const QByteArray &data);
   KST_EXPORT KstAVector(int n, KstObjectTag tag);
 
   KstObject::UpdateType update(int update_counter);
--- branches/work/kst/portto4/kst/src/libkst/kstrvector.cpp #689625:689626
@@ -52,9 +52,13 @@
 }
 
 
-KstRVector::KstRVector(const QDomElement &e, const QString &o_file,
+KstRVector::KstRVector(const QString &tag, const QByteArray &data,
+                       const QString &provider, const QString &file,
+                       const QString &field, int start, int num,
+                       int skip, bool doAve,
+                       const QString &o_file,
                        int o_n, int o_f, int o_s, bool o_ave)
-: KstVector(e) {
+: KstVector(tag, data) {
   KstDataSourcePtr in_file, in_provider;
   QString in_field;
   int in_f0 = 0;
@@ -63,53 +67,57 @@
   bool in_DoSkip = false;
   bool in_DoAve = false;
 
-  /* parse the DOM tree */
-  QDomNode n = e.firstChild();
-  while (!n.isNull()) {
-    QDomElement e = n.toElement();
-    if (!e.isNull()) {
-      if (e.tagName() == "provider") {
-        KST::dataSourceList.lock().readLock();
-        in_provider = *KST::dataSourceList.findTag(e.text());
-        KST::dataSourceList.lock().unlock();
-      } else if (e.tagName() == "filename") {
-        if (!in_provider) {
-          KST::dataSourceList.lock().readLock();
-          if (o_file == "|") {
-            in_file = *KST::dataSourceList.findFileName(e.text());
-          } else {
-            in_file = *KST::dataSourceList.findFileName(o_file);
-          }
-          KST::dataSourceList.lock().unlock();
-        }
-      } else if (e.tagName() == "field") {
-        in_field = e.text();
-      } else if (e.tagName() == "start") {
-        in_f0 = e.text().toInt();
-      } else if (e.tagName() == "num") {
-        in_n = e.text().toInt();
-      } else if (e.tagName() == "skip") {
-        in_skip = e.text().toInt();
-        in_DoSkip = in_skip > 0;
-      } else if (e.tagName() == "doAve") {
-        in_DoAve = true;
-        in_DoSkip = true;
-        if (in_skip < 1) {
-          in_skip = 1;
-        }
-      }
+  //FIXME THIS CTOR IS SO OBFUSCATED IT IS LAUGHABLE!
+  if (!provider.isEmpty()) {
+      KST::dataSourceList.lock().readLock();
+      in_provider = *KST::dataSourceList.findTag(provider);
+      KST::dataSourceList.lock().unlock();
+  }
+
+  if (!in_provider && !file.isEmpty()) {
+    KST::dataSourceList.lock().readLock();
+    if (o_file == "|") {
+      in_file = *KST::dataSourceList.findFileName(file);
+    } else {
+      in_file = *KST::dataSourceList.findFileName(o_file);
     }
-    n = n.nextSibling();
+    KST::dataSourceList.lock().unlock();
   }
 
+  if (!field.isEmpty()) {
+    in_field = field;
+  }
+
+  if (start > 0) {
+    in_f0 = start;
+  }
+
+  if (num > 0) {
+    in_n = num;
+  }
+
+  if (skip > 0) {
+    in_skip = skip;
+    in_DoSkip = in_skip > 0;
+  }
+
+  if (doAve) {
+    in_DoAve = true;
+    in_DoSkip = true;
+    if (in_skip < 1) {
+      in_skip = 1;
+    }
+  }
+
   if (in_provider) {
     // provider overrides filename
     in_file = in_provider;
   }
+
   if (in_file) {
     // use datasource as tag context for this RVector
     // allow unique vector names to be displayed at top-level
-    setTagName(KstObjectTag(tag().tag(), in_file->tag(), false));
+    setTagName(KstObjectTag(this->tag().tag(), in_file->tag(), false));
   }
 
   if (o_n > -2) {
--- branches/work/kst/portto4/kst/src/libkst/kstrvector.h #689625:689626
@@ -40,8 +40,11 @@
              int skip, bool in_doSkip,
              bool in_doAve);
 
-  KstRVector(const QDomElement &e,
-             const QString &o_file="|",
+  KstRVector(const QString &tag, const QByteArray &data,
+             const QString &provider = QString(), const QString &file = QString(),
+             const QString &field = QString(), int start = -1, int num = -1,
+             int skip = -1, bool doAve = false,
+             const QString &o_file = "|",
              int o_n = -2, int o_f = -2,
              int o_s = -1, bool o_ave = false);
 
--- branches/work/kst/portto4/kst/src/libkst/kstsvector.cpp #689625:689626
@@ -19,30 +19,10 @@
 #include <qtextstream.h>
 #include <QXmlStreamWriter>
 
-KstSVector::KstSVector(const QDomElement &e) : KstVector(e) {
-  double in_x0 = 0.0;
-  double in_x1 = 1.0;
-  int in_n = 2;
-
-  /* parse the DOM tree */
-  QDomNode n = e.firstChild();
-  while (!n.isNull()) {
-    QDomElement e = n.toElement();
-    if (!e.isNull()) {
-      if (e.tagName() == "N") {
-        in_n = e.text().toInt();
-      } else if (e.tagName() == "min") {
-        in_x0 = e.text().toDouble();
-      } else if (e.tagName() == "max") {
-        in_x1 = e.text().toDouble();
-      }
-    }
-    n = n.nextSibling();
-  }
-
+KstSVector::KstSVector(const QString &tag, const QByteArray &data, double x0, double x1, int n) : KstVector(tag, data) {
   _saveable = true;
   _saveData = false;
-  changeRange( in_x0,  in_x1,  in_n );
+  changeRange( x0,  x1,  n );
 }
 
 
--- branches/work/kst/portto4/kst/src/libkst/kstsvector.h #689625:689626
@@ -25,7 +25,7 @@
  */
 class KST_EXPORT KstSVector : public KstVector {
  public:
-  KstSVector(const QDomElement &e);
+  KstSVector(const QString &tag, const QByteArray &data, double x0 = 0.0, double x1 = 1.0, int n = 2);
   KstSVector(double x0, double x1, int n, KstObjectTag tag);
 
   void save(QXmlStreamWriter &s);
--- branches/work/kst/portto4/kst/src/libkst/kstvector.cpp #689625:689626
@@ -83,7 +83,7 @@
 }
 
 
-KstVector::KstVector(const QDomElement& e)
+KstVector::KstVector(const QString &tag, const QByteArray& data)
 : KstPrimitive(), _nsum(0) {
   QByteArray qba;
   _v = 0L;
@@ -98,21 +98,9 @@
   _saveable = false;
   _saveData = false;
 
-  QDomNode n = e.firstChild();
-  while (!n.isNull()) {
-    QDomElement e = n.toElement();
-    if (!e.isNull()) {
-      if (e.tagName() == "tag") {
-        in_tag = KstObjectTag::fromString(e.text());
-      } else if (e.tagName() == "data") {
-        QString qcs(e.text().toLatin1());
-        QByteArray qbca = QByteArray::fromBase64(qcs.toLatin1());
-        qba = qUncompress(qbca);
-        sz = qMax((size_t)(INITSIZE), qba.size()/sizeof(double));
-      }
-    }
-    n = n.nextSibling();
-  }
+  in_tag = KstObjectTag::fromString(tag);
+  qba = data;
+  sz = qMax((size_t)(INITSIZE), qba.size()/sizeof(double));
 
   if (!in_tag.isValid()) {
     do {
--- branches/work/kst/portto4/kst/src/libkst/kstvector.h #689625:689626
@@ -59,7 +59,7 @@
      */
     KstVector(KstObjectTag in_tag = KstObjectTag::invalidTag, int size = 0,
         KstObject *provider = 0L, bool bIsScalarList = false);
-    KstVector(const QDomElement& e);
+    KstVector(const QString &tag, const QByteArray &data);
 
   protected:
     virtual ~KstVector();
--- branches/work/kst/portto4/kst/src/libkst/vectorfactory.cpp #689625:689626
@@ -32,19 +32,22 @@
   QByteArray data;
 
   while (!xml.atEnd()) {
+      const QString n = xml.name().toString();
     if (xml.isStartElement()) {
-      const QString n = xml.name().toString();
       if (n == "vector") {
         QXmlStreamAttributes attrs = xml.attributes();
         tag = attrs.value("tag").toString();
-//         QString qcs(xml.readElementText().toLatin1());
-//         QByteArray qbca = QByteArray::fromBase64(qcs.toLatin1());
-//         data = qUncompress(qbca);
+      } else if (n == "data") {
+
+        QString qcs(xml.readElementText().toLatin1());
+        QByteArray qbca = QByteArray::fromBase64(qcs.toLatin1());
+        data = qUncompress(qbca);
+
       } else {
         return 0;
       }
     } else if (xml.isEndElement()) {
-      if (xml.name().toString() == "vector") {
+      if (n == "vector") {
         break;
       } else {
         KstDebug::self()->log(QObject::tr("Error creating vector from Kst file."), KstDebug::Warning);
@@ -58,7 +61,7 @@
     return 0;
   }
 
-  KstVectorPtr vector = 0;
+  KstVectorPtr vector = new KstVector(tag, data);
   return vector.data();
 }
 
--- branches/work/kst/portto4/kst/src/libkstmath/equationfactory.cpp #689625:689626
@@ -31,8 +31,8 @@
   bool interpolate = false;
 
   while (!xml.atEnd()) {
+    const QString n = xml.name().toString();
     if (xml.isStartElement()) {
-      const QString n = xml.name().toString();
       if (n == "equation") {
         QXmlStreamAttributes attrs = xml.attributes();
         name = attrs.value("name").toString();
@@ -46,7 +46,7 @@
         return 0;
       }
     } else if (xml.isEndElement()) {
-      if (xml.name().toString() == "equation") {
+      if (n == "equation") {
         break;
       } else {
         KstDebug::self()->log(QObject::tr("Error creating equation from Kst file."), KstDebug::Warning);


More information about the Kst mailing list