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

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


SVN commit 1103988 by kuemmel:

cleanup DataSourceConfigWidget

 M  +31 -41    datasources/ascii/asciiplugin.cpp  
 M  +12 -15    libkst/datasource.cpp  
 M  +30 -26    libkst/datasource.h  


--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiplugin.cpp #1103987:1103988
@@ -81,15 +81,15 @@
 
 void ConfigWidgetAsciiInternal::setConfig(const AsciiSource::Config& config)
 {
-  _delimiters->setText(config._delimiters);// _cfg->value("Comment Delimiters", DEFAULT_DELIMITERS).toString());
-  _fileNamePattern->setText(config._fileNamePattern); // _cfg->value("Filename Pattern").toString());
-  _columnDelimiter->setText(config._columnDelimiter); // _cfg->value("Column Delimiter").toString());
-  _columnWidth->setValue(config._columnWidth); //_cfg->value("Column Width", DEFAULT_COLUMN_WIDTH).toInt());
-  _startLine->setValue(config._dataLine); //_cfg->value("Data Start", 0).toInt());
-  _readFields->setChecked(config._readFields); //_cfg->value("Read Fields", false).toBool());
-  _useDot->setChecked(config._useDot); //_cfg->value("Use Dot", true).toBool());
-  _fieldsLine->setValue(config._fieldsLine); //_cfg->value("Fields Line", 0).toInt());
-  AsciiSource::Config::ColumnType ct = config._columnType; //(AsciiSource::Config::ColumnType)_cfg->value("Column Type", 0).toInt();
+  _delimiters->setText(config._delimiters);// settings().value("Comment Delimiters", DEFAULT_DELIMITERS).toString());
+  _fileNamePattern->setText(config._fileNamePattern); // settings().value("Filename Pattern").toString());
+  _columnDelimiter->setText(config._columnDelimiter); // settings().value("Column Delimiter").toString());
+  _columnWidth->setValue(config._columnWidth); //settings().value("Column Width", DEFAULT_COLUMN_WIDTH).toInt());
+  _startLine->setValue(config._dataLine); //settings().value("Data Start", 0).toInt());
+  _readFields->setChecked(config._readFields); //settings().value("Read Fields", false).toBool());
+  _useDot->setChecked(config._useDot); //settings().value("Use Dot", true).toBool());
+  _fieldsLine->setValue(config._fieldsLine); //settings().value("Fields Line", 0).toInt());
+  AsciiSource::Config::ColumnType ct = config._columnType; //(AsciiSource::Config::ColumnType)settings().value("Column Type", 0).toInt();
   if (ct == AsciiSource::Config::Fixed) {
     _fixed->setChecked(true);
   } else if (ct == AsciiSource::Config::Custom) {
@@ -106,11 +106,9 @@
 
 class ConfigWidgetAscii : public Kst::DataSourceConfigWidget {
   public:
-    ConfigWidgetAscii();
+    ConfigWidgetAscii(QSettings&);
     ~ConfigWidgetAscii();
 
-
-    void setConfig(QSettings *cfg);
     void load();
     void save();
 
@@ -118,7 +116,7 @@
 };
 
 
-ConfigWidgetAscii::ConfigWidgetAscii() : Kst::DataSourceConfigWidget() {
+ConfigWidgetAscii::ConfigWidgetAscii(QSettings& s) : Kst::DataSourceConfigWidget(s) {
   QGridLayout *layout = new QGridLayout(this);
   _ac = new ConfigWidgetAsciiInternal(this);
   layout->addWidget(_ac, 0, 0);
@@ -130,67 +128,60 @@
 }
 
 
-void ConfigWidgetAscii::setConfig(QSettings *cfg) {
-  Kst::DataSourceConfigWidget::setConfig(cfg);
-}
-
-
 void ConfigWidgetAscii::load() {
 
-  _cfg->beginGroup(AsciiSource::Config::asciiTypeKey());
+  settings().beginGroup(AsciiSource::Config::asciiTypeKey());
   AsciiSource::Config config;
-  config.readGroup(*_cfg);
+  config.readGroup(settings());
   _ac->setConfig(config);
 
-  bool hasInstance = (_instance != 0L);
   _ac->_indexVector->clear();
-  if (hasInstance) {
-    _ac->_indexVector->addItems(_instance->fieldList());
-    Kst::SharedPtr<AsciiSource> src = Kst::kst_cast<AsciiSource>(_instance);
+  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)) {
+    if (instance()->fieldList().contains(src->_config->_indexVector)) {
       _ac->_indexVector->setEditText(src->_config->_indexVector);
     }
 
-    _cfg->beginGroup(src->fileName());
+    settings().beginGroup(src->fileName());
     _ac->setConfig(config);
-    _cfg->endGroup();
+    settings().endGroup();
 
   } else {
     _ac->_indexVector->addItem("INDEX");
 
-    int x = config._indexInterpretation; //_cfg->value("Default INDEX Interpretation", (int)AsciiSource::Config::INDEX).toInt();
+    int x = config._indexInterpretation; //settings().value("Default INDEX Interpretation", (int)AsciiSource::Config::INDEX).toInt();
     if (x > 0 && x <= _ac->_indexType->count()) {
       _ac->_indexType->setCurrentIndex(x - 1);
     } else {
       _ac->_indexType->setCurrentIndex(0);
     }
   }
-  _ac->_indexVector->setEnabled(hasInstance);
+  _ac->_indexVector->setEnabled(hasInstance());
 
-  _cfg->endGroup();
+  settings().endGroup();
 }
 
 void ConfigWidgetAscii::save() {
-  assert(_cfg);
-  _cfg->beginGroup(AsciiSource::Config::asciiTypeKey());
+  settings().beginGroup(AsciiSource::Config::asciiTypeKey());
   if (_ac->_applyDefault->isChecked()) {
-    _ac->config().save(*_cfg);
+    _ac->config().save(settings());
   }
 
   // If we have an instance, save settings for that instance as well
-  Kst::SharedPtr<AsciiSource> src = Kst::kst_cast<AsciiSource>(_instance);
+  Kst::SharedPtr<AsciiSource> src = Kst::kst_cast<AsciiSource>(instance());
   if (src) {
-    _cfg->beginGroup(src->fileName());
-    _ac->config().save(*_cfg);
-    _cfg->endGroup();
+    settings().beginGroup(src->fileName());
+    _ac->config().save(settings());
+    settings().endGroup();
   }
-  _cfg->endGroup();
+  settings().endGroup();
 
   // Update the instance from our new settings
   if (src && src->reusable()) {
-    src->_config->readGroup(*_cfg, src->fileName());
+    src->_config->readGroup(settings(), src->fileName());
     src->reset();
   }
 }
@@ -402,8 +393,7 @@
 
 Kst::DataSourceConfigWidget *AsciiPlugin::configWidget(QSettings *cfg, const QString& filename) const {
   Q_UNUSED(filename)
-  ConfigWidgetAscii *config = new ConfigWidgetAscii;
-  config->setConfig(cfg);
+  ConfigWidgetAscii *config = new ConfigWidgetAscii(*cfg);
   config->load();
   return config;
 }
--- branches/work/kst/portto4/kst/src/libkst/datasource.cpp #1103987:1103988
@@ -122,7 +122,7 @@
     //try a cast
     if (DataSourcePluginInterface *ds = dynamic_cast<DataSourcePluginInterface*>(plugin)) {
       tmpList.append(ds);
-    } 
+    }
   }
 
   QStringList pluginPaths;
@@ -956,8 +956,8 @@
 }
 
 /////////////////////////////////////////////////////////////////////////////
-DataSourceConfigWidget::DataSourceConfigWidget()
-: QWidget(0L), _cfg(0L) {
+DataSourceConfigWidget::DataSourceConfigWidget(QSettings& settings)
+: QWidget(0L), _cfg(settings) {
 }
 
 
@@ -965,30 +965,27 @@
 }
 
 
-void DataSourceConfigWidget::save() {
+void DataSourceConfigWidget::setInstance(DataSourcePtr inst) {
+  _instance = inst;
 }
 
 
-void DataSourceConfigWidget::load() {
+DataSourcePtr DataSourceConfigWidget::instance() const {
+  return _instance;
 }
 
 
-void DataSourceConfigWidget::setConfig(QSettings *cfg) {
-  _cfg = cfg;
+QSettings& DataSourceConfigWidget::settings() const {
+  return _cfg;
 }
 
 
-void DataSourceConfigWidget::setInstance(DataSourcePtr inst) {
-  _instance = inst;
+bool DataSourceConfigWidget::hasInstance() const {
+  return _instance != 0L;
 }
 
 
-DataSourcePtr DataSourceConfigWidget::instance() const {
-  return _instance;
-}
-
-
-ValidateDataSourceThread::ValidateDataSourceThread(const QString& file, const int requestID) : QRunnable(), 
+ValidateDataSourceThread::ValidateDataSourceThread(const QString& file, const int requestID) : QRunnable(),
   _file(file),
   _requestID(requestID) {
 }
--- branches/work/kst/portto4/kst/src/libkst/datasource.h #1103987:1103988
@@ -221,7 +221,7 @@
     /** Returns a list of scalars associated with a field by the data source.
         These could be sample rate, calibrations, etc.  This list must be
         complete the very first time it is called and must never change its
-        order or size, because readFieldScalars counts on its order and size. 
+        order or size, because readFieldScalars counts on its order and size.
         */
     virtual QStringList fieldScalars(const QString& field);
 
@@ -229,29 +229,29 @@
         every time the vector is updated, so it needs to be kept very cheap.
         Returns the number of scalars returned, and 0 on failure. V must
         be pre allocated to the right size as given by the length of the list
-        returned by fieldScalars(). 
-        Most data sources will never change the the field scalars once they have 
-        been initialized.  In order to keep this case as fast as possible, the data 
-        source can chose to only update v[] if init is true.  
-        Note: datavector currently assumes these never change, and only gets them once! */ 
+        returned by fieldScalars().
+        Most data sources will never change the the field scalars once they have
+        been initialized.  In order to keep this case as fast as possible, the data
+        source can chose to only update v[] if init is true.
+        Note: datavector currently assumes these never change, and only gets them once! */
     virtual int readFieldScalars(QList<double> &v, const QString& field, bool init);
 
     /** Returns a list of strings associated with a field by the data source.
         These could be units, notes, etc.  This list must be
         complete the very first time it is called and must never change its
-        order or size, because readFieldScalars counts on its order and size. 
+        order or size, because readFieldScalars counts on its order and size.
         In order to remain fast, the data source can additionally assume that
         readField() has already been called on the field, so the updating
         of string values can be done there instead and cached for read by this
         call.  */
     virtual QStringList fieldStrings(const QString& field);
 
-    /** Read the values of the field strings.  This is called 
+    /** Read the values of the field strings.  This is called
         every time the vector is updated, so it needs to be kept very cheap.
-        Returns the number of strings returned, and 0 on failure. 
-        Most data sources will never change the the field strings once they have 
-        been initialized.  In order to keep this case as fast as possible, the data 
-        source can chose to only update v if init is true.  */ 
+        Returns the number of strings returned, and 0 on failure.
+        Most data sources will never change the the field strings once they have
+        been initialized.  In order to keep this case as fast as possible, the data
+        source can chose to only update v if init is true.  */
     virtual int readFieldStrings(QStringList &v, const QString& field, bool init);
 
     /************************************************************/
@@ -267,7 +267,7 @@
         yStart - starting y *frame*
         xNumSteps - number of *frames* to read in x direction; -1 to read 1 *sample* from xStart
         yNumSteps - number of *frames* to read in y direction; -1 to read 1 *sample* from yStart
-        Will skip according to the parameter, but it may not be implemented.  If return value is -9999, 
+        Will skip according to the parameter, but it may not be implemented.  If return value is -9999,
         use the non-skip version instead.
         The suggested scaling and translation is returned in xMin, yMin, xStepSize, and yStepSize
         Returns the number of *samples* read **/
@@ -424,29 +424,33 @@
 
 
 // @since 1.1.0
-class DataSourceConfigWidget : public QWidget {
+class KST_EXPORT DataSourceConfigWidget : public QWidget
+{
   Q_OBJECT
-  friend class DataSource;
+
   public:
-    DataSourceConfigWidget(); // will be reparented later
+    DataSourceConfigWidget(QSettings&); // will be reparented later
     virtual ~DataSourceConfigWidget();
 
-    virtual void setConfig(QSettings*);
+    QSettings& settings() const;
 
-    KST_EXPORT void setInstance(DataSourcePtr inst);
-    KST_EXPORT DataSourcePtr instance() const;
+    // If _instance is nonzero, then your settings are to be saved for this
+    // particular instance of the source, as opposed to globally.
+    void setInstance(DataSourcePtr inst);
+    DataSourcePtr instance() const;
+    bool hasInstance() const;
 
   public slots:
-    virtual void load();
-    virtual void save();
+    virtual void load() = 0;
+    virtual void save() = 0;
 
-  protected:
-    QSettings *_cfg;
-    // If _instance is nonzero, then your settings are to be saved for this
-    // particular instance of the source, as opposed to globally.
+  private:
     DataSourcePtr _instance;
-} KST_EXPORT;
+    QSettings& _cfg;
+    friend class DataSource;
+};
 
+
 class KST_EXPORT ValidateDataSourceThread : public QObject, public QRunnable
 {
   Q_OBJECT


More information about the Kst mailing list