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

Peter Kümmel syntheticpp at gmx.net
Thu Aug 12 14:46:40 CEST 2010


SVN commit 1162698 by kuemmel:

prepare for better data source path handling:
    - encapsulate path saving/loading to kst file

 M  +1 -3      datamatrix.cpp  
 M  +23 -0     dataprimitive.cpp  
 M  +9 -0      dataprimitive.h  
 M  +1 -3      datascalar.cpp  
 M  +1 -1      datasource.cpp  
 M  +1 -1      datasourcepluginfactory.cpp  
 M  +1 -3      datastring.cpp  
 M  +1 -3      datavector.cpp  
 M  +1 -1      matrixfactory.cpp  
 M  +2 -2      scalarfactory.cpp  
 M  +1 -1      vectorfactory.cpp  
 M  +1 -1      vscalar.cpp  


--- branches/work/kst/portto4/kst/src/libkst/datamatrix.cpp #1162697:1162698
@@ -59,9 +59,7 @@
   if (file()) {
     xml.writeStartElement(staticTypeTag);
 
-    file()->readLock();
-    xml.writeAttribute("file", file()->fileName());
-    file()->unlock();
+    saveFilename(xml);
 
     xml.writeAttribute("field", _field);
     xml.writeAttribute("reqxstart", QString::number(_reqXStart));
--- branches/work/kst/portto4/kst/src/libkst/dataprimitive.cpp #1162697:1162698
@@ -20,6 +20,8 @@
 
 #include "datasource.h"
 
+#include <QXmlStreamWriter>
+
 namespace Kst {
 
 
@@ -56,6 +58,27 @@
 }
 
 
+void DataPrimitive::saveFilename(QXmlStreamWriter& s) {
+  if (d._file) {
+    file()->readLock();
+    s.writeAttribute("file", d._file->fileName());
+    file()->unlock();
+  }
+}
+
+
+void DataPrimitive::saveFilename(const QString& fileName, QXmlStreamWriter& s)
+{
+    s.writeAttribute("file", fileName);
+}
+
+
+QString DataPrimitive::readFilename(const QXmlStreamAttributes& attrs)
+{
+    return attrs.value("file").toString();
+}
+
+
 /** return the field */
 const QString& DataPrimitive::field() const {
   return _field;
--- branches/work/kst/portto4/kst/src/libkst/dataprimitive.h #1162697:1162698
@@ -25,6 +25,8 @@
 
 #include <QString>
 
+class QXmlStreamWriter;
+class QXmlStreamAttributes;
 
 namespace Kst {
 
@@ -41,6 +43,13 @@
     /** return the name of the file */
     QString filename() const;
 
+    /** save filename to xml stream */
+    void saveFilename(QXmlStreamWriter&);
+    static void saveFilename(const QString&, QXmlStreamWriter&);
+
+    static QString readFilename(const QXmlStreamAttributes&);
+
+
     /** return the field name */
     const QString& field() const;
 
--- branches/work/kst/portto4/kst/src/libkst/datascalar.cpp #1162697:1162698
@@ -85,9 +85,7 @@
 void DataScalar::save(QXmlStreamWriter &s) {
   if (file()) {
     s.writeStartElement("datascalar");
-    file()->readLock();
-    s.writeAttribute("file", file()->fileName());
-    file()->unlock();
+    saveFilename(s);
     s.writeAttribute("field", _field);
 
     saveNameInfo(s, XNUM);
--- branches/work/kst/portto4/kst/src/libkst/datasource.cpp #1162697:1162698
@@ -270,7 +270,7 @@
   }
   s.writeStartElement("source");
   s.writeAttribute("reader", fileType());
-  s.writeAttribute("file", name);
+  DataPrimitive::saveFilename(name, s);
   save(s);
   s.writeEndElement();
 }
--- branches/work/kst/portto4/kst/src/libkst/datasourcepluginfactory.cpp #1162697:1162698
@@ -42,7 +42,7 @@
       if (n == DataSource::staticTypeTag) {
         QXmlStreamAttributes attrs = xml.attributes();
         fileType = attrs.value("reader").toString();
-        fileName = attrs.value("file").toString();
+        fileName = DataPrimitive::readFilename(attrs);
       } else if (n == "properties") {
         propertyAttributes = xml.attributes();
         xml.readElementText();
--- branches/work/kst/portto4/kst/src/libkst/datastring.cpp #1162697:1162698
@@ -83,9 +83,7 @@
 void DataString::save(QXmlStreamWriter &s) {
   if (file()) {
     s.writeStartElement("datastring");
-    file()->readLock();
-    s.writeAttribute("file", file()->fileName());
-    file()->unlock();
+    saveFilename(s);
     s.writeAttribute("field", _field);
 
     saveNameInfo(s, XNUM);
--- branches/work/kst/portto4/kst/src/libkst/datavector.cpp #1162697:1162698
@@ -274,9 +274,7 @@
 void DataVector::save(QXmlStreamWriter &s) {
   if (file()) {
     s.writeStartElement("datavector");
-    file()->readLock();
-    s.writeAttribute("file", file()->fileName());
-    file()->unlock();
+    saveFilename(s);
     s.writeAttribute("field", _field);
 
     s.writeAttribute("start", QString::number(ReqF0));
--- branches/work/kst/portto4/kst/src/libkst/matrixfactory.cpp #1162697:1162698
@@ -186,7 +186,7 @@
       if (n == DataMatrix::staticTypeTag) {
         QXmlStreamAttributes attrs = xml.attributes();
         provider = attrs.value("provider").toString();
-        file = attrs.value("file").toString();
+        file = DataPrimitive::readFilename(attrs);
         field = attrs.value("field").toString();
         requestedXStart = attrs.value("reqxstart").toString().toInt();
         requestedYStart = attrs.value("reqystart").toString().toInt();
--- branches/work/kst/portto4/kst/src/libkst/scalarfactory.cpp #1162697:1162698
@@ -101,7 +101,7 @@
       if (n == DataScalar::staticTypeTag) {
         QXmlStreamAttributes attrs = xml.attributes();
         provider = attrs.value("provider").toString();
-        file = attrs.value("file").toString();
+        file = DataPrimitive::readFilename(attrs);
         field = attrs.value("field").toString();
 
         if (attrs.value("descriptiveNameIsManual").toString() == "true") {
@@ -170,7 +170,7 @@
       if (n == VScalar::staticTypeTag) {
         QXmlStreamAttributes attrs = xml.attributes();
         provider = attrs.value("provider").toString();
-        file = attrs.value("file").toString();
+        file = DataPrimitive::readFilename(attrs);
         field = attrs.value("field").toString();
         f0 = attrs.value("f0").toString().toInt();
         if (attrs.value("descriptiveNameIsManual").toString() == "true") {
--- branches/work/kst/portto4/kst/src/libkst/vectorfactory.cpp #1162697:1162698
@@ -221,7 +221,7 @@
         QXmlStreamAttributes attrs = xml.attributes();
 
         //provider = attrs.value("provider").toString();
-        file = attrs.value("file").toString();
+        file = DataPrimitive::readFilename(attrs);
         field = attrs.value("field").toString();
         start = attrs.value("start").toString().toInt();
         count = attrs.value("count").toString().toInt();
--- branches/work/kst/portto4/kst/src/libkst/vscalar.cpp #1162697:1162698
@@ -101,7 +101,7 @@
 
     _file->readLock();
     s.writeAttribute("provider", _file->Name());
-    s.writeAttribute("file", _file->fileName());
+    DataPrimitive::saveFilename(_file->fileName(), s);
     _file->unlock();
 
     s.writeAttribute("field", _field);


More information about the Kst mailing list