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

Mike Fenton mike at staikos.net
Tue Nov 6 16:00:31 CET 2007


SVN commit 733520 by fenton:

Addition of Save/Restore for DataMatrix, EditableMatrix and GeneratedMatrix.


 M  +4 -0      builtinprimitives.cpp  
 M  +2 -1      datamatrix.cpp  
 M  +1 -0      datamatrix.h  
 M  +14 -14    editablematrix.cpp  
 M  +2 -1      editablematrix.h  
 M  +3 -1      generatedmatrix.cpp  
 M  +1 -0      generatedmatrix.h  
 M  +51 -49    libkst.pro  
 M  +25 -0     matrix.cpp  
 M  +3 -0      matrix.h  
 A             matrixfactory.cpp   [License: GPL (v2+)]
 A             matrixfactory.h   [License: GPL (v2+)]


--- branches/work/kst/portto4/kst/src/libkst/builtinprimitives.cpp #733519:733520
@@ -13,6 +13,7 @@
 #include "vectorfactory.h"
 #include "scalarfactory.h"
 #include "stringfactory.h"
+#include "matrixfactory.h"
 
 namespace Kst {
   namespace Builtins {
@@ -23,6 +24,9 @@
       new DataVectorFactory();
       new ScalarFactory();
       new StringFactory();
+      new GeneratedMatrixFactory();
+      new EditableMatrixFactory();
+      new DataMatrixFactory();
     }
   }
 }
--- branches/work/kst/portto4/kst/src/libkst/datamatrix.cpp #733519:733520
@@ -31,6 +31,7 @@
 namespace Kst {
 
 const QString DataMatrix::staticTypeString = I18N_NOOP("Data Matrix");
+const QString DataMatrix::staticTypeTag = I18N_NOOP("datamatrix");
 
 DataMatrix::DataMatrix(ObjectStore *store, const ObjectTag& tag)
   : Matrix(store, tag) {
@@ -118,7 +119,7 @@
 
 void DataMatrix::save(QXmlStreamWriter &xml) {
   if (_file) {
-    xml.writeStartElement("datamatrix");
+    xml.writeStartElement(staticTypeTag);
     xml.writeAttribute("tag", tag().tagString());
 
     _file->readLock();
--- branches/work/kst/portto4/kst/src/libkst/datamatrix.h #733519:733520
@@ -26,6 +26,7 @@
   public:
     virtual const QString& typeString() const;
     static const QString staticTypeString;
+    static const QString staticTypeTag;
 
     // save DataMatrix
     virtual void save(QXmlStreamWriter &xml);
--- branches/work/kst/portto4/kst/src/libkst/editablematrix.cpp #733519:733520
@@ -16,12 +16,13 @@
 #include "editablematrix.h"
 #include "debug.h"
 #include <qbytearray.h>
-#include <qtextdocument.h>
+#include <QXmlStreamWriter>
 #include "kst_i18n.h"
 
 namespace Kst {
 
 const QString EditableMatrix::staticTypeString = I18N_NOOP("Editable Matrix");
+const QString EditableMatrix::staticTypeTag = I18N_NOOP("editablematrix");
 
 EditableMatrix::EditableMatrix(ObjectStore *store, const QDomElement &e) : Matrix(store) {
   _editable = true;
@@ -97,10 +98,8 @@
 }
 
 
-void EditableMatrix::save(QTextStream &ts, const QString& indent) {
+void EditableMatrix::save(QXmlStreamWriter &xml) {
 
-  QString indent2 = "  ";
-
   QByteArray qba(_zSize*sizeof(double), '\0');
   QDataStream qds(&qba, QIODevice::WriteOnly);
 
@@ -108,17 +107,18 @@
     qds << _z[i];
   }
 
-  ts << indent << "<amatrix>" << endl;
-  ts << indent << indent2 << "<tag>" << Qt::escape(tag().tagString()) << "</tag>" << endl;
-  ts << indent << indent2 << "<xmin>" << minX() << "</xmin>" << endl;
-  ts << indent << indent2 << "<ymin>" << minY() << "</ymin>" << endl;
-  ts << indent << indent2 << "<nx>" << xNumSteps() << "</nx>" << endl;
-  ts << indent << indent2 << "<ny>" << yNumSteps() << "</ny>" << endl;
-  ts << indent << indent2 << "<xstep>" << xStepSize() << "</xstep>" << endl;
-  ts << indent << indent2 << "<ystep>" << xStepSize() << "</ystep>" << endl;
-  ts << indent << indent2 << "<data>" << qCompress(qba).toBase64() << "</data>" << endl;
-  ts << indent << "</amatrix>" << endl;
+  xml.writeStartElement(staticTypeTag);
+  xml.writeAttribute("tag", tag().tagString());
+  xml.writeAttribute("xmin", QString::number(minX()));
+  xml.writeAttribute("ymin", QString::number(minY()));
+  xml.writeAttribute("nx", QString::number(xNumSteps()));
+  xml.writeAttribute("ny", QString::number(yNumSteps()));
+  xml.writeAttribute("xstep", QString::number(xStepSize()));
+  xml.writeAttribute("ystep", QString::number(yStepSize()));
+  xml.writeTextElement("data", qCompress(qba).toBase64());
+  xml.writeEndElement();
 }
 
+
 }
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkst/editablematrix.h #733519:733520
@@ -23,8 +23,9 @@
   public:
     virtual const QString& typeString() const;
     static const QString staticTypeString;
+    static const QString staticTypeTag;
 
-    virtual void save(QTextStream &ts, const QString& indent = QString::null);
+    virtual void save(QXmlStreamWriter &xml);
 
   protected:
     EditableMatrix(ObjectStore *store, const ObjectTag& in_tag, uint nX=1, uint nY=1, double minX=0, double minY=0, double stepX=1, double stepY=1);
--- branches/work/kst/portto4/kst/src/libkst/generatedmatrix.cpp #733519:733520
@@ -22,6 +22,7 @@
 namespace Kst {
 
 const QString GeneratedMatrix::staticTypeString = I18N_NOOP("Generated Matrix");
+const QString GeneratedMatrix::staticTypeTag = I18N_NOOP("generatedmatrix");
 
 GeneratedMatrix::GeneratedMatrix(ObjectStore *store, const QDomElement &e) : Matrix(store) {
   double in_xMin = 0, in_yMin = 0, in_xStep = 1, in_yStep = 1;
@@ -84,7 +85,7 @@
 }
 
 void GeneratedMatrix::save(QXmlStreamWriter &xml) {
-  xml.writeStartElement("generatedmatrix");
+  xml.writeStartElement(staticTypeTag);
   xml.writeAttribute("tag", tag().tagString());
   xml.writeAttribute("xmin", QString::number(minX()));
   xml.writeAttribute("ymin", QString::number(minY()));
@@ -96,6 +97,7 @@
   xml.writeAttribute("gradzmax", QString::number(_gradZMax));
   xml.writeAttribute("xdirection", QVariant(_xDirection).toString());
   xml.writeEndElement();
+
 }
 
 void GeneratedMatrix::change(uint nX, uint nY, double minX, double minY,
--- branches/work/kst/portto4/kst/src/libkst/generatedmatrix.h #733519:733520
@@ -24,6 +24,7 @@
   public:
     virtual const QString& typeString() const;
     static const QString staticTypeString;
+    static const QString staticTypeTag;
 
     virtual void save(QXmlStreamWriter &xml);
 
--- branches/work/kst/portto4/kst/src/libkst/libkst.pro #733519:733520
@@ -15,91 +15,93 @@
 
 x11:!macx:PROCPS += sysinfo.c psversion.c
 SOURCES += \
-    object.cpp \
+    builtinprimitives.cpp \
     coredocument.cpp \
     datacollection.cpp \
+    datamatrix.cpp \
     datasource.cpp \
+    datasourcefactory.cpp \
+    datavector.cpp \
+    dateparser.cpp \
+    debug.cpp \
+    editablematrix.cpp \
+    editablevector.cpp \
     extension.cpp \
+    generatedmatrix.cpp \
+    generatedvector.cpp \
+    math_kst.cpp \
+    matrix.cpp \
+    matrixdefaults.cpp \
+    matrixfactory.cpp \
+    object.cpp \
+    objectlist.cpp \
+    objectmap.cpp \
     objectstore.cpp \
-    debug.cpp \
+    objecttag.cpp \
+    plotiteminterface.cpp \
+    primitive.cpp \
+    primitivefactory.cpp \
     rwlock.cpp \
-    math_kst.cpp \
-    dateparser.cpp \
-    #  Needs porting, but is unused anyway
-    #timezones.cpp \
     scalar.cpp \
     scalarfactory.cpp \
-    # $(PROCPS_COPY) \
-    $$PROCPS \
     string_kst.cpp \
     stringfactory.cpp \
-    matrix.cpp \
-    datamatrix.cpp \
-    generatedmatrix.cpp \
-    editablematrix.cpp \
     vector.cpp \
-    generatedvector.cpp \
-    editablevector.cpp \
-    datavector.cpp \
     vectordefaults.cpp \
-    matrixdefaults.cpp \
-    plotiteminterface.cpp \
-    primitive.cpp \
-    primitivefactory.cpp \
-    datasourcefactory.cpp \
-    objectlist.cpp \
-    objectmap.cpp \
-    objecttag.cpp \
-    builtinprimitives.cpp \
-    vectorfactory.cpp
+    vectorfactory.cpp \
+    #  Needs porting, but is unused anyway
+    #timezones.cpp \
+    # $(PROCPS_COPY) \
+    $$PROCPS 
 
 !win32:SOURCES += stdinsource.cpp
 
 HEADERS += \
-    datasourcefactory.h \
+    builtinprimitives.h \
     coredocument.h \
     datacollection.h \
-    editablematrix.h \
-    editablevector.h \
-    objectstore.h \
+    datamatrix.h \
     dataplugin.h \
     datasource.h \
+    datasourcefactory.h \
+    datavector.h \
     dateparser.h \
     debug.h \
+    editablematrix.h \
+    editablevector.h \
     events.h \
+    extension.h \
+    generatedmatrix.h \
+    generatedvector.h \
     kst_export.h \
-    extension.h \
     kst_i18n.h \
+    kstrevision.h \
+    ksttimers.h \
     index_kst.h \
+    logevents.h \
     math_kst.h \
+    matrix.h \
     matrixdefaults.h \
-    matrix.h \
+    matrixfactory.h \
     object.h \
+    objectlist.h \
+    objectmap.h \
+    objectstore.h \
+    objecttag.h \
     plotiteminterface.h \
     primitive.h \
-    kstrevision.h \
-    datamatrix.h \
-    datavector.h \
+    primitivefactory.h \
+    procps.h \
+    psversion.h \
+    rwlock.h \
     scalar.h \
     scalarfactory.h \
     sharedptr.h \
-    generatedmatrix.h \
+    stdinsource.h \
     string_kst.h \
     stringfactory.h \
-    generatedvector.h \
-    ksttimers.h \
+    sysinfo.h \
     timezones.h \
+    vector.h \
     vectordefaults.h \
-    vector.h \
-    logevents.h \
-    primitivefactory.h \
-    procps.h \
-    psversion.h \
-    rwlock.h \
-    stdinsource.h \
-    sysinfo.h \
-    objectlist.h \
-    objectmap.h \
-    objecttag.h \
-    builtinprimitives.h \
     vectorfactory.h
--- branches/work/kst/portto4/kst/src/libkst/matrix.cpp #733519:733520
@@ -587,5 +587,30 @@
   setDirty();
 }
 
+
+void Matrix::change(QByteArray &data, uint nX, uint nY, double minX, double minY, double stepX, double stepY) {
+  _nX = nX;
+  _nY = nY;
+  _stepX = stepX;
+  _stepY = stepY;
+  _minX = minX;
+  _minY = minY;
+
+  _saveable = true;
+  resizeZ(nX*nY, true);
+
+  QDataStream qds(&data, QIODevice::ReadOnly);
+  int i;
+  // fill in the raw array with the data
+  for (i = 0; i < nX*nY && !qds.atEnd(); i++) {
+    qds >> _z[i];  // stored in the same order as it was saved
+  }
+  if (i < nX*nY) {
+    Debug::self()->log(i18n("Saved matrix contains less data than it claims."), Debug::Warning);
+    resizeZ(i, false);
+  }
+  setDirty();
 }
+
+}
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkst/matrix.h #733519:733520
@@ -51,6 +51,9 @@
     void change(uint nX, uint nY, double minX=0, double minY=0,
         double stepX=1, double stepY=1);
 
+    void change(QByteArray& data, uint nX, uint nY, double minX=0, double minY=0,
+        double stepX=1, double stepY=1);
+
     // Return the sample count (x times y) of the matrix
     virtual int sampleCount() const;
 


More information about the Kst mailing list