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

Mike Fenton mike at staikos.net
Fri Nov 28 17:35:35 CET 2008


SVN commit 890240 by fenton:

Update DataSourceSelectorDialog to allow selection of directories and to clear file selection on directory change.


 M  +26 -2     datasourceselectordialog.cpp  
 M  +4 -0      datasourceselectordialog.h  


--- branches/work/kst/portto4/kst/src/widgets/datasourceselectordialog.cpp #890239:890240
@@ -14,14 +14,16 @@
 #include <QMessageBox>
 #include <QDebug>
 
-
 namespace Kst {
 
 DataSourceSelectorDialog::DataSourceSelectorDialog(QString &file, QWidget *parent)
   : QFileDialog(parent) {
 
-  setFileMode(QFileDialog::ExistingFile);
+  setFileMode(QFileDialog::Directory);
   selectFile(file);
+
+  connect(this, SIGNAL(directoryEntered(const QString &)), this, SLOT(directoryChanged()));
+  connect(this, SIGNAL(currentChanged(const QString &)), this, SLOT(currentChanged(const QString &)));
 }
 
 
@@ -34,6 +36,28 @@
 }
 
 
+void DataSourceSelectorDialog::directoryChanged() {
+//   qDebug() << "directory changed" << directory();
+}
+
+
+void DataSourceSelectorDialog::currentChanged(const QString &current) {
+//   qDebug() << "currentChanged" << current;
+  QFileInfo fileInfo(current);
+  if (fileInfo.isDir()) {
+//     qDebug() << "Directory Selected";
+    if (fileMode() != QFileDialog::Directory) {
+      setFileMode(QFileDialog::Directory);
+    }
+  } else if (fileInfo.exists()) {
+//     qDebug() << "File Selected";
+    if (fileMode() != QFileDialog::ExistingFile) {
+      setFileMode(QFileDialog::ExistingFile);
+    }
+  }
+}
+
+
 void DataSourceSelectorDialog::accept() {
   QStringList files = selectedFiles();
   if (files.isEmpty()) {
--- branches/work/kst/portto4/kst/src/widgets/datasourceselectordialog.h #890239:890240
@@ -26,6 +26,10 @@
 
     QString selectedDataSource();
 
+  public Q_SLOTS:
+    void directoryChanged();
+    void currentChanged(const QString &current);
+
   protected:
     void accept();
 };


More information about the Kst mailing list