[Kst] branches/work/kst/portto4/kst/src/datasources/ascii
Peter Kümmel
syntheticpp at gmx.net
Thu Jan 27 13:18:13 CET 2011
SVN commit 1217468 by kuemmel:
Fixed column width is the third column layout
M +24 -24 asciiconfig.ui
M +28 -15 asciiplugin.cpp
M +18 -0 asciiplugin.h
M +5 -3 asciisource.cpp
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiconfig.ui #1217467:1217468
@@ -118,11 +118,11 @@
</layout>
</item>
<item>
- <widget class="QGroupBox" name="buttonGroup2">
+ <widget class="QGroupBox" name="headerButtonGroup">
<property name="title">
<string>Header</string>
</property>
- <layout class="QGridLayout" name="gridLayout">
+ <layout class="QGridLayout" name="gridLayout2">
<item row="0" column="0">
<widget class="QLabel" name="textLabel1_3">
<property name="sizePolicy">
@@ -221,9 +221,9 @@
</widget>
</item>
<item>
- <widget class="QGroupBox" name="buttonGroup1">
+ <widget class="QGroupBox" name="layoutButtonGroup">
<property name="title">
- <string>Data Format: Delimiters</string>
+ <string>Data Column Layout</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
@@ -254,26 +254,7 @@
</item>
</layout>
</item>
- </layout>
- </widget>
- </item>
<item>
- <widget class="QGroupBox" name="groupBox">
- <property name="title">
- <string>Data Format: Fixed-Width Options</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
- <widget class="QRadioButton" name="radioButton">
- <property name="text">
- <string>Do not make assumptions on column width</string>
- </property>
- <property name="checked">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="_fixed">
@@ -300,10 +281,29 @@
</item>
</layout>
</item>
+ </layout>
+ </widget>
+ </item>
<item>
+ <widget class="QGroupBox" name="widthButtonGroup">
+ <property name="title">
+ <string>Data Column Width Options</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QRadioButton" name="radioButton">
+ <property name="text">
+ <string>Do not make assumptions on column width</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QRadioButton" name="_columnWidthIsConst">
<property name="text">
- <string>Each column has a constant width</string>
+ <string>Each column has its own constant width</string>
</property>
</widget>
</item>
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiplugin.cpp #1217467:1217468
@@ -17,45 +17,56 @@
#include "asciiplugin.h"
#include "asciisourceconfig.h"
-#include "ui_asciiconfig.h"
+
#include <QFile>
#include <QFileInfo>
+#include <QButtonGroup>
-
//
// ConfigWidgetAsciiInternal
//
-class ConfigWidgetAsciiInternal : public QWidget, public Ui_AsciiConfig
-{
- public:
- ConfigWidgetAsciiInternal(QWidget *parent);
- AsciiSourceConfig config();
- void setConfig(const AsciiSourceConfig&);
-};
-
ConfigWidgetAsciiInternal::ConfigWidgetAsciiInternal(QWidget *parent) : QWidget(parent), Ui_AsciiConfig() {
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)));
}
+void ConfigWidgetAsciiInternal::columnLayoutChanged(int idx)
+{
+ if (idx == AsciiSourceConfig::Fixed) {
+ widthButtonGroup->setEnabled(false);
+ } else {
+ widthButtonGroup->setEnabled(true);
+ }
+}
+
+
AsciiSourceConfig ConfigWidgetAsciiInternal::config()
{
AsciiSourceConfig config;
config._fileNamePattern = _fileNamePattern->text();
config._indexInterpretation = (AsciiSourceConfig::Interpretation) (1 + _indexType->currentIndex());
config._delimiters = _delimiters->text();
- AsciiSourceConfig::ColumnType ct = AsciiSourceConfig::Whitespace;
- if (_fixed->isChecked()) {
- ct = AsciiSourceConfig::Fixed;
+
+ if (_whitespace->isChecked()) {
+ config._columnType = AsciiSourceConfig::Whitespace;
} else if (_custom->isChecked()) {
- ct = AsciiSourceConfig::Custom;
+ config._columnType = AsciiSourceConfig::Custom;
+ } else if (_fixed->isChecked()) {
+ config._columnType = AsciiSourceConfig::Fixed;
}
- config._columnType = ct;
+
config._columnDelimiter = _columnDelimiter->text();
config._columnWidth = _columnWidth->value();
config._columnWidthIsConst = _columnWidthIsConst->isChecked();
@@ -79,6 +90,7 @@
_readFields->setChecked(config._readFields);
_useDot->setChecked(config._useDot);
_fieldsLine->setValue(config._fieldsLine);
+
AsciiSourceConfig::ColumnType ct = (AsciiSourceConfig::ColumnType) config._columnType.value();
if (ct == AsciiSourceConfig::Fixed) {
_fixed->setChecked(true);
@@ -87,6 +99,7 @@
} else {
_whitespace->setChecked(true);
}
+ columnLayoutChanged(ct);
}
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiplugin.h #1217467:1217468
@@ -22,7 +22,9 @@
#include "asciisource.h"
#include "dataplugin.h"
+#include "ui_asciiconfig.h"
+
class AsciiPlugin : public QObject, public Kst::DataSourcePluginInterface
{
Q_OBJECT
@@ -75,5 +77,21 @@
virtual Kst::DataSourceConfigWidget *configWidget(QSettings *cfg, const QString& filename) const;
};
+
+class ConfigWidgetAsciiInternal : public QWidget, public Ui_AsciiConfig
+{
+ Q_OBJECT
+
+ public:
+ ConfigWidgetAsciiInternal(QWidget *parent);
+
+ AsciiSourceConfig config();
+ void setConfig(const AsciiSourceConfig&);
+
+ private Q_SLOTS:
+ void columnLayoutChanged(int);
+
+};
+
#endif
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1217467:1217468
@@ -476,9 +476,11 @@
if (_config._columnType == AsciiSourceConfig::Fixed) {
LexicalCast lexc;
lexc.setDecimalSeparator(_config._useDot, _config._localSeparator);
- for (int i = 0; i < n; ++i, ++s) {
- // Read appropriate column and convert to double
- v[i] = lexc.toDouble(&buffer[0] + _rowIndex[i] - _rowIndex[0] + _config._columnWidth * (col - 1));
+ const char* col_start = &buffer[0] + _config._columnWidth * (col - 1);
+ for (int i = 0; i < n; ++i) {
+ /* Read appropriate column and convert to double
+ v[i] = lexc.toDouble(&buffer[0] + _rowIndex[i] + _config._columnWidth * (col - 1));*/
+ v[i] = lexc.toDouble(col_start + _rowIndex[i]);
}
return n;
} else if (_config._columnType == AsciiSourceConfig::Custom) {
More information about the Kst
mailing list