[Kst] branches/work/kst/portto4/kst/src
Peter Kümmel
syntheticpp at gmx.net
Fri Mar 18 23:39:22 CET 2011
SVN commit 1225259 by kuemmel:
When only a filename is passed to kst without any further arguments
and it is not a .kst file try to find a datasource which could load it,
and show all vectors against INDEX. Each datasource could overwrite this
behavior, like it was asked by Syam Krishnan C.R. on the mailinglist.
Having this feature it is now possible to register Kst as default program
for opening data files: double-click on your data file and see Kst previewing
your data!
M +12 -0 datasources/ascii/asciisource.cpp
M +2 -0 datasources/ascii/asciisource.h
M +4 -0 libkst/datasource.h
M +68 -1 libkstapp/commandlineparser.cpp
M +3 -0 libkstapp/commandlineparser.h
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1225258:1225259
@@ -19,6 +19,10 @@
#include "asciisource.h"
#include "asciisourceconfig.h"
+#include "curve.h"
+#include "colorsequence.h"
+#include "objectstore.h"
+
#include "math_kst.h"
#include "kst_inf.h"
#include "kst_i18n.h"
@@ -916,4 +920,12 @@
}
+
+Kst::ObjectList<Kst::Object> AsciiSource::autoCurves(ObjectStore& objectStore)
+{
+ // here we could do more sophisticated stuff when generating a list of curves
+ return ObjectList<Kst::Object>();
+}
+
+
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.h #1225258:1225259
@@ -76,6 +76,8 @@
static QStringList scalarListFor(const QString& filename, AsciiSourceConfig *cfg);
static QStringList stringListFor(const QString& filename, AsciiSourceConfig *cfg);
+ Kst::ObjectList<Kst::Object> autoCurves(Kst::ObjectStore& objectStore);
+
private:
// TODO Is this too big or should we use even more: 1MB on the stack?
#define KST_PREALLOC 1 * 1024 * 1024
--- branches/work/kst/portto4/kst/src/libkst/datasource.h #1225258:1225259
@@ -194,7 +194,11 @@
virtual QString descriptionTip() const;
+ /** Creates a list of curves without user interaction
+ */
+ virtual ObjectList<Object> autoCurves(ObjectStore& objectStore) { return ObjectList<Object>(); }
+
public Q_SLOTS:
virtual void checkUpdate();
--- branches/work/kst/portto4/kst/src/libkstapp/commandlineparser.cpp #1225258:1225259
@@ -281,6 +281,11 @@
curve->registerChange();
curve->unlock();
+ addCurve(curve);
+}
+
+void CommandLineParser::addCurve(CurvePtr curve)
+{
if (_doConsecutivePlots) {
CreatePlotForCurve *cmd = new CreatePlotForCurve();
cmd->createItem();
@@ -361,7 +366,9 @@
}
while (*ok) {
- if (_arguments.count()<1) break;
+ if (_arguments.count() < 1) {
+ break;
+ }
arg = _arguments.takeFirst();
if ((arg == "--help")||(arg == "-help")) {
@@ -588,8 +595,24 @@
new_fileList = false;
}
_fileNames.append(arg);
+
+ if (!arg.endsWith(".kst") && _arguments.count() == 0) {
+ // try loading data without user interaction
+ DataSourcePtr ds = DataSourcePluginManager::findOrLoadSource(_document->objectStore(), arg);
+ if (ds) {
+ ObjectList<Object> curves = ds->autoCurves(*_document->objectStore());
+ if (curves.isEmpty()) {
+ curves = autoCurves(ds);
}
+ if (!curves.isEmpty()) {
+ foreach(const ObjectPtr& ptr, curves) {
+ addCurve(kst_cast<Curve>(ptr));
}
+ }
+ }
+ }
+ }
+ }
// set defaults to match what has been set.
_dialogDefaults->setValue("print/landscape", _landscape);
@@ -602,4 +625,48 @@
return (dataPlotted);
}
+
+Kst::ObjectList<Kst::Object> CommandLineParser::autoCurves(DataSourcePtr ds)
+{
+ QStringList fieldList = ds->vector().list();
+
+ if (fieldList.isEmpty()) {
+ return ObjectList<Kst::Object>();
}
+
+ ObjectList<Kst::Object> curves;
+
+ DataVectorPtr xv = _document->objectStore()->createObject<DataVector>();
+ xv->writeLock();
+ xv->change(ds, "INDEX", 0, -1, 0, false, false);
+ xv->registerChange();
+ xv->unlock();
+
+ foreach(const QString& field, fieldList) {
+ if (field != "INDEX") {
+ DataVectorPtr yv= _document->objectStore()->createObject<DataVector>();
+ yv->writeLock();
+ yv->change(ds, field, 0, -1, 0, false, false);
+ yv->registerChange();
+ yv->unlock();
+
+ CurvePtr curve = _document->objectStore()->createObject<Curve>();
+ curve->setXVector(xv);
+ curve->setYVector(yv);
+ curve->setXError(0);
+ curve->setXMinusError(0);
+ curve->setYMinusError(0);
+ curve->setColor(Kst::ColorSequence::self().next());
+ curve->setLineWidth(1);
+
+ curve->writeLock();
+ curve->registerChange();
+ curve->unlock();
+
+ curves << curve;
+ }
+ }
+ return curves;
+}
+
+}
--- branches/work/kst/portto4/kst/src/libkstapp/commandlineparser.h #1225258:1225259
@@ -34,6 +34,7 @@
QString pngFile() const {return _pngFile;}
QString printFile() const {return _printFile;}
//bool landscape() const {return _landscape;}
+
private:
bool _doAve;
bool _doSkip;
@@ -73,6 +74,8 @@
void createOrFindPlot(const QString name);
void createCurveInPlot(VectorPtr xv, VectorPtr yv, VectorPtr ev=0);
void createImageInPlot(MatrixPtr m);
+ void addCurve(CurvePtr curve);
+ ObjectList<Object> autoCurves(DataSourcePtr ds);
};
}
More information about the Kst
mailing list