From 324fb229c172821dac62f9bf433b8d581c922d69 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Fri, 13 Oct 2006 01:31:41 +0000 Subject: [PATCH] pass default_dir around 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 | 19 +++++++++++++--- qui/ImageSaveDialog.hpp | 11 +++++++--- qui/MussaAlignedWindow.cpp | 5 ++++- qui/MussaAlignedWindow.hpp | 8 +++++-- qui/MussaWindow.cpp | 28 ++++++++++++------------ qui/MussaWindow.hpp | 2 +- qui/seqbrowser/SequenceBrowserWidget.cpp | 10 ++++++--- qui/seqbrowser/SequenceBrowserWidget.hpp | 4 +++- 8 files changed, 59 insertions(+), 28 deletions(-) diff --git a/qui/ImageSaveDialog.cpp b/qui/ImageSaveDialog.cpp index 0357af4..3a0a63f 100644 --- a/qui/ImageSaveDialog.cpp +++ b/qui/ImageSaveDialog.cpp @@ -12,8 +12,14 @@ #include -ImageSaveDialog::ImageSaveDialog(QGLWidget *newglwidget, QWidget *parent) - : QDialog(parent) +#include +namespace fs = boost::filesystem; + +ImageSaveDialog::ImageSaveDialog(boost::shared_ptr 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()); } } diff --git a/qui/ImageSaveDialog.hpp b/qui/ImageSaveDialog.hpp index 411bfe9..637e85f 100644 --- a/qui/ImageSaveDialog.hpp +++ b/qui/ImageSaveDialog.hpp @@ -1,7 +1,10 @@ #ifndef _IMAGESAVEDIALOG_H_ #define _IMAGESAVEDIALOG_H_ + +#include #include +#include 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 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 default_dir; ImageScaler *imageScaler; QPushButton *saveButton; QPushButton *cancelButton; diff --git a/qui/MussaAlignedWindow.cpp b/qui/MussaAlignedWindow.cpp index 9d6ff3f..92b96eb 100644 --- a/qui/MussaAlignedWindow.cpp +++ b/qui/MussaAlignedWindow.cpp @@ -12,13 +12,16 @@ #include using namespace std; -MussaAlignedWindow::MussaAlignedWindow(MussaRef m, +MussaAlignedWindow::MussaAlignedWindow(MussaRef m, + boost::shared_ptr default_dir_, const set& 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), diff --git a/qui/MussaAlignedWindow.hpp b/qui/MussaAlignedWindow.hpp index 6f6aaf8..f92e085 100644 --- a/qui/MussaAlignedWindow.hpp +++ b/qui/MussaAlignedWindow.hpp @@ -5,6 +5,7 @@ #include +#include #include #include #include @@ -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& paths, + MussaAlignedWindow(MussaRef analysis, + boost::shared_ptr default_dir, + const std::set& paths, SubanalysisWindowRef window, QWidget *parent=0); public slots: @@ -56,7 +59,8 @@ protected: void setupAlignmentMenus(); void computeMatchLines(); - MussaRef analysis; + MussaRef analysis; + boost::shared_ptr default_dir; //std::vector sequences; //const std::set& selected_paths; std::vector selected_paths; diff --git a/qui/MussaWindow.cpp b/qui/MussaWindow.cpp index 005cc16..36727a1 100644 --- a/qui/MussaWindow.cpp +++ b/qui/MussaWindow.cpp @@ -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 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); diff --git a/qui/MussaWindow.hpp b/qui/MussaWindow.hpp index aff3c6f..a64c46f 100644 --- a/qui/MussaWindow.hpp +++ b/qui/MussaWindow.hpp @@ -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 default_dir; std::list > aligned_windows; MotifEditor *motif_editor; MussaSetupDialog *setup_analysis_dialog; diff --git a/qui/seqbrowser/SequenceBrowserWidget.cpp b/qui/seqbrowser/SequenceBrowserWidget.cpp index 0ce3030..6a452fa 100644 --- a/qui/seqbrowser/SequenceBrowserWidget.cpp +++ b/qui/seqbrowser/SequenceBrowserWidget.cpp @@ -18,9 +18,13 @@ #include using namespace std; -SequenceBrowserWidget::SequenceBrowserWidget(QWidget *parent) +SequenceBrowserWidget::SequenceBrowserWidget( + boost::shared_ptr 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(); } diff --git a/qui/seqbrowser/SequenceBrowserWidget.hpp b/qui/seqbrowser/SequenceBrowserWidget.hpp index fedb86f..e8f75ad 100644 --- a/qui/seqbrowser/SequenceBrowserWidget.hpp +++ b/qui/seqbrowser/SequenceBrowserWidget.hpp @@ -4,6 +4,7 @@ #include +#include #include #include "alg/sequence.hpp" @@ -17,7 +18,7 @@ class SequenceBrowserWidget : public QWidget Q_OBJECT public: - SequenceBrowserWidget(QWidget *parent=0); + SequenceBrowserWidget(boost::shared_ptr, 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 default_dir; ScrollableSequenceBrowser scrollable_browser; SequenceBrowserSidebar left_sidebar; SequenceBrowserSidebar right_sidebar; -- 2.30.2