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

Mike Fenton mike at staikos.net
Mon Nov 5 17:43:29 CET 2007


SVN commit 733135 by fenton:

Add Save/Restore functionality for EditableVector, DataVector, GeneratedVector and Vector.


 M  +2 -2      datavector.cpp  
 M  +1 -0      datavector.h  
 M  +21 -1     editablevector.cpp  
 M  +3 -0      editablevector.h  
 M  +2 -2      generatedvector.cpp  
 M  +1 -0      generatedvector.h  
 M  +4 -1      vector.cpp  
 M  +1 -0      vector.h  
 M  +11 -18    vectorfactory.cpp  


--- branches/work/kst/portto4/kst/src/libkst/datavector.cpp #733134:733135
@@ -21,7 +21,6 @@
 #include <stdlib.h>
 
 #include <QDebug>
-#include <QTextDocument>
 #include <QXmlStreamWriter>
 
 #include "kst_i18n.h"
@@ -45,6 +44,7 @@
 namespace Kst {
 
 const QString DataVector::staticTypeString = I18N_NOOP("Data Vector");
+const QString DataVector::staticTypeTag = I18N_NOOP("datavector");
 
 /** Create a DataVector: raw data from a file */
 DataVector::DataVector(ObjectStore *store, const ObjectTag& in_tag,
@@ -347,7 +347,7 @@
 /** Save vector information */
 void DataVector::save(QXmlStreamWriter &s) {
   if (_file) {    
-    s.writeStartElement("rvector");
+    s.writeStartElement("datavector");
     _file->readLock();
     s.writeAttribute("provider", _file->tag().tagString());
     s.writeAttribute("file", _file->fileName());
--- branches/work/kst/portto4/kst/src/libkst/datavector.h #733134:733135
@@ -39,6 +39,7 @@
   public:
     virtual const QString& typeString() const;
     static const QString staticTypeString;
+    static const QString staticTypeTag;
 
     /** change the properties of a DataVector */
     void change(DataSourcePtr file, const QString &field,
--- branches/work/kst/portto4/kst/src/libkst/editablevector.cpp #733134:733135
@@ -12,7 +12,7 @@
 // use KCodecs::base64Encode() in kmdcodecs.h
 // Create QDataStream into a QByteArray
 // qCompress the bytearray
-#include <QTextStream>
+#include <QXmlStreamWriter>
 
 #include "editablevector.h"
 #include "debug.h"
@@ -21,6 +21,7 @@
 namespace Kst {
 
 const QString EditableVector::staticTypeString = I18N_NOOP("Editable Vector");
+const QString EditableVector::staticTypeTag = I18N_NOOP("editablevector");
 
 EditableVector::EditableVector(ObjectStore *store, const ObjectTag& tag, const QByteArray &data)
     : Vector(store, tag, data) {
@@ -65,5 +66,24 @@
   Q_UNUSED(save)
 }
 
+/** Save vector information */
+void EditableVector::save(QXmlStreamWriter &s) {
+  s.writeStartElement("editablevector");
+  s.writeAttribute("tag", tag().tagString());
+  if (_saveData) {
+    QByteArray qba(length()*sizeof(double), '\0');
+    QDataStream qds(&qba, QIODevice::WriteOnly);
+
+    for (int i = 0; i < length(); i++) {
+      qds << _v[i];
+    }
+
+    s.writeTextElement("data", qCompress(qba).toBase64());
+  }
+  s.writeEndElement();
 }
+
+
+
+}
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkst/editablevector.h #733134:733135
@@ -27,7 +27,10 @@
   public:
     virtual const QString& typeString() const;
     static const QString staticTypeString;
+    static const QString staticTypeTag;
 
+    void save(QXmlStreamWriter &s);
+
     Object::UpdateType update(int update_counter);
 
     void setSaveData(bool save);
--- branches/work/kst/portto4/kst/src/libkst/generatedvector.cpp #733134:733135
@@ -15,7 +15,6 @@
  *                                                                         *
  ***************************************************************************/
 #include <QDebug>
-#include <QTextStream>
 #include <QXmlStreamWriter>
 
 #include "kst_i18n.h"
@@ -25,6 +24,7 @@
 namespace Kst {
 
 const QString GeneratedVector::staticTypeString = I18N_NOOP("Generated Vector");
+const QString GeneratedVector::staticTypeTag = I18N_NOOP("generatedvector");
 
 GeneratedVector::GeneratedVector(ObjectStore *store, const ObjectTag& tag, const QByteArray &data, double x0, double x1, int n)
     : Vector(store, tag, data) {
@@ -48,7 +48,7 @@
 
 
 void GeneratedVector::save(QXmlStreamWriter &s) {
-  s.writeStartElement("svector");
+  s.writeStartElement("generatedvector");
   s.writeAttribute("tag", tag().tagString());
   s.writeAttribute("min", QString::number(min()));
   s.writeAttribute("max", QString::number(max()));
--- branches/work/kst/portto4/kst/src/libkst/generatedvector.h #733134:733135
@@ -31,6 +31,7 @@
   public:
     virtual const QString& typeString() const;
     static const QString staticTypeString;
+    static const QString staticTypeTag;
 
     void save(QXmlStreamWriter &s);
 
--- branches/work/kst/portto4/kst/src/libkst/vector.cpp #733134:733135
@@ -21,7 +21,6 @@
 #include <stdlib.h>
 
 #include <QDebug>
-#include <QTextDocument>
 #include <QXmlStreamWriter>
 
 #include "kst_i18n.h"
@@ -42,6 +41,7 @@
 #define INITSIZE 1
 
 const QString Vector::staticTypeString = I18N_NOOP("Vector");
+const QString Vector::staticTypeTag = I18N_NOOP("vector");
 
 /** Create a vector */
 Vector::Vector(ObjectStore *store, const ObjectTag& tag, int size, Object *provider, bool isScalarList)
@@ -86,6 +86,9 @@
   _saveable = false;
   _saveData = false;
 
+  // Contructor used for restore.  Must add Object to Store.
+  store->addObject(this);
+
   sz = qMax((size_t)(INITSIZE), data.size()/sizeof(double));
 
   CreateScalars(store);
--- branches/work/kst/portto4/kst/src/libkst/vector.h #733134:733135
@@ -53,6 +53,7 @@
   public:
     virtual const QString& typeString() const;
     static const QString staticTypeString;
+    static const QString staticTypeTag;
 
   protected:
     Vector(ObjectStore *store, const ObjectTag& tag = ObjectTag::invalidTag, int size = 0,
--- branches/work/kst/portto4/kst/src/libkst/vectorfactory.cpp #733134:733135
@@ -22,7 +22,7 @@
 
 VectorFactory::VectorFactory()
 : PrimitiveFactory() {
-  registerFactory(Vector::type(), this);
+  registerFactory(Vector::staticTypeTag, this);
 }
 
 
@@ -72,7 +72,7 @@
 
 GeneratedVectorFactory::GeneratedVectorFactory()
 : PrimitiveFactory() {
-  registerFactory(GeneratedVector::type(), this);
+  registerFactory(GeneratedVector::staticTypeTag, this);
 }
 
 
@@ -89,26 +89,20 @@
   while (!xml.atEnd()) {
       const QString n = xml.name().toString();
     if (xml.isStartElement()) {
-      if (n == "svector") {
+      if (n == "generatedvector") {
         QXmlStreamAttributes attrs = xml.attributes();
         tag = ObjectTag::fromString(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") {
+      if (n == "generatedvector") {
         break;
       } else {
-        Debug::self()->log(QObject::tr("Error creating vector from Kst file."), Debug::Warning);
+        Debug::self()->log(QObject::tr("Error creating generated vector from Kst file."), Debug::Warning);
         return 0;
       }
     }
@@ -124,7 +118,7 @@
 
 EditableVectorFactory::EditableVectorFactory()
 : PrimitiveFactory() {
-  registerFactory(EditableVector::type(), this);
+  registerFactory(EditableVector::staticTypeTag, this);
 }
 
 
@@ -139,11 +133,10 @@
   while (!xml.atEnd()) {
       const QString n = xml.name().toString();
     if (xml.isStartElement()) {
-      if (n == "avector") {
+      if (n == "editablevector") {
         QXmlStreamAttributes attrs = xml.attributes();
         tag = ObjectTag::fromString(attrs.value("tag").toString());
       } else if (n == "data") {
-
         QString qcs(xml.readElementText().toLatin1());
         QByteArray qbca = QByteArray::fromBase64(qcs.toLatin1());
         data = qUncompress(qbca);
@@ -152,7 +145,7 @@
         return 0;
       }
     } else if (xml.isEndElement()) {
-      if (n == "avector") {
+      if (n == "editablevector") {
         break;
       } else {
         Debug::self()->log(QObject::tr("Error creating vector from Kst file."), Debug::Warning);
@@ -172,7 +165,7 @@
 
 DataVectorFactory::DataVectorFactory()
 : PrimitiveFactory() {
-  registerFactory(DataVector::type(), this);
+  registerFactory(DataVector::staticTypeTag, this);
 }
 
 
@@ -190,7 +183,7 @@
   while (!xml.atEnd()) {
       const QString n = xml.name().toString();
     if (xml.isStartElement()) {
-      if (n == "rvector") {
+      if (n == "datavector") {
         QXmlStreamAttributes attrs = xml.attributes();
         tag = ObjectTag::fromString(attrs.value("tag").toString());
 
@@ -212,7 +205,7 @@
         return 0;
       }
     } else if (xml.isEndElement()) {
-      if (n == "rvector") {
+      if (n == "datavector") {
         break;
       } else {
         Debug::self()->log(QObject::tr("Error creating vector from Kst file."), Debug::Warning);


More information about the Kst mailing list