[Kst] branches/work/kst/portto4/kst
Adam Treat
treat at kde.org
Wed Sep 26 19:37:30 CEST 2007
SVN commit 717344 by treat:
* Rearrange some stuff in kstdatasource
* Add new tests for config widget and filetype to testdatasource
* Refactor vectordialog to cleanup taking into account above
M +2 -0 src/datasources/ascii/ascii.h
M +34 -7 src/libkst/kstdatasource.cpp
M +14 -14 src/libkst/kstdatasource.h
M +0 -2 src/libkstapp/dialogtab.h
M +35 -33 src/libkstapp/vectordialog.cpp
M +2 -3 src/libkstapp/vectordialog.h
M +12 -1 tests/testdatasource.cpp
--- branches/work/kst/portto4/kst/src/datasources/ascii/ascii.h #717343:717344
@@ -94,6 +94,8 @@
virtual QString pluginName() const;
+ virtual bool hasConfigWidget() const { return true; }
+
virtual KstDataSource *create(QSettings *cfg,
const QString &filename,
const QString &type,
--- branches/work/kst/portto4/kst/src/libkst/kstdatasource.cpp #717343:717344
@@ -234,14 +234,21 @@
}
-KstDataSourceConfigWidget* KstDataSource::configWidget() const {
+bool KstDataSource::hasConfigWidget() const {
+ return sourceHasConfigWidget(_filename, fileType());
+}
+
+
+KstDataSourceConfigWidget* KstDataSource::configWidget() {
+ if (!hasConfigWidget())
+ return 0;
+
KstDataSourceConfigWidget *w = configWidgetForSource(_filename, fileType());
- if (w) {
- // FIXME: what to do here? This is ugly, but the method is const and we
- // can't put a const shared pointer in the config widget. Fix for
- // Kst 2.0 by making this non-const?
- w->_instance = const_cast<KstDataSource*>(this);
- }
+ Q_ASSERT(w);
+
+ //This is still ugly to me...
+ w->_instance = this;
+
return w;
}
@@ -282,6 +289,26 @@
}
+bool KstDataSource::sourceHasConfigWidget(const QString& filename, const QString& type) {
+ if (filename == "stdin" || filename == "-") {
+ return 0L;
+ }
+
+ QString fn = obtainFile(filename);
+ if (fn.isEmpty()) {
+ return 0L;
+ }
+
+ QList<PluginSortContainer> bestPlugins = bestPluginsForSource(fn, type);
+ for (QList<PluginSortContainer>::Iterator i = bestPlugins.begin(); i != bestPlugins.end(); ++i) {
+ return (*i).plugin->hasConfigWidget();
+ }
+
+ KstDebug::self()->log(i18n("Could not find a datasource for '%1'(%2), but we found one just prior. Something is wrong with Kst.", filename, type), KstDebug::Error);
+ return false;
+}
+
+
KstDataSourceConfigWidget* KstDataSource::configWidgetForSource(const QString& filename, const QString& type) {
if (filename == "stdin" || filename == "-") {
return 0L;
--- branches/work/kst/portto4/kst/src/libkst/kstdatasource.h #717343:717344
@@ -53,33 +53,33 @@
class KST_EXPORT KstDataSource : public KstObject {
public:
- KstDataSource(QSettings *cfg, const QString& filename, const QString& type);
- friend class KstApp;
static void setupOnStartup(QSettings*);
static void cleanupForExit();
- virtual ~KstDataSource();
-
- void setTagName(const KstObjectTag& tag);
-
- // These six static methods are not for plugins to use
/** Returns a list of plugins found on the system. */
static QStringList pluginList();
static KstSharedPtr<KstDataSource> loadSource(const QString& filename, const QString& type = QString::null);
static KstSharedPtr<KstDataSource> loadSource(QDomElement& e);
- static QStringList fieldListForSource(const QString& filename, const QString& type = QString::null, QString *outType = 0L, bool *complete = 0L);
- static QStringList matrixListForSource(const QString& filename, const QString& type = QString::null, QString *outType = 0L, bool *complete = 0L);
- static KstDataSourceConfigWidget *configWidgetForSource(const QString& filename, const QString& type);
+ static QStringList fieldListForSource(const QString& filename, const QString& type = QString(), QString *outType = 0L, bool *complete = 0L);
+ static QStringList matrixListForSource(const QString& filename, const QString& type = QString(), QString *outType = 0L, bool *complete = 0L);
+
+ static bool sourceHasConfigWidget(const QString& filename, const QString& type = QString());
+ static KstDataSourceConfigWidget *configWidgetForSource(const QString& filename, const QString& type = QString());
+
+ static bool pluginHasConfigWidget(const QString& plugin);
static KstDataSourceConfigWidget *configWidgetForPlugin(const QString& plugin);
- // @since 1.1.0
- static bool pluginHasConfigWidget(const QString& plugin);
- // @since 1.1.0
+
static bool supportsTime(const QString& plugin, const QString& type = QString::null);
+ KstDataSource(QSettings *cfg, const QString& filename, const QString& type);
+ virtual ~KstDataSource();
- KstDataSourceConfigWidget *configWidget() const;
+ void setTagName(const KstObjectTag& tag);
+ bool hasConfigWidget() const;
+ KstDataSourceConfigWidget *configWidget();
+
// @since 1.1.0
bool reusable() const;
// @since 1.1.0
--- branches/work/kst/portto4/kst/src/libkstapp/dialogtab.h #717343:717344
@@ -24,8 +24,6 @@
{
Q_OBJECT
public:
- typedef QMap<QString, QVariant> ValueMap;
-
DialogTab(QWidget *parent);
virtual ~DialogTab();
--- branches/work/kst/portto4/kst/src/libkstapp/vectordialog.cpp #717343:717344
@@ -93,55 +93,57 @@
_field->clear();
KST::dataSourceList.lock().readLock();
-
- KstDataSourcePtr ds = KST::dataSourceList.findReusableFileName(QUrl(file));
+ _dataSource = KST::dataSourceList.findReusableFileName(QUrl(file));
KST::dataSourceList.lock().unlock();
- //FIXME this can't be good...
- delete _configWidget;
- _configWidget = 0L;
+ if (!_dataSource) {
+ _dataSource = KstDataSource::loadSource(QUrl(file), QString());
+ }
- QStringList list;
- if (ds) {
+ if (!_dataSource) {
+ _field->setEnabled(false);
+ _configure->setEnabled(false);
+ return; //Couldn't find a suitable datasource
+ }
- ds->readLock();
- list = ds->fieldList();
- _field->setEditable(!ds->fieldListIsComplete());
- _configWidget = ds->configWidget();
- ds->unlock();
- _field->setEnabled(true);
- //_dataRange->setAllowTime(ds->supportsTimeConversions());
+ _field->setEnabled(true);
- } else {
+ _dataSource->readLock();
- QString type;
- bool complete = false;
+ _field->addItems(_dataSource->fieldList());
+ _field->setEditable(!_dataSource->fieldListIsComplete());
+ _configure->setEnabled(_dataSource->hasConfigWidget());
- list = KstDataSource::fieldListForSource(QUrl(file), QString::null, &type, &complete);
+ //FIXME deal with time...
+ //_dataRange->setAllowTime(ds->supportsTimeConversions());
- _field->setEditable(!complete);
- _field->setEnabled(!list.isEmpty());
+ _dataSource->unlock();
+}
- if (!list.isEmpty() && !type.isEmpty()) {
- _configWidget = KstDataSource::configWidgetForSource(QUrl(file), type);
- }
- //_dataRange->setAllowTime(KstDataSource::supportsTime(QUrl(file), type));
- }
+void VectorTab::showConfigWidget() {
+ QDialog dialog(this);
- _configure->setEnabled(_configWidget);
+ QVBoxLayout layout(&dialog);
- _field->addItems(list);
-}
+ _dataSource->readLock();
+ QWidget *widget = _dataSource->configWidget();
+ widget->setParent(&dialog);
+ layout.addWidget(widget);
+ _dataSource->unlock();
+ QDialogButtonBox box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
+ layout.addWidget(&box);
-void VectorTab::showConfigWidget() {
- QDialog dialog(this);
+// if (isNew) {
+// connect(dlg, SIGNAL(okClicked()), _configWidget, SLOT(save()));
+// connect(dlg, SIGNAL(applyClicked()), _configWidget, SLOT(save()));
+// } else {
+// connect(dlg, SIGNAL(okClicked()), this, SLOT(markSourceAndSave()));
+// connect(dlg, SIGNAL(applyClicked()), this, SLOT(markSourceAndSave()));
+// }
- QHBoxLayout layout(&dialog);
- layout.addWidget(_configWidget);
dialog.setLayout(&layout);
-
dialog.exec();
}
--- branches/work/kst/portto4/kst/src/libkstapp/vectordialog.h #717343:717344
@@ -21,7 +21,7 @@
#include "kst_export.h"
-class KstDataSourceConfigWidget;
+#include "kstdatasource.h"
namespace Kst {
@@ -53,8 +53,7 @@
private:
Mode _mode;
-
- QPointer<KstDataSourceConfigWidget> _configWidget;
+ KstDataSourcePtr _dataSource;
};
class KST_EXPORT VectorDialog : public DataDialog {
--- branches/work/kst/portto4/kst/tests/testdatasource.cpp #717343:717344
@@ -63,8 +63,9 @@
KstDataSourcePtr dsp = KstDataSource::loadSource(tf.fileName());
QVERIFY(dsp);
-
QVERIFY(dsp->isValid());
+ QVERIFY(dsp->hasConfigWidget());
+ QCOMPARE(dsp->fileType(), QLatin1String("ASCII"));
QVERIFY(dsp->isValidField("INDEX"));
QVERIFY(dsp->isValidField("1"));
QVERIFY(!dsp->isValidField("0"));
@@ -115,6 +116,8 @@
QVERIFY(dsp);
QVERIFY(dsp->isValid());
+ QVERIFY(dsp->hasConfigWidget());
+ QCOMPARE(dsp->fileType(), QLatin1String("ASCII"));
QVERIFY(dsp->isValidField("INDEX"));
QVERIFY(dsp->isValidField("1"));
QVERIFY(!dsp->isValidField("0"));
@@ -168,6 +171,8 @@
QVERIFY(dsp);
QVERIFY(dsp->isValid());
+ QVERIFY(dsp->hasConfigWidget());
+ QCOMPARE(dsp->fileType(), QLatin1String("ASCII"));
QVERIFY(dsp->isValidField("INDEX"));
QVERIFY(dsp->isValidField("1"));
QVERIFY(!dsp->isValidField("0"));
@@ -211,6 +216,8 @@
KstDataSourcePtr dsp = KstDataSource::loadSource(tf.fileName());
QVERIFY(dsp);
+ QVERIFY(dsp->hasConfigWidget());
+ QCOMPARE(dsp->fileType(), QLatin1String("ASCII"));
tf.close();
}
@@ -227,6 +234,8 @@
QVERIFY(dsp);
QVERIFY(dsp->isValid());
+ QVERIFY(dsp->hasConfigWidget());
+ QCOMPARE(dsp->fileType(), QLatin1String("ASCII"));
QCOMPARE(dsp->frameCount(QString::null), 39000);
QCOMPARE(dsp->frameCount("1"), 39000);
QCOMPARE(dsp->frameCount("2"), 39000);
@@ -293,6 +302,8 @@
QVERIFY(dsp);
QVERIFY(dsp->isValid());
+ QVERIFY(dsp->hasConfigWidget());
+ QCOMPARE(dsp->fileType(), QLatin1String("DirFile"));
QVERIFY(dsp->isValidField("INDEX"));
QCOMPARE(dsp->frameCount("INDEX"), 15);
QVERIFY(dsp->isValidField("cos"));
More information about the Kst
mailing list