From c087c60fe98c571a27e7508aa3d2ac14fb5d3893 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Tue, 3 Oct 2006 21:36:10 +0000 Subject: [PATCH] Add window titles this patch adds window titles to most of the windows that Mussa will popup. I refactored the code that figured out a reasonble title name from MussaWindow and put it into Mussa. This did mean that the SubanalysisWindow now needed its own copy of a MussaRef so it could ask the analysis for its name. --- alg/mussa.cpp | 19 ++++++++++++++++++- alg/mussa.hpp | 8 +++++++- alg/test/test_mussa.cpp | 14 ++++++++++++++ qui/MussaAlignedWindow.cpp | 11 +++++++++++ qui/MussaAlignedWindow.hpp | 3 +++ qui/MussaWindow.cpp | 9 ++------- qui/SubanalysisWindow.cpp | 14 +++++++++++++- qui/SubanalysisWindow.hpp | 9 +++++++-- qui/motif_editor/MotifEditor.cpp | 9 +++++---- qui/mussa_setup_dialog/MussaSetupDialog.cpp | 1 + 10 files changed, 81 insertions(+), 16 deletions(-) diff --git a/alg/mussa.cpp b/alg/mussa.cpp index 7226e43..c93990b 100644 --- a/alg/mussa.cpp +++ b/alg/mussa.cpp @@ -62,6 +62,11 @@ boost::filesystem::path Mussa::get_analysis_path() const return analysis_path; } +void Mussa::set_analysis_path(boost::filesystem::path pathname) +{ + analysis_path = pathname; +} + // set all parameters to null state void Mussa::clear() @@ -102,11 +107,23 @@ Mussa::set_name(string a_name) dirty = true; } -string Mussa::get_name() +string Mussa::get_name() const { return analysis_name; } +string Mussa::get_title() const +{ + fs::path analysis_path = get_analysis_path(); + if (not analysis_path.empty()) { + return analysis_path.native_file_string(); + } else if (get_name().size() > 0) { + return get_name(); + } else { + return std::string("Unnamed"); + } +} + int Mussa::size() const { diff --git a/alg/mussa.hpp b/alg/mussa.hpp index 84fcd92..cc80607 100644 --- a/alg/mussa.hpp +++ b/alg/mussa.hpp @@ -54,6 +54,8 @@ public: void load(boost::filesystem::path ana_path); // ! return path to the where the analysis is stored boost::filesystem::path get_analysis_path() const; + //! set analysis path + void set_analysis_path(boost::filesystem::path); //! clear parameters and initialize data lists void clear(); @@ -66,7 +68,11 @@ public: //! set analysis name void set_name(std::string a_name); //! return name for this analysis - std::string get_name(); + std::string get_name() const; + //! return a reasonable window title for this analysis + /*! this returns the "variable" portion for a title + */ + std::string get_title() const; //! return number of sequences in this analyzis /*! this returns either the_seqs.size() or seq_files.size() diff --git a/alg/test/test_mussa.cpp b/alg/test/test_mussa.cpp index bebb38d..068d44b 100644 --- a/alg/test/test_mussa.cpp +++ b/alg/test/test_mussa.cpp @@ -50,6 +50,20 @@ BOOST_AUTO_TEST_CASE( mussa_simple ) BOOST_CHECK_EQUAL(m.get_analysis_mode(), Mussa::TransitiveNway); } +BOOST_AUTO_TEST_CASE ( mussa_title ) +{ + Mussa m; + + BOOST_CHECK_EQUAL( m.get_title(), "Unnamed"); + string foo("foo"); + m.set_name(foo); + BOOST_CHECK_EQUAL( m.get_title(), foo); + string foopath_name("/my/silly/path"); + fs::path foopath(foopath_name); + m.set_analysis_path(foopath); + BOOST_CHECK_EQUAL( m.get_title(), foopath_name); +} + BOOST_AUTO_TEST_CASE( mussa_analysis_name ) { Mussa m; diff --git a/qui/MussaAlignedWindow.cpp b/qui/MussaAlignedWindow.cpp index 4daa5d8..9d6ff3f 100644 --- a/qui/MussaAlignedWindow.cpp +++ b/qui/MussaAlignedWindow.cpp @@ -56,6 +56,8 @@ MussaAlignedWindow::MussaAlignedWindow(MussaRef m, message << "Selected " << selected_paths.size() << " paths"; statusBar()->showMessage(message.str().c_str(), 5000); browser.updatePosition(); + + updateTitle(); } void MussaAlignedWindow::setupActions() @@ -199,6 +201,15 @@ void MussaAlignedWindow::update() browser.update(); } +void MussaAlignedWindow::updateTitle() +{ + std::string title("Sequence View: "); + if (analysis) { + title += analysis->get_title(); + } + setWindowTitle(title.c_str()); +} + void MussaAlignedWindow::computeMatchLines() { browser.clear_links(); diff --git a/qui/MussaAlignedWindow.hpp b/qui/MussaAlignedWindow.hpp index f67e5b3..6f6aaf8 100644 --- a/qui/MussaAlignedWindow.hpp +++ b/qui/MussaAlignedWindow.hpp @@ -41,6 +41,9 @@ public slots: //! just force updating the window void update(); + + //! set the title based on the analysis + void updateTitle(); protected: // figure out what Alignments we have (needed for setupAlignmentMenus) diff --git a/qui/MussaWindow.cpp b/qui/MussaWindow.cpp index 0170230..09d6ee9 100644 --- a/qui/MussaWindow.cpp +++ b/qui/MussaWindow.cpp @@ -35,7 +35,7 @@ MussaWindow::MussaWindow(MussaRef analysis_, QWidget *parent) : default_dir(QDir::home().absolutePath().toStdString(), fs::native), motif_editor(0), setup_analysis_dialog(new MussaSetupDialog(this)), - subanalysis_window(new SubanalysisWindow), + subanalysis_window(new SubanalysisWindow(analysis)), browser(new SequenceBrowserWidget(this)), mussaViewTB(new QToolBar("Path Views")), zoom(new ZoomWidget), @@ -720,11 +720,6 @@ MussaWindow::updateProgress(const string& description, int current, int max) void MussaWindow::updateTitle() { if (analysis) { - fs::path analysis_path = analysis->get_analysis_path(); - if (not analysis_path.empty()) { - setWindowTitle(analysis_path.native_file_string().c_str()); - } else if (analysis->get_name().size() > 0) { - setWindowTitle(analysis->get_name().c_str()); - } + setWindowTitle(analysis->get_title().c_str()); } } diff --git a/qui/SubanalysisWindow.cpp b/qui/SubanalysisWindow.cpp index 34ef9aa..1ecbcbc 100644 --- a/qui/SubanalysisWindow.cpp +++ b/qui/SubanalysisWindow.cpp @@ -8,8 +8,9 @@ #include #include -SubanalysisWindow::SubanalysisWindow(QWidget *parent) +SubanalysisWindow::SubanalysisWindow(MussaRef m, QWidget *parent) : QWidget(parent), + analysis(m), window(0), threshold(0), table(0), @@ -56,6 +57,8 @@ SubanalysisWindow::SubanalysisWindow(QWidget *parent) this, SLOT(modelUpdated(const QModelIndex&, int, int))); connect(&model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), this, SLOT(modelUpdated(const QModelIndex&, int, int))); + + updateTitle(); } SequenceLocationModel& SubanalysisWindow::getModel() @@ -105,3 +108,12 @@ void SubanalysisWindow::modelUpdated(const QModelIndex&, int, int ) // if the model is empty we shouldn't be able to click ok if (ok) ok->setEnabled(not model.empty()); } + +void SubanalysisWindow::updateTitle() +{ + std::string title("Subanalysis: "); + if (analysis) { + title += analysis->get_title(); + } + setWindowTitle(title.c_str()); +} \ No newline at end of file diff --git a/qui/SubanalysisWindow.hpp b/qui/SubanalysisWindow.hpp index 0bf3294..9d9ef73 100644 --- a/qui/SubanalysisWindow.hpp +++ b/qui/SubanalysisWindow.hpp @@ -8,13 +8,14 @@ #include #include "qui/SequenceLocationModel.hpp" +#include "alg/mussa.hpp" class SubanalysisWindow : public QWidget { Q_OBJECT public: - SubanalysisWindow(QWidget *parent = 0); + SubanalysisWindow(MussaRef m, QWidget *parent = 0); //! return a modifiable reference to our SequenceLocationModel SequenceLocationModel& getModel(); @@ -26,8 +27,12 @@ public slots: void run(); //! provide a way for the model to tell us to update our gui void modelUpdated(const QModelIndex&, int, int); + //! update our title + void updateTitle(); -private: +private: + //! keep track of what analysis we're attached to + MussaRef analysis; QSpinBox *window; QSpinBox *threshold; QTableView *table; diff --git a/qui/motif_editor/MotifEditor.cpp b/qui/motif_editor/MotifEditor.cpp index e5e559e..93178d6 100644 --- a/qui/motif_editor/MotifEditor.cpp +++ b/qui/motif_editor/MotifEditor.cpp @@ -79,10 +79,11 @@ void MotifEditor::updateMotifs() void MotifEditor::updateTitle() { - QString title("Motif Editor: "); - title.append(analysis->get_name().c_str()); - setWindowTitle(title); - + std::string title("Motif Editor: "); + if (analysis) { + title += analysis->get_title(); + } + setWindowTitle(title.c_str()); } void MotifEditor::updateView() diff --git a/qui/mussa_setup_dialog/MussaSetupDialog.cpp b/qui/mussa_setup_dialog/MussaSetupDialog.cpp index dcbd179..3d214d1 100644 --- a/qui/mussa_setup_dialog/MussaSetupDialog.cpp +++ b/qui/mussa_setup_dialog/MussaSetupDialog.cpp @@ -11,6 +11,7 @@ MussaSetupDialog::MussaSetupDialog(QWidget *parent, Qt::WFlags f) : QDialog(parent, f), setupWidget(0) { + setWindowTitle("Define New Analysis"); setupWidget = new MussaSetupWidget; connect(setupWidget, SIGNAL(createButtonPushed()), -- 2.30.2