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

Peter Kümmel syntheticpp at gmx.net
Fri Oct 19 09:23:07 UTC 2012


SVN commit 1321326 by kuemmel:

split out ascii config widget

 A             asciiconfigwidget.cpp   asciiplugin.cpp#1321313 [License: GPL (v2+)]
 A             asciiconfigwidget.h   [License: GPL (v2+)]
 M  +1 -252    asciiplugin.cpp  
 M  +0 -44     asciiplugin.h  


--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiplugin.cpp #1321325:1321326
@@ -11,6 +11,7 @@
  ***************************************************************************/
 
 #include "asciiplugin.h"
+#include "asciiconfigwidget.h"
 #include "asciisourceconfig.h"
 #include "kst_atof.h"
 
@@ -19,258 +20,6 @@
 #include <QButtonGroup>
 #include <QPlainTextEdit>
 #include <QMessageBox>
-
-//
-// ConfigWidgetAsciiInternal
-//
-
-
-
-ConfigWidgetAsciiInternal::ConfigWidgetAsciiInternal(QWidget *parent) : 
-    QWidget(parent), 
-    Ui_AsciiConfig(),
-    _index_offset(1)
-{
-  setupUi(this);
-
-  QButtonGroup* bgroup = new QButtonGroup(this);
-  bgroup->addButton(_whitespace, AsciiSourceConfig::Whitespace);
-  bgroup->addButton(_custom, AsciiSourceConfig::Custom);
-  bgroup->addButton(_fixed, AsciiSourceConfig::Fixed);
-  connect(bgroup, SIGNAL(buttonClicked(int)), this, SLOT(columnLayoutChanged(int)));
-
-  _showBeginning->setFont(  QFont("Courier"));
-  _showBeginning->setReadOnly(true);
-  _showBeginning->setLineWrapMode(QPlainTextEdit::NoWrap);
-
-  connect(_readFields, SIGNAL(toggled(bool)), this, SLOT(updateUnitLineEnabled(bool)));
-  connect(_limitFileBuffer, SIGNAL(toggled(bool)), this, SLOT(updateFrameBuffer(bool)));
-}
-
-void ConfigWidgetAsciiInternal::updateUnitLineEnabled(bool checked)
-{
-  if (checked && _readUnits->isChecked()) {
-    _unitsLine->setEnabled(true);
-  } else {
-    _unitsLine->setEnabled(false);
-  }
-}
-
-void ConfigWidgetAsciiInternal::updateFrameBuffer(bool checked)
-{
-  if (checked) {
-    _limitFileBufferSize->setEnabled(true);
-  } else {
-    _limitFileBufferSize->setEnabled(false);
-  }
-}
-
-
-void ConfigWidgetAsciiInternal::columnLayoutChanged(int idx)
-{
-  if (idx == AsciiSourceConfig::Fixed) {
-    widthButtonGroup->setEnabled(false);
-  } else {
-    widthButtonGroup->setEnabled(true);
-  }
-}
-
-
-void ConfigWidgetAsciiInternal::showBeginning()
-{
-  QFile file(_filename);
-  if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
-    return;
-  }
-
-  int lines_read = 1;
-  QTextStream in(&file);
-  QStringList lines;
-  while (!in.atEnd() && lines_read <= 100) {
-    lines << QString("%1:").arg(lines_read, 3) + in.readLine();
-    lines_read++;
-  }
-
-  _showBeginning->setPlainText(lines.join("\n"));
-  _showBeginning->moveCursor(QTextCursor::Start);
-
-  _labelBeginning->setText(QString("First 100 lines in file '%1'").arg(QFileInfo(_filename).fileName()));
-}
-
-
-AsciiSourceConfig ConfigWidgetAsciiInternal::config()
-{
-  AsciiSourceConfig config;
-  config._fileNamePattern = _fileNamePattern->text();
-  config._indexInterpretation = (AsciiSourceConfig::Interpretation) (1 + _indexType->currentIndex());
-  config._delimiters = _delimiters->text();
-  
-  if (_whitespace->isChecked()) {
-    config._columnType = AsciiSourceConfig::Whitespace;
-  } else if (_custom->isChecked()) {
-    config._columnType = AsciiSourceConfig::Custom;
-  } else if (_fixed->isChecked()) {
-    config._columnType = AsciiSourceConfig::Fixed;
-  }
-
-  config._columnDelimiter = _columnDelimiter->text();
-  config._columnWidth = _columnWidth->value();
-  config._columnWidthIsConst = _columnWidthIsConst->isChecked();
-  config._readFields = _readFields->isChecked();
-  config._readUnits = _readUnits->isChecked();
-  config._useDot = _useDot->isChecked();
-
-  config._dataLine = _startLine->value() - _index_offset;
-  config._fieldsLine = _fieldsLine->value() - _index_offset;
-  config._unitsLine = _unitsLine->value() - _index_offset;
-
-  config._limitFileBuffer = _limitFileBuffer->isChecked();
-  bool ok;
-  int size = _limitFileBufferSize->text().toInt(&ok);
-  if (ok) {
-    config._limitFileBufferSize = size * 1024 * 1024;
-  }
-
-  config._useThreads =_useThreads->isChecked();
-
-  return config;
-}
-
-void ConfigWidgetAsciiInternal::setFilename(const QString& filename)
-{
-  _filename = filename;
-  showBeginning();
-}
-
-
-void ConfigWidgetAsciiInternal::setConfig(const AsciiSourceConfig& config)
-{
-  _delimiters->setText(config._delimiters);
-  _fileNamePattern->setText(config._fileNamePattern);
-  _columnDelimiter->setText(config._columnDelimiter);
-  _columnWidth->setValue(config._columnWidth);
-  _columnWidthIsConst->setChecked(config._columnWidthIsConst);
-  _readFields->setChecked(config._readFields);
-  _readUnits->setChecked(config._readUnits);
-  _useDot->setChecked(config._useDot);
-  _useComma->setChecked(!config._useDot);
-  updateUnitLineEnabled(config._readFields);
-  
-  _startLine->setValue(config._dataLine + _index_offset);
-  _fieldsLine->setValue(config._fieldsLine + _index_offset);
-  _unitsLine->setValue(config._unitsLine + _index_offset);
-
-  AsciiSourceConfig::ColumnType ct = (AsciiSourceConfig::ColumnType) config._columnType.value();
-  if (ct == AsciiSourceConfig::Fixed) {
-    _fixed->setChecked(true);
-  } else if (ct == AsciiSourceConfig::Custom) {
-    _custom->setChecked(true);
-  } else {
-    _whitespace->setChecked(true);
-  }
-  columnLayoutChanged(ct);
-
-  _limitFileBuffer->setChecked(config._limitFileBuffer);
-  _limitFileBufferSize->setText(QString::number(config._limitFileBufferSize / 1024 / 1024));
-  updateFrameBuffer(config._limitFileBuffer);
-
-  _useThreads->setChecked(config._useThreads);
-}
-
-
-ConfigWidgetAscii::ConfigWidgetAscii(QSettings& s) : Kst::DataSourceConfigWidget(s) {
-  QGridLayout *layout = new QGridLayout(this);
-  _ac = new ConfigWidgetAsciiInternal(this);
-  layout->addWidget(_ac, 0, 0);
-  layout->activate();
-}
-
-
-ConfigWidgetAscii::~ConfigWidgetAscii() {
-}
-
-
-void ConfigWidgetAscii::setFilename(const QString& filename)
-{
-  _ac->setFilename(filename);
-}
-
-
-void ConfigWidgetAscii::load() {
-  AsciiSourceConfig config;
-  if (hasInstance())
-    config.readGroup(settings(), instance()->fileName());
-  else
-    config.readGroup(settings());
-
-  _ac->setConfig(config);
-
-  // Now handle index
-  _ac->_indexVector->clear();
-  if (hasInstance()) {
-    Kst::SharedPtr<AsciiSource> src = Kst::kst_cast<AsciiSource>(instance());
-    _ac->_indexVector->addItems(src->vector().list());
-    _ac->_indexVector->setCurrentIndex(src->_config._indexInterpretation - 1);
-    if (src->vector().list().contains(src->_config._indexVector)) {
-      _ac->_indexVector->setEditText(src->_config._indexVector);
-    }
-  } else {
-    _ac->_indexVector->addItem("INDEX");
-    int x = config._indexInterpretation;
-    if (x > 0 && x <= _ac->_indexType->count()) {
-      _ac->_indexType->setCurrentIndex(x - 1);
-    } else {
-      _ac->_indexType->setCurrentIndex(0);
-    }
-  }
-  _ac->_indexVector->setEnabled(hasInstance());
-}
-
-
-void ConfigWidgetAscii::save() {
-  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());
-
-    // Update the instance from our new settings
-    if (src->reusable()) {
-      src->_config.readGroup(settings(), src->fileName());
-      src->reset();
-      src->internalDataSourceUpdate();
-    }
-  }
-}
-
-bool ConfigWidgetAscii::isOkAcceptabe() const {
-  AsciiSourceConfig config = _ac->config();
-  QString msg;
-  if (config._readFields) {
-    if (config._fieldsLine == config._dataLine) {
-      msg = QString("Line %1 could not list field names AND values!").arg(config._fieldsLine + 1);
-    }
-    if (config._readUnits) {
-      if (config._unitsLine == config._dataLine) {
-        msg = QString("Line %1 could not list units AND values!").arg(config._unitsLine + 1);
-      }
-      if (config._unitsLine == config._fieldsLine) {
-        msg = QString("Line %1 could not list field names AND units!").arg(config._unitsLine + 1);
-      }
-    }
-  }
-  if (!msg.isEmpty()) {
-    QMessageBox::critical(0, "Inconsistent parameters", msg);
-    return false;
-  }
-  return true;
-}
-
-//
-// AsciiPlugin
-//
-
 QString AsciiPlugin::pluginName() const { return "ASCII File Reader"; }
 QString AsciiPlugin::pluginDescription() const { return "ASCII File Reader"; }
 
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiplugin.h #1321325:1321326
@@ -13,13 +13,10 @@
 #ifndef ASCII_PLUGIN_H
 #define ASCII_PLUGIN_H
 
-
 #include "asciisource.h"
 #include "dataplugin.h"
 
-#include "ui_asciiconfig.h"
 
-
 class AsciiPlugin : public QObject, public Kst::DataSourcePluginInterface
 {
     Q_OBJECT
@@ -74,46 +71,5 @@
 };
 
 
-
-class ConfigWidgetAsciiInternal : public QWidget, public Ui_AsciiConfig
-{
-  Q_OBJECT
-
-  public:
-    ConfigWidgetAsciiInternal(QWidget *parent);
-
-    AsciiSourceConfig config();
-    void setConfig(const AsciiSourceConfig&);
-    void setFilename(const QString& filename);
-
-  private Q_SLOTS:
-    void columnLayoutChanged(int);
-    void showBeginning();
-    void updateUnitLineEnabled(bool);
-    void updateFrameBuffer(bool);
-
-  private:
-    const int _index_offset;
-    QString _filename;
-};
-
-
-class ConfigWidgetAscii : public Kst::DataSourceConfigWidget
-{
-  public:
-    ConfigWidgetAscii(QSettings&);
-    ~ConfigWidgetAscii();
-
-    void load();
-    void save();
-    bool isOkAcceptabe() const;
-
-    void setFilename(const QString& filename);
-
-    ConfigWidgetAsciiInternal *_ac;
-};
-
-
-
 #endif
 // vim: ts=2 sw=2 et


More information about the Kst mailing list