[Kst] kdeextragear-2/kst/kst/datasources/ascii

George Staikos staikos at kde.org
Thu Apr 14 01:24:50 CEST 2005


CVS commit by staikos: 

save and load settings to the Kst file.  Problem: we have no mechanism to ask
the source plugin to load yet.  I think I have to use the virtual hook for this.


  M +59 -3     ascii.cpp   1.53


--- kdeextragear-2/kst/kst/datasources/ascii/ascii.cpp  #1.52:1.53
@@ -89,4 +89,62 @@ class AsciiSource::Config {
     bool _readFields;
     int _fieldsLine;
+
+    void save(QTextStream& str, const QString& indent) {
+      if (_indexInterpretation != AsciiSource::Config::Unknown) {
+        str << indent << "<index vector=\"" << QStyleSheet::escape(_indexVector) << "\" interpretation=\"" << int(_indexInterpretation) << "\"/>" << endl;
+      }
+      str << indent << "<comment delimiters=\"" << QStyleSheet::escape(_delimiters) << "\"/>" << endl;
+      str << indent << "<columns type=\"" << int(_columnType) << "\"";
+      if (_columnType == Fixed) {
+        str << " width=\"" << _columnWidth << "\"";
+      } else if (_columnType == Custom) {
+        str << " delimiters=\"" << QStyleSheet::escape(_columnDelimiter) << "\"";
+      }
+      str << "/>" << endl;
+      str << indent << "<header start=\"" << _dataLine << "\"";
+      if (_readFields) {
+        str << " fields=\"" << _fieldsLine << "\"";
+      }
+      str << "/>" << endl;
+    }
+
+    void load(const QDomElement& e) {
+       QDomNode n = e.firstChild();
+       while (!n.isNull()) {
+         QDomElement e = n.toElement();
+         if (!e.isNull()) {
+           if (e.tagName() == "index") {
+             if (e.hasAttribute("vector")) {
+               _indexVector = e.attribute("vector");
+             }
+             if (e.hasAttribute("interpretation")) {
+               _indexInterpretation = Interpretation(e.attribute("interpretation").toInt());
+             }
+           } else if (e.tagName() == "comment") {
+             if (e.hasAttribute("delimiters")) {
+               _delimiters = e.attribute("delimiters");
+             }
+           } else if (e.tagName() == "columns") {
+             if (e.hasAttribute("type")) {
+               _columnType = ColumnType(e.attribute("type").toInt());
+             }
+             if (e.hasAttribute("width")) {
+               _columnWidth = e.attribute("width").toInt();
+             }
+             if (e.hasAttribute("delimiters")) {
+               _columnDelimiter = e.attribute("delimiters");
+             }
+           } else if (e.tagName() == "header") {
+             if (e.hasAttribute("start")) {
+               _dataLine = e.attribute("start").toInt();
+             }
+             if (e.hasAttribute("fields")) {
+               _fieldsLine = e.attribute("fields").toInt();
+             }
+           }
+         }
+         n = n.nextSibling();
+       }
+    }
 };
 
@@ -485,7 +543,5 @@ QStringList AsciiSource::fieldList() con
 void AsciiSource::save(QTextStream &ts, const QString& indent) {
   KstDataSource::save(ts, indent);
-  if (_config->_indexInterpretation != AsciiSource::Config::Unknown) {
-    ts << indent << "<index vector=\"" << QStyleSheet::escape(_config->_indexVector) << "\" interpretation=\"" << int(_config->_indexInterpretation) << "\"/>" << endl;
-  }
+  _config->save(ts, indent);
 }
 




More information about the Kst mailing list