pass default_dir around
authorDiane Trout <diane@caltech.edu>
Fri, 13 Oct 2006 01:31:41 +0000 (01:31 +0000)
committerDiane Trout <diane@caltech.edu>
Fri, 13 Oct 2006 01:31:41 +0000 (01:31 +0000)
convert default_dir to be a shared_ptr and then pass it around
all of our windows that need to save things. Pretty much now
whenever someone saves something we'll remember that last directory
and use it as our default dir.

I hope this works on windows, if it breaks, there
might be a few fs::natives that are needed.

qui/ImageSaveDialog.cpp
qui/ImageSaveDialog.hpp
qui/MussaAlignedWindow.cpp
qui/MussaAlignedWindow.hpp
qui/MussaWindow.cpp
qui/MussaWindow.hpp
qui/seqbrowser/SequenceBrowserWidget.cpp
qui/seqbrowser/SequenceBrowserWidget.hpp

index 0357af402dc97c7585c1a2995b4d8053d045c8c1..3a0a63f36fa3cb0f297a86d1813e3c0ae3a0b0d0 100644 (file)
 
 #include <iostream>
 
-ImageSaveDialog::ImageSaveDialog(QGLWidget *newglwidget, QWidget *parent)
-  : QDialog(parent)
+#include <boost/filesystem/path.hpp>
+namespace fs = boost::filesystem;
+
+ImageSaveDialog::ImageSaveDialog(boost::shared_ptr<QDir> default_dir_,
+                                 QGLWidget *newglwidget, 
+                                 QWidget *parent)
+  : QDialog(parent),
+    default_dir(default_dir_)
 {
   setWindowTitle(tr("Mussa Save Image"));
 
@@ -60,6 +66,11 @@ ImageSaveDialog::ImageSaveDialog(QGLWidget *newglwidget, QWidget *parent)
   setLayout(layout);
 }
 
+QDir ImageSaveDialog::defaultDir() const
+{
+  return *default_dir;
+}
+
 void ImageSaveDialog::accept()
 {
   bool endDialog = true;
@@ -113,7 +124,7 @@ void ImageSaveDialog::savePixmap(bool &endDialog)
   QString filePath;
   filePath = QFileDialog::getSaveFileName(this,
             "Choose a filename to save image",
-            ".",
+            default_dir->absolutePath(),
             "Images (*.png *.jpg)");  
 
   if (filePath.isNull()) {
@@ -136,5 +147,7 @@ void ImageSaveDialog::savePixmap(bool &endDialog)
       filePath.append(".png");
       pixmap.save(filePath, "PNG");
     }
+    fs::path path(filePath.toStdString(), fs::native);
+    default_dir->setPath(path.branch_path().native_directory_string().c_str());
   }
 }
index 411bfe97d5951176539d6f4a4df505f0f134d7bf..637e85f42b48c53b08831bc77dfd90fb15111d48 100644 (file)
@@ -1,7 +1,10 @@
 #ifndef _IMAGESAVEDIALOG_H_
 #define _IMAGESAVEDIALOG_H_
+
+#include <boost/shared_ptr.hpp>
  
 #include <QDialog>
+#include <QDir>
 
 class ImageScaler;
 class QLabel;
@@ -14,8 +17,9 @@ class ImageSaveDialog : public QDialog
   Q_OBJECT
 
 public:
-  ImageSaveDialog(QGLWidget *qlwidget = 0, QWidget *parent = 0);
-
+  ImageSaveDialog(boost::shared_ptr<QDir> default_dir_, QGLWidget *qlwidget = 0, QWidget *parent = 0);
+  QDir defaultDir() const;
+  
 public slots:
   void accept();
   void reject();
@@ -30,7 +34,8 @@ private:
   void savePixmap(bool &endDialog);
   QSize getOpenGlPixmapSize();
   QPixmap renderOpenGlPixmap();
-
+  
+  boost::shared_ptr<QDir> default_dir;
   ImageScaler *imageScaler;
   QPushButton *saveButton;
   QPushButton *cancelButton;
index 9d6ff3f640248efd3a1a6617a473bb825576a395..92b96eb9e538796409a1c53766c369d3cf1e38de 100644 (file)
 #include <iostream>
 using namespace std;
 
-MussaAlignedWindow::MussaAlignedWindow(MussaRef m, 
+MussaAlignedWindow::MussaAlignedWindow(MussaRef m,
+                                       boost::shared_ptr<QDir> default_dir_,
                                        const set<int>& sel_paths,
                                        SubanalysisWindowRef window, 
                                        QWidget *parent)
   : QMainWindow(parent),
     analysis(m),
+    default_dir(default_dir_),
     subanalysis_window(window),
+    browser(default_dir),
     pick_align_menu(tr("Choose Alignment")),
     view_align_menu(tr("View Alignment")),
     threshold_widget(0),
index 6f6aaf83eee8aaf6022a3e0dbb4005c8f5b36f59..f92e0859b638a6964c29fb98509966e6960bce52 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <boost/shared_ptr.hpp>
 
+#include <QDir>
 #include <QMainWindow>
 #include <QMenu>
 #include <QToolBar>
@@ -28,7 +29,9 @@ public:
    *         sequence portions from both the mussa window and the sequence view window
    *  \param parent is the typical Qt pointer to a parent widget
    */ 
-  MussaAlignedWindow(MussaRef analysis, const std::set<int>& paths, 
+  MussaAlignedWindow(MussaRef analysis, 
+                     boost::shared_ptr<QDir> default_dir,
+                     const std::set<int>& paths, 
                      SubanalysisWindowRef window, QWidget *parent=0);
 
 public slots:
@@ -56,7 +59,8 @@ protected:
   void setupAlignmentMenus();
   void computeMatchLines();
   
-  MussaRef analysis;  
+  MussaRef analysis;
+  boost::shared_ptr<QDir> default_dir;
   //std::vector<Sequence> sequences;
   //const std::set<int>& selected_paths;
   std::vector<ConservedPath> selected_paths;
index 005cc1629625fea0ac619f0975fd32478ecadf60..36727a1635dd617670561688798bd5d789e0d855 100644 (file)
@@ -32,11 +32,11 @@ using namespace std;
 MussaWindow::MussaWindow(MussaRef analysis_, QWidget *parent) :
   QMainWindow(parent),
   analysis(analysis_),
-  default_dir(QDir::home().absolutePath()),
+  default_dir(new QDir(QDir::home().absolutePath())),
   motif_editor(0),
   setup_analysis_dialog(new MussaSetupDialog(this)),
   subanalysis_window(new SubanalysisWindow(analysis)),
-  browser(new SequenceBrowserWidget(this)),  
+  browser(new SequenceBrowserWidget(default_dir, this)),  
   mussaViewTB(new QToolBar("Path Views")),
   zoom(new ZoomWidget),
   threshold(new ThresholdWidget),
@@ -354,7 +354,7 @@ void MussaWindow::saveAnalysisAs()
   std::auto_ptr<QFileDialog> dialog(new QFileDialog(this));
   dialog->setAcceptMode(QFileDialog::AcceptSave);
   dialog->setFileMode(QFileDialog::AnyFile);
-  dialog->setDirectory(default_dir);
+  dialog->setDirectory(*default_dir);
 
   QStringList fileNames;
   if (not dialog->exec()) {
@@ -381,7 +381,7 @@ void MussaWindow::saveAnalysisAs()
   }
   analysis->save(save_path);
   fs::path normalized_path = (save_path / "..").normalize();   
-  default_dir = normalized_path.native_directory_string().c_str();
+  default_dir->setPath(normalized_path.native_directory_string().c_str());
 }
 
 bool MussaWindow::isClearingAnalysisSafe()
@@ -431,7 +431,7 @@ void MussaWindow::loadMotifList()
   QString filter("Motif list(*.txt *.mtl)");
   QString path = QFileDialog::getOpenFileName(this,
                                               caption, 
-                                              default_dir.absolutePath(),
+                                              default_dir->absolutePath(),
                                               filter);
   // user hit cancel?
   if (path.isNull()) 
@@ -440,7 +440,7 @@ void MussaWindow::loadMotifList()
   try {
     fs::path converted_path(path.toStdString(), fs::native);
     analysis->load_motifs(converted_path);
-    default_dir = converted_path.branch_path().native_directory_string().c_str();
+    default_dir->setPath(converted_path.branch_path().native_directory_string().c_str());
     emit changedMotifs();
   } catch (runtime_error e) {
     QString msg("Unable to load ");
@@ -457,7 +457,7 @@ void MussaWindow::saveMotifList()
   QString filter("Motif list(*.txt *.mtl)");
   QString path = QFileDialog::getSaveFileName(this,
                                               caption, 
-                                              default_dir.absolutePath(),
+                                              default_dir->absolutePath(),
                                               filter);
   // user hit cancel?
   if (path.isNull()) 
@@ -466,7 +466,7 @@ void MussaWindow::saveMotifList()
   try {
     fs::path converted_path(path.toStdString(), fs::native);
     analysis->save_motifs(converted_path);
-    default_dir = converted_path.branch_path().native_directory_string().c_str();
+    default_dir->setPath(converted_path.branch_path().native_directory_string().c_str());
   } catch (runtime_error e) {
     QString msg("Unable to save ");
     msg += path;
@@ -482,7 +482,7 @@ void MussaWindow::loadMupa()
   QString mupa_path = QFileDialog::getOpenFileName(
                          this,
                          caption, 
-                         default_dir.absolutePath(),
+                         default_dir->absolutePath(),
                          filter
                       );
   // user hit cancel?
@@ -503,7 +503,7 @@ void MussaWindow::loadMupa()
     setAnalysis(m);
     updateTitle();
     // grab the path ignoring the mupa file portion
-    default_dir = converted_path.branch_path().native_directory_string().c_str();
+    default_dir->setPath(converted_path.branch_path().native_directory_string().c_str());
   } catch (mussa_load_error e) {
     QString msg("Unable to load ");
     msg += mupa_path;
@@ -520,7 +520,7 @@ void MussaWindow::loadSavedAnalysis()
   QString muway_dir = QFileDialog::getExistingDirectory(
                         this,
                         caption, 
-                        default_dir.absolutePath()
+                        default_dir->absolutePath()
                      );
   // user hit cancel?
   if (muway_dir.isNull()) 
@@ -541,11 +541,11 @@ void MussaWindow::loadSavedAnalysis()
       // our current window is empty so load and replace.
       setAnalysis(m);
       updateTitle();
-      default_dir = converted_path.branch_path().native_directory_string().c_str();
+      default_dir->setPath(converted_path.branch_path().native_directory_string().c_str());
     } else {
       MussaWindow *win = new MussaWindow(m);
       updateTitle();
-      win->default_dir = converted_path.branch_path().native_directory_string().c_str();
+      win->default_dir->setPath(converted_path.branch_path().native_directory_string().c_str());
       win->show();
     }
   } catch (mussa_load_error e) {
@@ -641,7 +641,7 @@ void MussaWindow::viewMussaAlignment()
                                      "first"));
   } else {
     MussaAlignedWindowRef ma_win( 
-      new MussaAlignedWindow(analysis, selected_paths, subanalysis_window)
+      new MussaAlignedWindow(analysis, default_dir, selected_paths, subanalysis_window)
     );
 
     aligned_windows.push_back(ma_win);
index aff3c6ffbc9ef8d326556ac42bf95cc70fa2bb4e..a64c46f34413359b3356b10d00359984de041f58 100644 (file)
@@ -100,7 +100,7 @@ protected:
   //! shared_ptr to our analysis
   MussaRef analysis;
   //! the default directory we should loand and save from
-  QDir default_dir;
+  boost::shared_ptr<QDir> default_dir;
   std::list<boost::shared_ptr<MussaAlignedWindow> > aligned_windows;
   MotifEditor *motif_editor;
   MussaSetupDialog *setup_analysis_dialog;
index 0ce3030d48a9265226228d5f4f0e484740dd3490..6a452fa00808840689a4d92e95cc85361b612c78 100644 (file)
 #include <math.h>
 using namespace std;
 
-SequenceBrowserWidget::SequenceBrowserWidget(QWidget *parent)
+SequenceBrowserWidget::SequenceBrowserWidget(
+    boost::shared_ptr<QDir> default_dir_,
+    QWidget *parent
+)
   : QWidget(parent),
-    scrollable_browser(parent)
+    default_dir(default_dir_),
+    scrollable_browser(this)
 {
   QHBoxLayout *hlayout = new QHBoxLayout;
   hlayout->addWidget(&left_sidebar, 0);
@@ -181,7 +185,7 @@ void SequenceBrowserWidget::promptSaveBrowserPixmap()
   QSize size;
   size = scrollable_browser.browser().size();
   //Image Save Dialog
-  ImageSaveDialog imageSaveDialog(&scrollable_browser.browser(), this);
+  ImageSaveDialog imageSaveDialog(default_dir, &scrollable_browser.browser(), this);
   imageSaveDialog.setSize(size.width(), size.height());
   imageSaveDialog.exec();
 }
index fedb86f6accb8e0e2af22c79a8e3c7bcb2257215..e8f75adc4689c3624207b985f4fea73788e73601 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <boost/shared_ptr.hpp>
 
+#include <QDir>
 #include <QWidget>
 
 #include "alg/sequence.hpp"
@@ -17,7 +18,7 @@ class SequenceBrowserWidget : public QWidget
   Q_OBJECT 
 
 public:
-  SequenceBrowserWidget(QWidget *parent=0);
+  SequenceBrowserWidget(boost::shared_ptr<QDir>, QWidget *parent=0);
 
   //! return the popup menu for the glcanvas (reference stored internally)
   QMenu *getPopupMenu();
@@ -71,6 +72,7 @@ public slots:
   void update();
 
 private:
+  boost::shared_ptr<QDir> default_dir;
   ScrollableSequenceBrowser scrollable_browser;
   SequenceBrowserSidebar left_sidebar;
   SequenceBrowserSidebar right_sidebar;