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

Mike Fenton mike at staikos.net
Thu Nov 8 20:15:06 CET 2007


SVN commit 734388 by fenton:

Add Save/Restore for DataSources.
Modify loading of DataSources and addition of DataSources to ObjectStore.


 M  +2 -1      devel-docs/Kst2Specs/kstfile.txt  
 M  +25 -13    src/datasources/ascii/ascii.cpp  
 M  +1 -0      src/datasources/ascii/ascii.h  
 A             src/libkst/builtindatasources.cpp   [License: GPL (v2+)]
 A             src/libkst/builtindatasources.h   [License: GPL (v2+)]
 M  +0 -3      src/libkst/datamatrix.cpp  
 M  +27 -2     src/libkst/datasource.cpp  
 M  +4 -0      src/libkst/datasource.h  
 A             src/libkst/datasourcepluginfactory.cpp   [License: GPL (v2+)]
 A             src/libkst/datasourcepluginfactory.h   [License: GPL (v2+)]
 M  +0 -3      src/libkst/datavector.cpp  
 M  +4 -0      src/libkst/libkst.pro  
 M  +1 -5      src/libkst/matrixfactory.cpp  
 M  +14 -2     src/libkst/objectstore.cpp  
 M  +9 -13     src/libkst/vectorfactory.cpp  
 M  +2 -0      src/libkstapp/application.cpp  
 M  +1 -5      src/libkstapp/datawizard.cpp  
 M  +1 -1      src/libkstapp/document.cpp  
 M  +1 -5      src/libkstapp/matrixdialog.cpp  
 M  +1 -5      src/libkstapp/vectordialog.cpp  


--- branches/work/kst/portto4/kst/devel-docs/Kst2Specs/kstfile.txt #734387:734388
@@ -3,7 +3,8 @@
 
 <kst version="">
   <data>
-    <source name="" reader="">
+    <source tag="" reader="" file="">
+      <properties></properties>
     </source>
   </data>
   <variables>
--- branches/work/kst/portto4/kst/src/datasources/ascii/ascii.cpp #734387:734388
@@ -32,6 +32,7 @@
 #include <qspinbox.h>
 #include <qtextdocument.h>
 #include <QXmlStreamWriter>
+#include <QXmlStreamAttributes>
 
 #include <math_kst.h>
 #include "ascii.h"
@@ -94,31 +95,39 @@
     int _fieldsLine;
 
     void save(QXmlStreamWriter& s) {
+      s.writeStartElement("properties");
       if (_indexInterpretation != AsciiSource::Config::Unknown) {
-        s.writeStartElement("index");
         s.writeAttribute("vector", _indexVector);
         s.writeAttribute("interpretation", QString::number(int(_indexInterpretation)));
-        s.writeEndElement();
       }
-      s.writeStartElement("comment");
       s.writeAttribute("delimiters", _delimiters);
-      s.writeEndElement();
-      s.writeStartElement("columns");
-      s.writeAttribute("type", QString::number(int(_columnType)));
+
+      s.writeAttribute("columntype", QString::number(int(_columnType)));
       if (_columnType == Fixed) {
-        s.writeAttribute("width", QString::number(_columnWidth));
+        s.writeAttribute("columnwidth", QString::number(_columnWidth));
       } else if (_columnType == Custom) {
-        s.writeAttribute("delimiters", _columnDelimiter);
+        s.writeAttribute("columndelimiters", _columnDelimiter);
       }
-      s.writeEndElement();
-      s.writeStartElement("header");
-      s.writeAttribute("start", QString::number(_dataLine));
+
+      s.writeAttribute("headerstart", QString::number(_dataLine));
       if (_readFields) {
         s.writeAttribute("fields", QString::number(_fieldsLine));
       }
       s.writeEndElement();
     }
 
+    void parseProperties(QXmlStreamAttributes &properties) {
+      _indexVector = properties.value("vector").toString();
+      _indexInterpretation = (Interpretation)properties.value("interpretation").toString().toInt();
+
+      _delimiters = properties.value("delimiters").toString();
+      _columnType = (ColumnType)properties.value("columntype").toString().toInt();
+      _columnDelimiter = properties.value("columndelimiters").toString().toInt();
+
+      _dataLine = properties.value("headerstart").toString().toInt();
+      _fieldsLine = properties.value("fields").toString().toInt();
+    }
+
     void load(const QDomElement& e) {
        QDomNode n = e.firstChild();
        while (!n.isNull()) {
@@ -168,7 +177,6 @@
   if (!type.isEmpty() && type != "ASCII") {
     return;
   }
-
   _config = new AsciiSource::Config;
   _config->read(cfg, filename);
   if (!e.isNull()) {
@@ -749,6 +757,11 @@
 }
 
 
+void AsciiSource::parseProperties(QXmlStreamAttributes &properties) {
+  _config->parseProperties(properties);
+}
+
+
 bool AsciiSource::supportsTimeConversions() const {
   return false; //fieldList().contains(_config->_indexVector) && _config->_indexInterpretation != AsciiSource::Config::Unknown && _config->_indexInterpretation != AsciiSource::Config::INDEX;
 }
@@ -915,7 +928,6 @@
                                             const QString &filename,
                                             const QString &type,
                                             const QDomElement &element) const {
-
   return new AsciiSource(store, cfg, filename, type, element);
 }
 
--- branches/work/kst/portto4/kst/src/datasources/ascii/ascii.h #734387:734388
@@ -57,6 +57,7 @@
     QStringList matrixList() const;
 
     void save(QXmlStreamWriter &s);
+    void parseProperties(QXmlStreamAttributes &properties);
 
     bool isEmpty() const;
 
--- branches/work/kst/portto4/kst/src/libkst/datamatrix.cpp #734387:734388
@@ -514,9 +514,6 @@
         }
         _file = newsrc;
         _file->writeLock();
-        if (store()) {
-          store()->addObject<DataSource>(_file);
-        }
         reset();
       }
     }
--- branches/work/kst/portto4/kst/src/libkst/datasource.cpp #734387:734388
@@ -43,6 +43,7 @@
 namespace Kst {
 
 const QString DataSource::staticTypeString = I18N_NOOP("Data Source");
+const QString DataSource::staticTypeTag = I18N_NOOP("source");
 
 static QSettings *settingsObject = 0L;
 static QMap<QString,QString> urlMap;
@@ -234,16 +235,35 @@
     return new StdinSource(0, settingsObject);
   }
 #endif
-
   QString fn = obtainFile(filename);
   if (fn.isEmpty()) {
     return 0L;
   }
 
-  return findPluginFor(store, fn, type);
+  DataSourcePtr dataSource = findPluginFor(store, fn, type);
+  if (dataSource) {
+    store->addObject<DataSource>(dataSource);
+  }
+
+  return dataSource;
+
 }
 
 
+DataSourcePtr DataSource::findOrLoadSource(ObjectStore *store, const QString& filename) {
+  Q_ASSERT(store);
+  DataSourcePtr dataSource = store->dataSourceList().findReusableFileName(filename);
+
+  if (!dataSource) {
+    dataSource = DataSource::loadSource(store, filename);
+  }
+
+  return dataSource;
+}
+
+
+
+
 bool DataSource::hasConfigWidget() const {
   return sourceHasConfigWidget(_filename, fileType());
 }
@@ -662,6 +682,11 @@
 }
 
 
+void DataSource::parseProperties(QXmlStreamAttributes &properties) {
+  Q_UNUSED(properties);
+}
+
+
 void *DataSource::bufferMalloc(size_t size) {
   return malloc(size);
 }
--- branches/work/kst/portto4/kst/src/libkst/datasource.h #734387:734388
@@ -34,6 +34,7 @@
 #include "scalar.h"
 
 class QXmlStreamWriter;
+class QXmlStreamAttributes;
 
 namespace KST {
   class DataSourcePlugin;
@@ -68,6 +69,7 @@
 
     static SharedPtr<DataSource> loadSource(ObjectStore *store, const QString& filename, const QString& type = QString::null);
     static SharedPtr<DataSource> loadSource(ObjectStore *store, QDomElement& e);
+    static SharedPtr<DataSource> findOrLoadSource(ObjectStore *store, const QString& filename);
     static QStringList fieldListForSource(const QString& filename, const QString& type = QString(), QString *outType = 0L, bool *complete = 0L);
     static QStringList matrixListForSource(const QString& filename, const QString& type = QString(), QString *outType = 0L, bool *complete = 0L);
 
@@ -84,9 +86,11 @@
 
     virtual const QString& typeString() const;
     static const QString staticTypeString;
+    static const QString staticTypeTag;
 
     bool hasConfigWidget() const;
     DataSourceConfigWidget *configWidget();
+    virtual void parseProperties(QXmlStreamAttributes &properties);
 
     // @since 1.1.0
     bool reusable() const;
--- branches/work/kst/portto4/kst/src/libkst/datavector.cpp #734387:734388
@@ -745,9 +745,6 @@
         _dontUseSkipAccel = false;
         _file = newsrc;
         _file->writeLock();
-        if (store()) {
-          store()->addObject<DataSource>(_file);
-        }
         reset();
       }
     }
--- branches/work/kst/portto4/kst/src/libkst/libkst.pro #734387:734388
@@ -15,12 +15,14 @@
 
 x11:!macx:PROCPS += sysinfo.c psversion.c
 SOURCES += \
+    builtindatasources.cpp \
     builtinprimitives.cpp \
     coredocument.cpp \
     datacollection.cpp \
     datamatrix.cpp \
     datasource.cpp \
     datasourcefactory.cpp \
+    datasourcepluginfactory.cpp \
     datavector.cpp \
     dateparser.cpp \
     debug.cpp \
@@ -57,6 +59,7 @@
 !win32:SOURCES += stdinsource.cpp
 
 HEADERS += \
+    builtindatasources.h \
     builtinprimitives.h \
     coredocument.h \
     datacollection.h \
@@ -64,6 +67,7 @@
     dataplugin.h \
     datasource.h \
     datasourcefactory.h \
+    datasourcepluginfactory.h \
     datavector.h \
     dateparser.h \
     debug.h \
--- branches/work/kst/portto4/kst/src/libkst/matrixfactory.cpp #734387:734388
@@ -204,13 +204,9 @@
   }
 
   Q_ASSERT(store);
-  DataSourcePtr dataSource = store->dataSourceList().findReusableFileName(file);
+  DataSourcePtr dataSource = DataSource::findOrLoadSource(store, file);
 
   if (!dataSource) {
-    dataSource = DataSource::loadSource(store, file, QString());
-  }
-
-  if (!dataSource) {
     return 0; //Couldn't find a suitable datasource
   }
 
--- branches/work/kst/portto4/kst/src/libkst/objectstore.cpp #734387:734388
@@ -228,8 +228,16 @@
 
   KstWriteLocker l(&this->_lock);
 
-  if (!_list.contains(o)) {
+  DataSourcePtr ds = kst_cast<DataSource>(o);
+  if (ds) {
+    if (!_dataSourceList.contains(ds)) {
 #if NAMEDEBUG > 1
+      qDebug() << "Trying to delete a non-existant data source from the store: " << ds->tag().tagString();
+#endif
+      return false;
+    }
+  } else if (!_list.contains(o)) {
+#if NAMEDEBUG > 1
     qDebug() << "Trying to delete a non-existant object from the store: " << o->tag().tagString();
 #endif
     return false;
@@ -263,7 +271,11 @@
 #if NAMEDEBUG > 2
     qDebug() << "  removing object from list";
 #endif
-    _list.removeAll(o);
+    if (ds) {
+      _dataSourceList.removeAll(ds);
+    } else {
+      _list.removeAll(o);
+    }
   }
 
   o->_store = 0;
--- branches/work/kst/portto4/kst/src/libkst/vectorfactory.cpp #734387:734388
@@ -40,7 +40,7 @@
   while (!xml.atEnd()) {
       const QString n = xml.name().toString();
     if (xml.isStartElement()) {
-      if (n == "vector") {
+      if (n == Vector::staticTypeTag) {
         QXmlStreamAttributes attrs = xml.attributes();
         tag = ObjectTag::fromString(attrs.value("tag").toString());
       } else if (n == "data") {
@@ -53,7 +53,7 @@
         return 0;
       }
     } else if (xml.isEndElement()) {
-      if (n == "vector") {
+      if (n == Vector::staticTypeTag) {
         break;
       } else {
         Debug::self()->log(QObject::tr("Error creating vector from Kst file."), Debug::Warning);
@@ -96,7 +96,7 @@
   while (!xml.atEnd()) {
       const QString n = xml.name().toString();
     if (xml.isStartElement()) {
-      if (n == "generatedvector") {
+      if (n == GeneratedVector::staticTypeTag) {
         QXmlStreamAttributes attrs = xml.attributes();
         tag = ObjectTag::fromString(attrs.value("tag").toString());
         min = attrs.value("min").toString().toDouble();
@@ -106,7 +106,7 @@
         return 0;
       }
     } else if (xml.isEndElement()) {
-      if (n == "generatedvector") {
+      if (n == GeneratedVector::staticTypeTag) {
         break;
       } else {
         Debug::self()->log(QObject::tr("Error creating generated vector from Kst file."), Debug::Warning);
@@ -147,7 +147,7 @@
   while (!xml.atEnd()) {
       const QString n = xml.name().toString();
     if (xml.isStartElement()) {
-      if (n == "editablevector") {
+      if (n == EditableVector::staticTypeTag) {
         QXmlStreamAttributes attrs = xml.attributes();
         tag = ObjectTag::fromString(attrs.value("tag").toString());
       } else if (n == "data") {
@@ -159,7 +159,7 @@
         return 0;
       }
     } else if (xml.isEndElement()) {
-      if (n == "editablevector") {
+      if (n == EditableVector::staticTypeTag) {
         break;
       } else {
         Debug::self()->log(QObject::tr("Error creating vector from Kst file."), Debug::Warning);
@@ -204,7 +204,7 @@
   while (!xml.atEnd()) {
       const QString n = xml.name().toString();
     if (xml.isStartElement()) {
-      if (n == "datavector") {
+      if (n == DataVector::staticTypeTag) {
         QXmlStreamAttributes attrs = xml.attributes();
         tag = ObjectTag::fromString(attrs.value("tag").toString());
 
@@ -226,7 +226,7 @@
         return 0;
       }
     } else if (xml.isEndElement()) {
-      if (n == "datavector") {
+      if (n == DataVector::staticTypeTag) {
         break;
       } else {
         Debug::self()->log(QObject::tr("Error creating vector from Kst file."), Debug::Warning);
@@ -241,13 +241,9 @@
   }
 
   Q_ASSERT(store);
-  DataSourcePtr dataSource = store->dataSourceList().findReusableFileName(file);
+  DataSourcePtr dataSource = DataSource::findOrLoadSource(store, file);
 
   if (!dataSource) {
-    dataSource = DataSource::loadSource(store, file, QString());
-  }
-
-  if (!dataSource) {
     return 0; //Couldn't find a suitable datasource
   }
 
--- branches/work/kst/portto4/kst/src/libkstapp/application.cpp #734387:734388
@@ -13,6 +13,7 @@
 #include "qgetoptions.h"
 
 #include "builtinprimitives.h"
+#include "builtindatasources.h"
 #include "builtinobjects.h"
 #include "builtingraphics.h"
 #include "builtinrelations.h"
@@ -30,6 +31,7 @@
   QCoreApplication::setApplicationName("Kst");
 
   Builtins::initPrimitives(); //libkst
+  Builtins::initDataSources(); //libkst
   Builtins::initObjects();    //libkstmath
   Builtins::initRelations();  //libkstmath
   Builtins::initGraphics();   //libkstapp
--- branches/work/kst/portto4/kst/src/libkstapp/datawizard.cpp #734387:734388
@@ -76,13 +76,9 @@
     return;
 
   Q_ASSERT(_store);
-  _dataSource = _store->dataSourceList().findReusableFileName(file);
+  _dataSource = DataSource::findOrLoadSource(_store, file);
 
   if (!_dataSource) {
-    _dataSource = DataSource::loadSource(_store, file, QString());
-  }
-
-  if (!_dataSource) {
     _pageValid = false;
     _configureSource->setEnabled(false);
     return; //Couldn't find a suitable datasource
--- branches/work/kst/portto4/kst/src/libkstapp/document.cpp #734387:734388
@@ -77,7 +77,7 @@
   xml.writeAttribute("version", "2.0");
 
   xml.writeStartElement("data");
-  foreach (DataSourcePtr s, objectStore()->getObjects<DataSource>()) {
+  foreach (DataSourcePtr s, objectStore()->dataSourceList()) {
     s->saveSource(xml);
   }
   xml.writeEndElement();
--- branches/work/kst/portto4/kst/src/libkstapp/matrixdialog.cpp #734387:734388
@@ -365,13 +365,9 @@
   _field->clear();
 
   Q_ASSERT(_store);
-  _dataSource = _store->dataSourceList().findReusableFileName(file);
+  _dataSource = DataSource::findOrLoadSource(_store, file);
 
   if (!_dataSource) {
-    _dataSource = DataSource::loadSource(_store, file, QString());
-  }
-
-  if (!_dataSource) {
     _field->setEnabled(false);
     _configure->setEnabled(false);
     return; //Couldn't find a suitable datasource
--- branches/work/kst/portto4/kst/src/libkstapp/vectordialog.cpp #734387:734388
@@ -166,13 +166,9 @@
   _field->clear();
 
   Q_ASSERT(_store);
-  _dataSource = _store->dataSourceList().findReusableFileName(file);
+  _dataSource = DataSource::findOrLoadSource(_store, file);
 
   if (!_dataSource) {
-    _dataSource = DataSource::loadSource(_store, file, QString());
-  }
-
-  if (!_dataSource) {
     _field->setEnabled(false);
     _configure->setEnabled(false);
     return; //Couldn't find a suitable datasource


More information about the Kst mailing list