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

Peter Kümmel syntheticpp at gmx.net
Thu Feb 10 16:11:33 CET 2011


SVN commit 1219721 by kuemmel:

recent files: same logic for data sources

 M  +8 -4      datawizard.cpp  
 M  +5 -2      datawizard.h  
 M  +44 -18    mainwindow.cpp  
 M  +11 -5     mainwindow.h  


--- branches/work/kst/portto4/kst/src/libkstapp/datawizard.cpp #1219720:1219721
@@ -37,7 +37,7 @@
 
 namespace Kst {
 
-DataWizardPageDataSource::DataWizardPageDataSource(ObjectStore *store, QWidget *parent)
+DataWizardPageDataSource::DataWizardPageDataSource(ObjectStore *store, QWidget *parent, const QString& default_source)
   : QWizardPage(parent), _pageValid(false), _store(store), _requestID(0) {
    setupUi(this);
 
@@ -46,8 +46,11 @@
    connect(_url, SIGNAL(changed(const QString&)), this, SLOT(sourceChanged(const QString&)));
    connect(_configureSource, SIGNAL(clicked()), this, SLOT(configureSource()));
 
-   QString default_source = _dialogDefaults->value("vector/datasource",".").toString();
+   if (default_source.isEmpty()) {
+    _url->setFile(_dialogDefaults->value("vector/datasource",".").toString());
+   } else {
   _url->setFile(default_source);
+   }
   _url->setFocus();
 
   _updateBox->addItem("Time interval");
@@ -641,7 +644,7 @@
 }
 
 
-DataWizard::DataWizard(QWidget *parent)
+DataWizard::DataWizard(QWidget *parent, const QString& fileToOpen)
   : QWizard(parent), _document(0) {
 
   if (MainWindow *mw = qobject_cast<MainWindow*>(parent)) {
@@ -652,7 +655,7 @@
   }
 
   Q_ASSERT(_document);
-  _pageDataSource = new DataWizardPageDataSource(_document->objectStore(), this);
+  _pageDataSource = new DataWizardPageDataSource(_document->objectStore(), this, fileToOpen);
   _pageVectors = new DataWizardPageVectors(this);
   _pageDataPresentation = new DataWizardPageDataPresentation(_document->objectStore(), this);
   _pageFilters = new DataWizardPageFilters(this);
@@ -718,6 +721,7 @@
     return;
   }
 
+  emit dataSourceLoaded(ds->fileName());
 
   // check for sufficient memory
   unsigned long memoryRequested = 0, memoryAvailable = 1024*1024*1024; // 1GB
--- branches/work/kst/portto4/kst/src/libkstapp/datawizard.h #1219720:1219721
@@ -38,7 +38,7 @@
 {
   Q_OBJECT
   public:
-    DataWizardPageDataSource(ObjectStore *store, QWidget *parent);
+    DataWizardPageDataSource(ObjectStore *store, QWidget *parent, const QString& filename);
     virtual ~DataWizardPageDataSource();
 
   bool isComplete() const;
@@ -175,7 +175,7 @@
   public:
     enum DataWizardPages {PageDataSource, PageVectors, PageDataPresentation, PageFilters, PagePlot};
 
-    DataWizard(QWidget *parent);
+    DataWizard(QWidget *parent, const QString& fn = QString());
     virtual ~DataWizard();
 
     QStringList dataSourceFieldList() const;
@@ -187,6 +187,9 @@
     DataWizardPagePlot *_pagePlot;
     DataWizardPageDataPresentation *_pageDataPresentation;
 
+  Q_SIGNALS:
+    void dataSourceLoaded(const QString&);
+
   private Q_SLOTS:
     void finished();
 
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #1219720:1219721
@@ -103,7 +103,7 @@
 
   QTimer::singleShot(0, this, SLOT(performHeavyStartupActions()));
 
-  updateRecentFiles();
+  updateRecentKstFiles();
 }
 
 
@@ -230,7 +230,7 @@
   _doc->save(fn);
   QDir::setCurrent(restorePath);
   setWindowTitle("Kst - " + fn);
-  updateRecentFiles(fn);
+  updateRecentKstFiles(fn);
 }
 
 
@@ -276,7 +276,7 @@
 
 
 
-QAction* MainWindow::createRecentFileAction(const QString& filename, int idx, const QString& name)
+QAction* MainWindow::createRecentFileAction(const QString& filename, int idx, const QString& name, const char* openslot)
 {
   QAction* action = new QAction(this);
   QString text = tr("&%1 %2").arg(idx).arg(name);
@@ -284,20 +284,31 @@
   action->setData(filename);
   action->setStatusTip(filename);
   action->setVisible(true);
-  connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
+  connect(action, SIGNAL(triggered()), this, openslot);
   return action;
 }
 
 
-void MainWindow::updateRecentFiles(const QString& newfilename)
+void MainWindow::updateRecentKstFiles(const QString& filename)
 {
-  foreach(QAction* it, _bottomRecentFiles) {
-    _fileMenu->removeAction(it);
+  updateRecentFiles("recentKstFileList", _fileMenu, _bottomRecentKstActions, _recentKstFilesMenu, filename, SLOT(openRecentKstFile()));
+}
+
+
+void MainWindow::updateRecentDataFiles(const QString& filename)
+{
+  updateRecentFiles("recentDataFileList", _toolsMenu, _bottomRecentDataActions, _recentDataFilesMenu, filename, SLOT(openRecentDataFile()));
+}
+
+
+void MainWindow::updateRecentFiles(const QString& key, QMenu* menu, QList<QAction*>& actions, QMenu* submenu, const QString& newfilename, const char* openslot)
+{
+  foreach(QAction* it, actions) {
+    menu->removeAction(it);
     delete it;
   }
-  _bottomRecentFiles.clear();
+  actions.clear();
   QSettings settings("Kst2");
-  QString key = "recentKstFiles";
   QStringList recentFiles = settings.value(key).toStringList();
   if (recentFiles.removeDuplicates() > 0) {
     settings.setValue(key, recentFiles);
@@ -309,21 +320,21 @@
     settings.setValue(key, recentFiles);
   }
   int i = 0;
-  _recentFilesMenu->clear();
+  submenu->clear();
   foreach(const QString& it, recentFiles) {
     i++;
     if (i <= 5) {
       // don't make file menu to wide, show complete path in statusbar
-      QAction* action = createRecentFileAction(it, i, QFileInfo(it).fileName());
-      _bottomRecentFiles << action;
-      _fileMenu->addAction(action);
+      QAction* action = createRecentFileAction(it, i, QFileInfo(it).fileName(), openslot);
+      actions << action;
+      menu->addAction(action);
     }
-    _recentFilesMenu->addAction(createRecentFileAction(it, i, it));
+    submenu->addAction(createRecentFileAction(it, i, it, openslot));
   }
 }
 
 
-void MainWindow::openRecentFile()
+void MainWindow::openRecentKstFile()
 {
   QAction *action = qobject_cast<QAction *>(sender());
   if (action) {
@@ -333,6 +344,7 @@
 
 
 
+
 bool MainWindow::initFromCommandLine() {
   delete _doc;
   _doc = new Document(this);
@@ -377,7 +389,7 @@
   }
 
   setWindowTitle("Kst - " + file);
-  updateRecentFiles(file);
+  updateRecentKstFiles(file);
 }
 
 
@@ -1146,7 +1158,7 @@
   _fileMenu->addAction(_saveAct);
   _fileMenu->addAction(_saveAsAct);
   _fileMenu->addAction(_closeAct);
-  _recentFilesMenu = _fileMenu->addMenu(tr("&Recent Files"));
+  _recentKstFilesMenu = _fileMenu->addMenu(tr("&Recent Files"));
   _fileMenu->addSeparator();
   // Reload, isolate it a bit from the other entries to avoid inadvertent triggering
   _fileMenu->addAction(_reloadAct);
@@ -1165,7 +1177,7 @@
   _fileMenu->addAction(_exitAct);
   // recent files
   _fileMenu->addSeparator();
-  updateRecentFiles();
+  updateRecentKstFiles();
 
 
   _editMenu = menuBar()->addMenu(tr("&Edit"));
@@ -1260,9 +1272,11 @@
   _toolsMenu = menuBar()->addMenu(tr("&Tools"));
   _toolsMenu->addAction(_dataManagerAct);
   _toolsMenu->addAction(_dataWizardAct);
+  _recentDataFilesMenu = _toolsMenu->addMenu("&Recent Data File");
   _toolsMenu->addAction(_changeFileDialogAct);
   _toolsMenu->addAction(_chooseColorDialogAct);
   _toolsMenu->addAction(_differentiateCurvesDialogAct);
+  _toolsMenu->addSeparator();
 
   _settingsMenu = menuBar()->addMenu(tr("&Settings"));
   _settingsMenu->addAction(_settingsDialogAct);
@@ -1684,10 +1698,22 @@
 
 void MainWindow::showDataWizard() {
   DataWizard *dataWizard = new DataWizard(this);
+  connect(dataWizard, SIGNAL(dataSourceLoaded(const QString&)), this, SLOT(updateRecentDataFiles(const QString&)));
   dataWizard->show();
 }
 
 
+void MainWindow::openRecentDataFile()
+{
+  QAction *action = qobject_cast<QAction *>(sender());
+  if (action) {
+    DataWizard *dataWizard = new DataWizard(this, action->data().toString());
+    connect(dataWizard, SIGNAL(dataSourceLoaded(const QString&)), this, SLOT(updateRecentDataFiles(const QString&)));
+    dataWizard->show();
+  }
+}
+
+
 void MainWindow::showBugReportWizard() {
   if (!_bugReportWizard) {
     _bugReportWizard = new BugReportWizard(this);
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.h #1219720:1219721
@@ -145,7 +145,10 @@
     void setHighlightPoint(bool);
     void changeZoomOnlyMode(QAction*);
 
-    void openRecentFile();
+    void openRecentKstFile();
+    void openRecentDataFile();
+    void updateRecentKstFiles(const QString& newfilename = QString());
+    void updateRecentDataFiles(const QString& newfilename = QString());
 
   protected:
     void closeEvent(QCloseEvent *e);
@@ -160,9 +163,10 @@
     void writeSettings();
     bool promptSave();
 
-    QAction* createRecentFileAction(const QString& filename, int idx, const QString& text);
-    void updateRecentFiles(const QString& filename = QString());
+    QAction* createRecentFileAction(const QString& filename, int idx, const QString& text, const char* openslot);
+    void updateRecentFiles(const QString& key, QMenu *menu, QList<QAction*>& actions, QMenu* submenu, const QString& newfilename, const char* openslot);
 
+
   private:
     Document *_doc;
     TabWidget *_tabWidget;
@@ -276,8 +280,10 @@
     QAction *_newSpectrogramAct;
     QAction *_newEventMonitorAct;
 
-    QMenu* _recentFilesMenu;
-    QList<QAction*> _bottomRecentFiles;
+    QMenu* _recentKstFilesMenu;
+    QMenu* _recentDataFilesMenu;
+    QList<QAction*> _bottomRecentKstActions;
+    QList<QAction*> _bottomRecentDataActions;
 };
 
 }


More information about the Kst mailing list