[Kst] branches/work/kst/portto4/kst/src

Adam Treat treat at kde.org
Tue Sep 25 19:49:09 CEST 2007


SVN commit 716950 by treat:

* Try and hook up reading from the datasource
in vectordialog.


 M  +6 -6      libkst/kstdatasource.h  
 M  +1 -1      libkst/kstrmatrix.cpp  
 M  +2 -2      libkst/kstrvector.cpp  
 M  +61 -3     libkstapp/vectordialog.cpp  
 M  +7 -0      libkstapp/vectordialog.h  
 M  +1 -1      widgets/filerequester.cpp  


--- branches/work/kst/portto4/kst/src/libkst/kstdatasource.h #716949:716950
@@ -257,23 +257,23 @@
     KstDataSourceList(const KstDataSourceList& x) : KstObjectList<KstDataSourcePtr>(x) {}
     virtual ~KstDataSourceList() {}
 
-    virtual KstDataSourceList::Iterator findFileName(const QString& x) {
+    virtual KstDataSourcePtr findFileName(const QString& x) {
       for (KstDataSourceList::Iterator it = begin(); it != end(); ++it) {
         if ((*it)->fileName() == x) {
-          return it;
+          return *it;
         }
       }
-      return end();
+      return 0;
     }
 
     // @since 1.1.0
-    KstDataSourceList::Iterator findReusableFileName(const QString& x) {
+    KstDataSourcePtr findReusableFileName(const QString& x) {
       for (KstDataSourceList::Iterator it = begin(); it != end(); ++it) {
         if ((*it)->reusable() && (*it)->fileName() == x) {
-          return it;
+          return *it;
         }
       }
-      return end();
+      return 0;
     }
 
     // @since 1.1.0
--- branches/work/kst/portto4/kst/src/libkst/kstrmatrix.cpp #716949:716950
@@ -62,7 +62,7 @@
         in_tag = e.text();
       } else if (e.tagName() == "file") {
         KST::dataSourceList.lock().readLock();
-        in_file = *KST::dataSourceList.findFileName(e.text());
+        in_file = KST::dataSourceList.findFileName(e.text());
         KST::dataSourceList.lock().unlock();
       } else if (e.tagName() == "provider") {
         KST::dataSourceList.lock().readLock();
--- branches/work/kst/portto4/kst/src/libkst/kstrvector.cpp #716949:716950
@@ -77,9 +77,9 @@
   if (!in_provider && !file.isEmpty()) {
     KST::dataSourceList.lock().readLock();
     if (o_file == "|") {
-      in_file = *KST::dataSourceList.findFileName(file);
+      in_file = KST::dataSourceList.findFileName(file);
     } else {
-      in_file = *KST::dataSourceList.findFileName(o_file);
+      in_file = KST::dataSourceList.findFileName(o_file);
     }
     KST::dataSourceList.lock().unlock();
   }
--- branches/work/kst/portto4/kst/src/libkstapp/vectordialog.cpp #716949:716950
@@ -15,7 +15,11 @@
 
 #include "kstsvector.h"
 
+#include "kstdatacollection.h"
+#include "kstdataobjectcollection.h"
+
 #include <QDir>
+#include <QUrl>
 
 namespace Kst {
 
@@ -29,8 +33,13 @@
           this, SLOT(readFromSourceChanged()));
   connect(_fileName, SIGNAL(changed(const QString &)),
           this, SLOT(fileNameChanged(const QString &)));
+  connect(_configure, SIGNAL(clicked()),
+          this, SLOT(showConfigWidget()));
 
   _fileName->setFile(QDir::currentPath());
+
+  //FIXME need a solution for replacing kio for this...
+  _connect->setVisible(false);
 }
 
 
@@ -77,13 +86,60 @@
 
 
 void VectorTab::fileNameChanged(const QString &file) {
-  //FIXME deep magic...
   QFileInfo info(file);
-  if (info.exists() && info.isFile())
-    qDebug() << "fileNameChanged" << endl;
+  if (!info.exists() || !info.isFile())
+    return;
+
+  _field->clear();
+
+  KST::dataSourceList.lock().readLock();
+
+  KstDataSourcePtr ds = KST::dataSourceList.findReusableFileName(QUrl(file));
+  KST::dataSourceList.lock().unlock();
+
+  //FIXME this can't be good...
+  delete _configWidget;
+  _configWidget = 0L;
+
+  QStringList list;
+  if (ds) {
+
+    ds->readLock();
+    list = ds->fieldList();
+    _field->setEditable(!ds->fieldListIsComplete());
+    _configWidget = ds->configWidget();
+    ds->unlock();
+    _field->setEnabled(true);
+    //_dataRange->setAllowTime(ds->supportsTimeConversions());
+
+  } else {
+
+    QString type;
+    bool complete = false;
+
+    list = KstDataSource::fieldListForSource(QUrl(file), QString::null, &type, &complete);
+
+    _field->setEditable(!complete);
+    _field->setEnabled(!list.isEmpty());
+
+    if (!list.isEmpty() && !type.isEmpty()) {
+      _configWidget = KstDataSource::configWidgetForSource(QUrl(file), type);
+    }
+
+    //_dataRange->setAllowTime(KstDataSource::supportsTime(QUrl(file), type));
+  }
+
+  _configure->setEnabled(_configWidget);
+
+  _field->addItems(list);
 }
 
 
+void VectorTab::showConfigWidget() {
+  _configWidget->show();
+}
+
+
 VectorDialog::VectorDialog(QWidget *parent)
   : DataDialog(parent) {
 
@@ -101,6 +157,8 @@
 
   _vectorTab = new VectorTab(this);
   addDataTab(_vectorTab);
+
+  //FIXME need to do validation to enable/disable ok button...
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/vectordialog.h #716949:716950
@@ -17,8 +17,12 @@
 
 #include "ui_vectortab.h"
 
+#include <QPointer>
+
 #include "kst_export.h"
 
+class KstDataSourceConfigWidget;
+
 namespace Kst {
 
 class KST_EXPORT VectorTab : public DialogTab, Ui::VectorTab {
@@ -45,9 +49,12 @@
   private Q_SLOTS:
     void readFromSourceChanged();
     void fileNameChanged(const QString &file);
+    void showConfigWidget();
 
   private:
     Mode _mode;
+
+    QPointer<KstDataSourceConfigWidget> _configWidget;
 };
 
 class KST_EXPORT VectorDialog : public DataDialog {
--- branches/work/kst/portto4/kst/src/widgets/filerequester.cpp #716949:716950
@@ -80,7 +80,7 @@
 
 void FileRequester::chooseFile() {
 
-  QString file = QFileDialog::getOpenFileName(this);
+  QString file = QFileDialog::getOpenFileName(this, QString(), _file);
   if (!file.isEmpty()) {
     setFile(file);
   }


More information about the Kst mailing list