[Kst] branches/work/kst/portto4/kst/src/datasources/ascii
Peter Kümmel
syntheticpp at gmx.net
Sun Oct 21 15:22:34 UTC 2012
SVN commit 1321750 by kuemmel:
some speed improvements for ascii data with very much columns
M +10 -1 asciiconfigwidget.cpp
M +2 -1 asciiconfigwidget.h
M +12 -7 asciisource.cpp
M +1 -1 asciisource.h
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiconfigwidget.cpp #1321749:1321750
@@ -75,6 +75,15 @@
}
}
+QString AsciiConfigWidgetInternal::readLine(QTextStream& in, int maxLength)
+{
+ const QString line = in.readLine();
+ if (line.size() > maxLength) {
+ // very log line, don't show it complete
+ return line.mid(0, maxLength) + " ...";
+ }
+ return line;
+}
void AsciiConfigWidgetInternal::showBeginning()
{
@@ -87,7 +96,7 @@
QTextStream in(&file);
QStringList lines;
while (!in.atEnd() && lines_read <= 100) {
- lines << QString("%1:").arg(lines_read, 3) + in.readLine();
+ lines << QString("%1: ").arg(lines_read, 3) + readLine(in, 1000);
lines_read++;
}
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiconfigwidget.h #1321749:1321750
@@ -18,8 +18,8 @@
#include "ui_asciiconfig.h"
+class QTextStream;
-
class AsciiConfigWidgetInternal : public QWidget, public Ui_AsciiConfig
{
Q_OBJECT
@@ -40,6 +40,7 @@
private:
const int _index_offset;
QString _filename;
+ QString readLine(QTextStream& in, int maxLength);
};
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1321749:1321750
@@ -405,9 +405,9 @@
//-------------------------------------------------------------------------------------------
-QStringList AsciiSource::splitHeaderLine(const QByteArray& line, AsciiSourceConfig* cfg)
+int AsciiSource::splitHeaderLine(const QByteArray& line, AsciiSourceConfig* cfg, QStringList& parts)
{
- QStringList parts;
+ parts.clear();
const QRegExp regexColumnDelimiter(QString("[%1]").arg(QRegExp::escape(cfg->_columnDelimiter.value())));
if (cfg->_columnType == AsciiSourceConfig::Custom && !cfg->_columnDelimiter.value().isEmpty()) {
@@ -421,7 +421,7 @@
} else {
parts += QString(line).trimmed().split(QRegExp("\\s"), QString::SkipEmptyParts);
}
- return parts;
+ return parts.count();
}
@@ -443,7 +443,9 @@
const QByteArray line = file.readLine();
int r = line.size();
if (currentLine == fieldsLine && r >= 0) {
- fields += AsciiSource::splitHeaderLine(line, cfg);
+ QStringList parts;
+ AsciiSource::splitHeaderLine(line, cfg, parts);
+ fields += parts;
break;
}
currentLine++;
@@ -478,6 +480,7 @@
int cnt;
int nextscan = 0;
int curscan = 0;
+ QStringList parts;
while (!file.atEnd() && !done && (nextscan < 200)) {
QByteArray line = file.readLine();
int r = line.size();
@@ -491,7 +494,7 @@
if (maxcnt >= 0) { //original skip value == 0, so scan some lines
if (curscan >= nextscan) {
if (r > 1 && !regex.exactMatch(line)) {
- cnt = splitHeaderLine(line, cfg).count();
+ cnt = splitHeaderLine(line, cfg, parts);
if (cnt > maxcnt) {
maxcnt = cnt;
}
@@ -504,7 +507,7 @@
continue;
}
if (r > 1 && !regex.exactMatch(line)) { //at desired line, find count
- maxcnt = splitHeaderLine(line, cfg).count();
+ maxcnt = splitHeaderLine(line, cfg, parts);
done = true;
} else if (r < 0) {
return fields;
@@ -536,7 +539,9 @@
const QByteArray line = file.readLine();
int r = line.size();
if (currentLine == unitsLine && r >= 0) {
- units += AsciiSource::splitHeaderLine(line, cfg);
+ QStringList parts;
+ AsciiSource::splitHeaderLine(line, cfg, parts);
+ units += parts;
break;
}
currentLine++;
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.h #1321749:1321750
@@ -92,7 +92,7 @@
int columnOfField(const QString& field) const;
- static QStringList splitHeaderLine(const QByteArray& line, AsciiSourceConfig* cfg);
+ static int splitHeaderLine(const QByteArray& line, AsciiSourceConfig* cfg, QStringList& result);
DataInterfaceAsciiString* is;
DataInterfaceAsciiVector* iv;
More information about the Kst
mailing list