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

Adam Treat treat at kde.org
Wed Jul 18 21:03:26 CEST 2007


SVN commit 689639 by treat:

* Load svector, avector, and rvector too.


 M  +3 -0      libkst/builtinprimitives.cpp  
 M  +1 -1      libkst/kstsvector.h  
 M  +170 -0    libkst/vectorfactory.cpp  
 M  +21 -0     libkst/vectorfactory.h  
 M  +1 -0      libkstmath/equationfactory.cpp  


--- branches/work/kst/portto4/kst/src/libkst/builtinprimitives.cpp #689638:689639
@@ -16,6 +16,9 @@
   namespace Builtins {
     void initPrimitives() {
       new VectorFactory;
+      new SVectorFactory;
+      new AVectorFactory;
+      new RVectorFactory;
     }
   }
 }
--- branches/work/kst/portto4/kst/src/libkst/kstsvector.h #689638:689639
@@ -25,7 +25,7 @@
  */
 class KST_EXPORT KstSVector : public KstVector {
  public:
-  KstSVector(const QString &tag, const QByteArray &data, double x0 = 0.0, double x1 = 1.0, int n = 2);
+  KstSVector(const QString &tag, const QByteArray &data, double x0, double x1, int n);
   KstSVector(double x0, double x1, int n, KstObjectTag tag);
 
   void save(QXmlStreamWriter &s);
--- branches/work/kst/portto4/kst/src/libkst/vectorfactory.cpp #689638:689639
@@ -13,6 +13,9 @@
 
 #include "kstdebug.h"
 #include "kstvector.h"
+#include "kstsvector.h"
+#include "kstavector.h"
+#include "kstrvector.h"
 #include "kstdatacollection.h"
 
 namespace Kst {
@@ -22,6 +25,7 @@
   registerFactory("vector", this);
 }
 
+
 VectorFactory::~VectorFactory() {
 }
 
@@ -65,6 +69,172 @@
   return vector.data();
 }
 
+
+SVectorFactory::SVectorFactory()
+: PrimitiveFactory() {
+  registerFactory("svector", this);
 }
 
+
+SVectorFactory::~SVectorFactory() {
+}
+
+
+KstPrimitivePtr SVectorFactory::generatePrimitive(QXmlStreamReader& xml) {
+
+  QString tag;
+  QByteArray data;
+  double min, max;
+  int count;
+
+  while (!xml.atEnd()) {
+      const QString n = xml.name().toString();
+    if (xml.isStartElement()) {
+      if (n == "svector") {
+        QXmlStreamAttributes attrs = xml.attributes();
+        tag = attrs.value("tag").toString();
+        min = attrs.value("min").toString().toDouble();
+        max = attrs.value("max").toString().toDouble();
+        count = attrs.value("count").toString().toInt();
+      } 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 (n == "svector") {
+        break;
+      } else {
+        KstDebug::self()->log(QObject::tr("Error creating vector from Kst file."), KstDebug::Warning);
+        return 0;
+      }
+    }
+    xml.readNext();
+  }
+
+  if (xml.hasError()) {
+    return 0;
+  }
+
+  KstVectorPtr vector = new KstSVector(tag, data, min, max, count);
+  return vector.data();
+}
+
+AVectorFactory::AVectorFactory()
+: PrimitiveFactory() {
+  registerFactory("avector", this);
+}
+
+
+AVectorFactory::~AVectorFactory() {
+}
+
+
+KstPrimitivePtr AVectorFactory::generatePrimitive(QXmlStreamReader& xml) {
+
+  QString tag;
+  QByteArray data;
+
+  while (!xml.atEnd()) {
+      const QString n = xml.name().toString();
+    if (xml.isStartElement()) {
+      if (n == "avector") {
+        QXmlStreamAttributes attrs = xml.attributes();
+        tag = attrs.value("tag").toString();
+      } 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 (n == "avector") {
+        break;
+      } else {
+        KstDebug::self()->log(QObject::tr("Error creating vector from Kst file."), KstDebug::Warning);
+        return 0;
+      }
+    }
+    xml.readNext();
+  }
+
+  if (xml.hasError()) {
+    return 0;
+  }
+
+  KstVectorPtr vector = new KstAVector(tag, data);
+  return vector.data();
+}
+
+
+RVectorFactory::RVectorFactory()
+: PrimitiveFactory() {
+  registerFactory("rvector", this);
+}
+
+
+RVectorFactory::~RVectorFactory() {
+}
+
+
+KstPrimitivePtr RVectorFactory::generatePrimitive(QXmlStreamReader& xml) {
+
+  QString tag;
+  QByteArray data;
+  QString provider, file, field;
+  int start, count, skip;
+  bool doAve;
+
+  while (!xml.atEnd()) {
+      const QString n = xml.name().toString();
+    if (xml.isStartElement()) {
+      if (n == "rvector") {
+        QXmlStreamAttributes attrs = xml.attributes();
+        tag = attrs.value("tag").toString();
+
+        provider = attrs.value("provider").toString();
+        file = attrs.value("file").toString();
+        field = attrs.value("field").toString();
+        start = attrs.value("start").toString().toInt();
+        count = attrs.value("count").toString().toInt();
+        skip = attrs.value("skip").toString().toInt();
+        doAve = attrs.value("doAve").toString() == "true" ? true : false;
+
+      } 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 (n == "rvector") {
+        break;
+      } else {
+        KstDebug::self()->log(QObject::tr("Error creating vector from Kst file."), KstDebug::Warning);
+        return 0;
+      }
+    }
+    xml.readNext();
+  }
+
+  if (xml.hasError()) {
+    return 0;
+  }
+
+  KstVectorPtr vector = new KstRVector(tag, data, provider, file, field, start, count, skip, doAve);
+  return vector.data();
+}
+
+}
+
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkst/vectorfactory.h #689638:689639
@@ -23,6 +23,27 @@
     KstPrimitivePtr generatePrimitive(QXmlStreamReader& stream);
 };
 
+class SVectorFactory : public PrimitiveFactory {
+  public:
+    SVectorFactory();
+    ~SVectorFactory();
+    KstPrimitivePtr generatePrimitive(QXmlStreamReader& stream);
+};
+
+class AVectorFactory : public PrimitiveFactory {
+  public:
+    AVectorFactory();
+    ~AVectorFactory();
+    KstPrimitivePtr generatePrimitive(QXmlStreamReader& stream);
+};
+
+class RVectorFactory : public PrimitiveFactory {
+  public:
+    RVectorFactory();
+    ~RVectorFactory();
+    KstPrimitivePtr generatePrimitive(QXmlStreamReader& stream);
+};
+
 }
 
 #endif
--- branches/work/kst/portto4/kst/src/libkstmath/equationfactory.cpp #689638:689639
@@ -22,6 +22,7 @@
   registerFactory("equation", this);
 }
 
+
 EquationFactory::~EquationFactory() {
 }
 


More information about the Kst mailing list