From f0075b826a1bb9f02021325a3ff1af043cfc8047 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Mon, 2 Oct 2006 23:07:00 +0000 Subject: [PATCH] Make MussaWindow UI objects pointers It appears to me that Qt seems to like UI widgets that are attached to it to be pointers as it'll sometimes handle freeing said pointer, which is bad when its a statically allocated member of a class. So this patch tries to make most of the UI objects associated with MussaWindow pointers (I had to convert some elements of the SequenceBrowserWidget as MussaWindow was storing references to them.) --- qui/MussaAlignedWindow.cpp | 2 +- qui/MussaWindow.cpp | 92 +++++++++++++----------- qui/MussaWindow.hpp | 12 ++-- qui/seqbrowser/SequenceBrowser.cpp | 16 ++--- qui/seqbrowser/SequenceBrowser.hpp | 8 +-- qui/seqbrowser/SequenceBrowserWidget.cpp | 4 +- qui/seqbrowser/SequenceBrowserWidget.hpp | 4 +- 7 files changed, 75 insertions(+), 63 deletions(-) diff --git a/qui/MussaAlignedWindow.cpp b/qui/MussaAlignedWindow.cpp index d54ef3d..f418b02 100644 --- a/qui/MussaAlignedWindow.cpp +++ b/qui/MussaAlignedWindow.cpp @@ -63,7 +63,7 @@ void MussaAlignedWindow::setupMenus() newMenu->addAction(saveBrowserPixmapAction); newMenu = menuBar()->addMenu(tr("&Edit")); - newMenu->addAction(&browser.getCopySelectedSequenceAsFastaAction()); + newMenu->addAction(browser.getCopySelectedSequenceAsFastaAction()); } void MussaAlignedWindow::setupAlignmentMenus() diff --git a/qui/MussaWindow.cpp b/qui/MussaWindow.cpp index 6b0e8a7..a079974 100644 --- a/qui/MussaWindow.cpp +++ b/qui/MussaWindow.cpp @@ -34,11 +34,12 @@ MussaWindow::MussaWindow(Mussa *analysis_, QWidget *parent) : analysis(analysis_), default_dir(QDir::home().absolutePath().toStdString(), fs::native), motif_editor(0), - setup_analysis_dialog(this), - browser(this), - mussaViewTB("Path Views"), - zoom(), - threshold(), + setup_analysis_dialog(new MussaSetupDialog(this)), + subanalysis_window(new SubanalysisWindow), + browser(new SequenceBrowserWidget(this)), + mussaViewTB(new QToolBar("Path Views")), + zoom(new ZoomWidget), + threshold(new ThresholdWidget), progress_dialog(0), aboutAction(0), closeAction(0), @@ -66,28 +67,28 @@ MussaWindow::MussaWindow(Mussa *analysis_, QWidget *parent) : // a segfault when using WhatsThis feature with // opengl widget. //scene->setWhatsThis(tr("Mussa in OpenGL!")); - setCentralWidget(&browser); + setCentralWidget(browser); // well updatePosition isn't quite right as we really just need // to call update() - connect(this, SIGNAL(changedAnnotations()), &browser, SLOT(update())); + connect(this, SIGNAL(changedAnnotations()), browser, SLOT(update())); - //mussaViewTB.addAction(toggleMotifsAction); - mussaViewTB.addWidget(&zoom); + //mussaViewTB->addAction(toggleMotifsAction); + mussaViewTB->addWidget(zoom); - connect(&zoom, SIGNAL(valueChanged(double)), - &browser, SLOT(setZoom(double))); + connect(zoom, SIGNAL(valueChanged(double)), + browser, SLOT(setZoom(double))); // threshold range is set in updateAnalysis //scene->setClipPlane(20); // FIXME: for when we get the paths drawn at the appropriate depth - //connect(&threshold, SIGNAL(thresholdChanged(int)), + //connect(threshold, SIGNAL(thresholdChanged(int)), // this, SLOT(setClipPlane(int))); - connect(&threshold, SIGNAL(thresholdChanged(int)), + connect(threshold, SIGNAL(thresholdChanged(int)), this, SLOT(setSoftThreshold(int))); - mussaViewTB.addWidget(&threshold); + mussaViewTB->addWidget(threshold); - addToolBar(&mussaViewTB); + addToolBar(mussaViewTB); statusBar()->showMessage("Welcome to mussa", 2000); connect(analysis, SIGNAL(progress(const std::string&, int, int)), @@ -194,7 +195,7 @@ void MussaWindow::setupActions() //Save pixel map action saveBrowserPixmapAction = new QAction(tr("Save to image..."), this); connect(saveBrowserPixmapAction, (SIGNAL(triggered())), - &browser, SLOT(promptSaveBrowserPixmap())); + browser, SLOT(promptSaveBrowserPixmap())); saveBrowserPixmapAction->setIcon(QIcon(":/icons/image2.png")); viewMussaAlignmentAction = new QAction(tr("View sequence alignment"), this); @@ -242,7 +243,7 @@ void MussaWindow::setupMainMenu() newMenu = menuBar()->addMenu(tr("&Edit")); newMenu->addAction(editMotifsAction); - newMenu->addAction(&browser.getCopySelectedSequenceAsFastaAction()); + newMenu->addAction(browser->getCopySelectedSequenceAsFastaAction()); newMenu->addAction(createSubAnalysisAction); newMenu = menuBar()->addMenu(tr("&View")); @@ -256,9 +257,11 @@ void MussaWindow::setupMainMenu() newMenu->addAction(aboutAction); // add some extra features to the context menu - QMenu& popupMenu = browser.getPopupMenu(); - popupMenu.addAction(viewMussaAlignmentAction); - popupMenu.addAction(createSubAnalysisAction); + QMenu *popupMenu = browser->getPopupMenu(); + if (popupMenu) { + popupMenu->addAction(viewMussaAlignmentAction); + popupMenu->addAction(createSubAnalysisAction); + } } void MussaWindow::setupAssistant() @@ -289,7 +292,7 @@ void MussaWindow::about() void MussaWindow::clear() { aligned_windows.clear(); - browser.clear(); + browser->clear(); } void MussaWindow::createNewAnalysis() @@ -299,9 +302,9 @@ void MussaWindow::createNewAnalysis() // but this should work for the moment. if (not isClearingAnalysisSafe()) return; - if (setup_analysis_dialog.exec()) { + if (setup_analysis_dialog->exec()) { Mussa *m = 0; - m = setup_analysis_dialog.getMussa(); + m = setup_analysis_dialog->getMussa(); setAnalysis(m); } } catch(mussa_error e) { @@ -313,8 +316,8 @@ void MussaWindow::createNewAnalysis() void MussaWindow::createSubAnalysis() { list result; - SequenceLocationModel& model = subanalysis_window.getModel(); - browser.copySelectedTracksAsSeqLocation(result); + SequenceLocationModel& model = subanalysis_window->getModel(); + browser->copySelectedTracksAsSeqLocation(result); for(list::iterator result_itor = result.begin(); result_itor != result.end(); ++result_itor) @@ -322,8 +325,8 @@ void MussaWindow::createSubAnalysis() model.push_back(*result_itor); } - if (not subanalysis_window.isVisible()) { - subanalysis_window.show(); + if (not subanalysis_window->isVisible()) { + subanalysis_window->show(); } } @@ -557,10 +560,10 @@ void MussaWindow::setSoftThreshold(int threshold) void MussaWindow::showMussaToolbar() { - if (mussaViewTB.isVisible()) - mussaViewTB.hide(); + if (mussaViewTB->isVisible()) + mussaViewTB->hide(); else - mussaViewTB.show(); + mussaViewTB->show(); } void MussaWindow::toggleMotifs() @@ -597,7 +600,7 @@ void MussaWindow::NotImplementedBox() void MussaWindow::viewMussaAlignment() { - const set& selected_paths = browser.selectedPaths(); + const set& selected_paths = browser->selectedPaths(); if (selected_paths.size() == 0 ) { QMessageBox::warning(this, QObject::tr("mussa"), @@ -617,13 +620,17 @@ void MussaWindow::viewMussaAlignment() void MussaWindow::updateAnalysis() { - threshold.setRange(analysis->get_threshold(),analysis->get_window()); - const Mussa::vector_sequence_type& seqs = analysis->sequences(); - browser.setSequences(seqs, analysis->colorMapper()); + browser->setSequences(seqs, analysis->colorMapper()); + assert(browser->sequences().size() == analysis->size()); + + // setRange eventually emits something that causes updateLinks to be called + // but it's possible for us to not have had a chance to set out sequences + // yet. + threshold->setRange(analysis->get_threshold(),analysis->get_window()); updateLinks(); - browser.zoomOut(); - zoom.setValue(browser.zoom()); + browser->zoomOut(); + zoom->setValue(browser->zoom()); } void MussaWindow::updateAnnotations() @@ -631,12 +638,17 @@ void MussaWindow::updateAnnotations() // motifs were changed in the sequences by // Mussa::update_sequences_motifs emit changedAnnotations(); - browser.update(); + browser->update(); } void MussaWindow::updateLinks() { - browser.clear_links(); + if(browser->sequences().size() == 0) { + // we don't have any sequences load so we have no business setting links + return; + } + + browser->clear_links(); bool reversed = false; const NwayPaths& nway = analysis->paths(); @@ -674,9 +686,9 @@ void MussaWindow::updateLinks() normalized_path.push_back(x); rc_flags.push_back(reversed); } - browser.link(normalized_path, rc_flags, path_itor->window_size); + browser->link(normalized_path, rc_flags, path_itor->window_size); } - browser.update(); + browser->update(); } void diff --git a/qui/MussaWindow.hpp b/qui/MussaWindow.hpp index d81d027..83692d3 100644 --- a/qui/MussaWindow.hpp +++ b/qui/MussaWindow.hpp @@ -99,14 +99,14 @@ protected: boost::filesystem::path default_dir; std::list > aligned_windows; MotifEditor *motif_editor; - MussaSetupDialog setup_analysis_dialog; - SubanalysisWindow subanalysis_window; + MussaSetupDialog *setup_analysis_dialog; + boost::shared_ptr subanalysis_window; // display our wonderful mussa output - SequenceBrowserWidget browser; - QToolBar mussaViewTB; - ZoomWidget zoom; - ThresholdWidget threshold; + SequenceBrowserWidget *browser; + QToolBar *mussaViewTB; + ZoomWidget *zoom; + ThresholdWidget *threshold; QProgressDialog *progress_dialog; QAction *aboutAction; diff --git a/qui/seqbrowser/SequenceBrowser.cpp b/qui/seqbrowser/SequenceBrowser.cpp index 3d31f7f..fbfc124 100644 --- a/qui/seqbrowser/SequenceBrowser.cpp +++ b/qui/seqbrowser/SequenceBrowser.cpp @@ -20,21 +20,21 @@ using namespace std; SequenceBrowser::SequenceBrowser(QWidget *parent) : QGLWidget(parent), rubberBand(0), - popupMenu(this), - copySelectedSequenceAsFastaAction(tr("&Copy as Fasta"), this) + popupMenu(new QMenu(this)), + copySelectedSequenceAsFastaAction(new QAction(tr("&Copy as Fasta"), this)) { - connect(©SelectedSequenceAsFastaAction, SIGNAL(triggered()), + connect(copySelectedSequenceAsFastaAction, SIGNAL(triggered()), this, SLOT(copySelectedSequenceAsFasta())); - copySelectedSequenceAsFastaAction.setShortcut(Qt::CTRL | Qt::Key_C); - popupMenu.addAction(©SelectedSequenceAsFastaAction); + copySelectedSequenceAsFastaAction->setShortcut(Qt::CTRL | Qt::Key_C); + popupMenu->addAction(copySelectedSequenceAsFastaAction); } -QMenu &SequenceBrowser::getPopupMenu() +QMenu *SequenceBrowser::getPopupMenu() { return popupMenu; } -QAction &SequenceBrowser::getCopySelectedSequenceAsFastaAction() +QAction *SequenceBrowser::getCopySelectedSequenceAsFastaAction() { return copySelectedSequenceAsFastaAction; } @@ -105,7 +105,7 @@ void SequenceBrowser::clear() void SequenceBrowser::displayContextMenu(const QPoint& point) { - popupMenu.popup(point); + popupMenu->popup(point); } void SequenceBrowser::push_sequence(boost::shared_ptr s) diff --git a/qui/seqbrowser/SequenceBrowser.hpp b/qui/seqbrowser/SequenceBrowser.hpp index 7ada612..8d1ef65 100644 --- a/qui/seqbrowser/SequenceBrowser.hpp +++ b/qui/seqbrowser/SequenceBrowser.hpp @@ -34,9 +34,9 @@ public: void push_sequence(boost::shared_ptr); //! return the popup menu for the glcanvas (reference stored internally) - QMenu &getPopupMenu(); + QMenu *getPopupMenu(); //! return our copy actioy (reference stored internally) - QAction &getCopySelectedSequenceAsFastaAction(); + QAction *getCopySelectedSequenceAsFastaAction(); public slots: void copySelectedSequenceAsFasta(); @@ -71,7 +71,7 @@ protected: void stopSelecting(QMouseEvent *); /* \@} */ - QMenu popupMenu; - QAction copySelectedSequenceAsFastaAction; + QMenu *popupMenu; + QAction *copySelectedSequenceAsFastaAction; }; #endif diff --git a/qui/seqbrowser/SequenceBrowserWidget.cpp b/qui/seqbrowser/SequenceBrowserWidget.cpp index 6152913..0ce3030 100644 --- a/qui/seqbrowser/SequenceBrowserWidget.cpp +++ b/qui/seqbrowser/SequenceBrowserWidget.cpp @@ -51,12 +51,12 @@ void SequenceBrowserWidget::clear() right_sidebar.clear(); } -QMenu &SequenceBrowserWidget::getPopupMenu() +QMenu *SequenceBrowserWidget::getPopupMenu() { return scrollable_browser.browser().getPopupMenu(); } -QAction &SequenceBrowserWidget::getCopySelectedSequenceAsFastaAction() +QAction *SequenceBrowserWidget::getCopySelectedSequenceAsFastaAction() { return scrollable_browser.browser().getCopySelectedSequenceAsFastaAction(); } diff --git a/qui/seqbrowser/SequenceBrowserWidget.hpp b/qui/seqbrowser/SequenceBrowserWidget.hpp index 332fa1b..fedb86f 100644 --- a/qui/seqbrowser/SequenceBrowserWidget.hpp +++ b/qui/seqbrowser/SequenceBrowserWidget.hpp @@ -20,9 +20,9 @@ public: SequenceBrowserWidget(QWidget *parent=0); //! return the popup menu for the glcanvas (reference stored internally) - QMenu &getPopupMenu(); + QMenu *getPopupMenu(); //! return our copy actioy (reference stored internally) - QAction &getCopySelectedSequenceAsFastaAction(); + QAction *getCopySelectedSequenceAsFastaAction(); //! copy selected track regions into a list of SequenceLocations void copySelectedTracksAsSeqLocation(std::list& ); -- 2.30.2