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

Mike Fenton mike at staikos.net
Thu Nov 8 14:51:56 CET 2007


SVN commit 734292 by fenton:

Redo Vector creation in the Factory.


 M  +16 -3     vector.cpp  
 M  +2 -0      vector.h  
 M  +53 -6     vectorfactory.cpp  


--- branches/work/kst/portto4/kst/src/libkst/vector.cpp #734291:734292
@@ -86,9 +86,6 @@
   _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);
@@ -665,6 +662,22 @@
   _saveData = save;
 }
 
+
+void Vector::change(QByteArray &data) {
+  if (!data.isEmpty()) {
+    _saveable = true;
+    _saveData = true;
+
+    int sz = qMax((size_t)(INITSIZE), data.size()/sizeof(double));
+    resize(sz, true);
+
+    QDataStream qds(data);
+    for (int i = 0; !qds.atEnd(); ++i) {
+      qds >> _v[i];
+    }
+  }
+}
+
 #undef ZERO_MEMORY
 #undef INITSIZE
 
--- branches/work/kst/portto4/kst/src/libkst/vector.h #734291:734292
@@ -67,6 +67,8 @@
     friend class ObjectStore; // FIXME: remove this when VectorFactory is working
 
   public:
+    void change(QByteArray& data);
+
     inline int length() const { return _size; }
 
     /** Return V[i], interpolated/decimated to have ns_i total samples */
--- branches/work/kst/portto4/kst/src/libkst/vectorfactory.cpp #734291:734292
@@ -17,6 +17,7 @@
 #include "editablevector.h"
 #include "datavector.h"
 #include "datacollection.h"
+#include "objectstore.h"
 
 namespace Kst {
 
@@ -66,7 +67,14 @@
     return 0;
   }
 
-  return new Vector(store, tag, data);
+  VectorPtr vector = store->createObject<Vector>(tag);
+  vector->change(data);
+
+  vector->writeLock();
+  vector->update(0);
+  vector->unlock();
+
+  return vector;
 }
 
 
@@ -82,7 +90,6 @@
 
 PrimitivePtr GeneratedVectorFactory::generatePrimitive(ObjectStore *store, QXmlStreamReader& xml) {
   ObjectTag tag;
-  QByteArray data;
   double min, max;
   int count;
 
@@ -113,7 +120,14 @@
     return 0;
   }
 
-  return new GeneratedVector(store, tag, data, min, max, count);
+  GeneratedVectorPtr vector = store->createObject<GeneratedVector>(tag);
+  vector->changeRange(min, max, count);
+
+  vector->writeLock();
+  vector->update(0);
+  vector->unlock();
+
+  return vector;
 }
 
 EditableVectorFactory::EditableVectorFactory()
@@ -159,7 +173,14 @@
     return 0;
   }
 
-  return new EditableVector(store, tag, data);
+  EditableVectorPtr vector = store->createObject<EditableVector>(tag);
+  vector->change(data);
+
+  vector->writeLock();
+  vector->update(0);
+  vector->unlock();
+
+  return vector;
 }
 
 
@@ -177,7 +198,7 @@
   ObjectTag tag;
   QByteArray data;
   QString provider, file, field;
-  int start, count, skip;
+  int start, count, skip = -1;
   bool doAve;
 
   while (!xml.atEnd()) {
@@ -219,7 +240,33 @@
     return 0;
   }
 
-  return new DataVector(store, tag, data, provider, file, field, start, count, skip, doAve);
+  Q_ASSERT(store);
+  DataSourcePtr dataSource = store->dataSourceList().findReusableFileName(file);
+
+  if (!dataSource) {
+    dataSource = DataSource::loadSource(store, file, QString());
+  }
+
+  if (!dataSource) {
+    return 0; //Couldn't find a suitable datasource
+  }
+
+  DataVectorPtr vector = store->createObject<DataVector>(tag);
+
+  vector->writeLock();
+  vector->change(dataSource, field,
+      start,
+      count,
+      skip,
+      (skip != -1),
+      doAve);
+
+  vector->update(0);
+  vector->unlock();
+
+  return vector;
+
+  return 0;
 }
 
 }


More information about the Kst mailing list