[Kst] kdeextragear-2/kst/kst/datasources/ascii
George Staikos
staikos at kde.org
Wed Apr 13 19:14:55 CEST 2005
CVS commit by staikos:
should be the rest of the regressions here
M +37 -13 ascii.cpp 1.52
M +3 -0 ascii.h 1.20
M +3 -2 notes.txt 1.2
--- kdeextragear-2/kst/kst/datasources/ascii/ascii.cpp #1.51:1.52
@@ -24,4 +24,5 @@
#include <qcheckbox.h>
#include <qfile.h>
+#include <qfileinfo.h>
#include <qlayout.h>
#include <qlineedit.h>
@@ -95,4 +96,5 @@ AsciiSource::AsciiSource(KConfig *cfg, c
_valid = false;
_haveHeader = false;
+ _fieldListComplete = false;
if (!type.isEmpty() && type != "ASCII") {
return;
@@ -172,4 +174,5 @@ KstObject::UpdateType AsciiSource::updat
// Re-update the field list since we have one now
_fields = fieldListFor(_filename, _config);
+ _fieldListComplete = _fields.count() > 1;
}
@@ -244,4 +247,9 @@ KstObject::UpdateType AsciiSource::updat
+bool AsciiSource::fieldListIsComplete() const {
+ return _fieldListComplete;
+}
+
+
int AsciiSource::readField(double *v, const QString& field, int s, int n) {
if (n < 0) {
@@ -266,6 +274,13 @@ int AsciiSource::readField(double *v, co
if (col + 1 > fieldList.count()) {
+ if (_fieldListComplete) {
+ return 0;
+ }
+ bool ok = false;
+ col = field.toInt(&ok);
+ if (!ok) {
return 0;
}
+ }
int bufstart = _rowIndex[s];
@@ -461,4 +476,5 @@ QStringList AsciiSource::fieldList() con
if (_fields.isEmpty()) {
_fields = fieldListFor(_filename, _config);
+ _fieldListComplete = _fields.count() > 1;
}
@@ -635,10 +651,5 @@ QStringList provides_ascii() {
}
-/** understands_ascii: returns true iff:
- the first line which is neither empty nor a comment is a number. **/
-// FIXME: might it be better to be more lenient and ignore lines with
-// ascii free text?
int understands_ascii(KConfig *cfg, const QString& filename) {
- QFile f(filename);
AsciiSource::Config config;
config.read(cfg, filename);
@@ -652,4 +663,9 @@ int understands_ascii(KConfig *cfg, cons
}
+ if (!QFile::exists(filename) || QFileInfo(filename).isDir()) {
+ return 0;
+ }
+
+ QFile f(filename);
if (f.open(IO_ReadOnly)) {
QString s;
@@ -692,6 +708,9 @@ int understands_ascii(KConfig *cfg, cons
}
}
+ } else {
+ return 0;
}
- return 5; // still might be ascii - ex: header with no data yet.
+
+ return 1; // still might be ascii - ex: header with no data yet.
}
@@ -699,10 +718,9 @@ int understands_ascii(KConfig *cfg, cons
QStringList fieldList_ascii(KConfig *cfg, const QString& filename, const QString& type, QString *typeSuggestion, bool *complete) {
if ((!type.isEmpty() && !provides_ascii().contains(type)) ||
- !understands_ascii(cfg, filename)) {
- return QStringList();
- }
-
+ 0 == understands_ascii(cfg, filename)) {
if (complete) {
- *complete = true;
+ *complete = false;
+ }
+ return QStringList();
}
@@ -713,5 +731,11 @@ QStringList fieldList_ascii(KConfig *cfg
AsciiSource::Config config;
config.read(cfg, filename);
- return AsciiSource::fieldListFor(filename, &config);
+ QStringList rc = AsciiSource::fieldListFor(filename, &config);
+
+ if (complete) {
+ *complete = rc.count() > 1;
+ }
+
+ return rc;
}
--- kdeextragear-2/kst/kst/datasources/ascii/ascii.h #1.19:1.20
@@ -54,4 +54,6 @@ class AsciiSource : public KstDataSource
int sampleForTime(const QDateTime& time, bool *ok);
+ bool fieldListIsComplete() const;
+
class Config;
static QStringList fieldListFor(const QString& filename, Config *cfg);
@@ -68,4 +70,5 @@ class AsciiSource : public KstDataSource
uint _tmpBufSize;
bool _haveHeader;
+ mutable bool _fieldListComplete;
};
--- kdeextragear-2/kst/kst/datasources/ascii/notes.txt #1.1:1.2
@@ -27,5 +27,6 @@
3) Time code is unfinished.
-4) Empty files are broken.
-
+4) Instance of datasource needs to reload if config changes since changes don't
+apply to existing instances, and new instances are not created if old ones
+exist - it's shared.
More information about the Kst
mailing list