[Kst] branches/work/kst/portto4/kst/src/datasources/ascii

Peter Kümmel syntheticpp at yahoo.com
Tue Mar 16 13:50:04 CET 2010


SVN commit 1103989 by kuemmel:

simplify load/save

 M  +22 -32    asciiplugin.cpp  
 M  +16 -2     asciisource.cpp  
 M  +4 -3      asciisource_p.h  


--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiplugin.cpp #1103988:1103989
@@ -130,29 +130,26 @@
 
 void ConfigWidgetAscii::load() {
 
-  settings().beginGroup(AsciiSource::Config::asciiTypeKey());
   AsciiSource::Config config;
-  config.readGroup(settings());
+  if (hasInstance())
+    config.readGroup(settings(), instance()->fileName());
+  else
+    config.readGroup(settings());
+
   _ac->setConfig(config);
 
+  // Now handle index
   _ac->_indexVector->clear();
   if (hasInstance()) {
-    _ac->_indexVector->addItems(instance()->fieldList());
     Kst::SharedPtr<AsciiSource> src = Kst::kst_cast<AsciiSource>(instance());
-    assert(src);
-    _ac->_indexType->setCurrentIndex(src->_config->_indexInterpretation - 1);
-    if (instance()->fieldList().contains(src->_config->_indexVector)) {
+    _ac->_indexVector->addItems(src->fieldList());
+    _ac->_indexVector->setCurrentIndex(src->_config->_indexInterpretation - 1);
+    if (src->fieldList().contains(src->_config->_indexVector)) {
       _ac->_indexVector->setEditText(src->_config->_indexVector);
     }
-
-    settings().beginGroup(src->fileName());
-    _ac->setConfig(config);
-    settings().endGroup();
-
   } else {
     _ac->_indexVector->addItem("INDEX");
-
-    int x = config._indexInterpretation; //settings().value("Default INDEX Interpretation", (int)AsciiSource::Config::INDEX).toInt();
+    int x = config._indexInterpretation;
     if (x > 0 && x <= _ac->_indexType->count()) {
       _ac->_indexType->setCurrentIndex(x - 1);
     } else {
@@ -160,30 +157,23 @@
     }
   }
   _ac->_indexVector->setEnabled(hasInstance());
-
-  settings().endGroup();
 }
 
+
 void ConfigWidgetAscii::save() {
-  settings().beginGroup(AsciiSource::Config::asciiTypeKey());
-  if (_ac->_applyDefault->isChecked()) {
-    _ac->config().save(settings());
-  }
+  if (hasInstance()) {
+    Kst::SharedPtr<AsciiSource> src = Kst::kst_cast<AsciiSource>(instance());
+    if (_ac->_applyDefault->isChecked()) {
+      _ac->config().saveGroup(settings());
+    }
+    _ac->config().saveGroup(settings(), src->fileName());
 
-  // If we have an instance, save settings for that instance as well
-  Kst::SharedPtr<AsciiSource> src = Kst::kst_cast<AsciiSource>(instance());
-  if (src) {
-    settings().beginGroup(src->fileName());
-    _ac->config().save(settings());
-    settings().endGroup();
+    // Update the instance from our new settings
+    if (src->reusable()) {
+      src->_config->readGroup(settings(), src->fileName());
+      src->reset();
+    }
   }
-  settings().endGroup();
-
-  // Update the instance from our new settings
-  if (src && src->reusable()) {
-    src->_config->readGroup(settings(), src->fileName());
-    src->reset();
-  }
 }
 
 
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1103988:1103989
@@ -114,6 +114,19 @@
 }
 
 
+void AsciiSource::Config::saveGroup(QSettings& cfg, const QString& fileName) {
+  cfg.beginGroup(asciiTypeString);
+  if (fileName.isEmpty()) {
+    save(cfg);
+  } else {
+    cfg.beginGroup(fileName);
+    save(cfg);
+    cfg.endGroup();
+  }
+  cfg.endGroup();
+}
+
+
 void AsciiSource::Config::read(QSettings& cfg) {
   _fileNamePattern << cfg;
   _indexVector << cfg;
@@ -131,8 +144,9 @@
 
 void AsciiSource::Config::readGroup(QSettings& cfg, const QString& fileName) {
   cfg.beginGroup(asciiTypeString);
-  read(cfg);
-  if (!fileName.isEmpty()) {
+  if (fileName.isEmpty()) {
+    read(cfg);
+  } else {
     cfg.beginGroup(fileName);
     read(cfg);
     cfg.endGroup();
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource_p.h #1103988:1103989
@@ -52,8 +52,7 @@
 
     static const QString asciiTypeKey();
 
-    void save(QSettings& cfg);
-    void read(QSettings& cfg);
+    void saveGroup(QSettings& cfg, const QString& fileName = QString());
     void readGroup(QSettings& cfg, const QString& fileName = QString());
 
     void save(QXmlStreamWriter& s);
@@ -80,7 +79,9 @@
 
     char _localSeparator;
 
-
+  private:
+    void save(QSettings& cfg);
+    void read(QSettings& cfg);
 };
 
 Q_DECLARE_METATYPE(AsciiSource::Config::Interpretation)


More information about the Kst mailing list