From: Diane Trout Date: Fri, 16 Jun 2006 00:33:49 +0000 (+0000) Subject: ticket:104 fix some pointer problems with MussaAlignedWindow X-Git-Url: http://woldlab.caltech.edu/gitweb/?a=commitdiff_plain;h=43df51947281da85b5fc7d0e0d26ca2967d8ef73;p=mussa.git ticket:104 fix some pointer problems with MussaAlignedWindow the vector of MussaAlignedWindow * was having prolems with a double delete. when a MussaAlignedWindow was open and one tried to load a different analysis, the code that was closing all of the open windows crashed. when I found boost::shared_ptr to fix it, I then found a problem with the Qt trying to delete my shared zoom object which was also causing a crash. This should have all of that fixed, and as a bonus the new analysis doesn't have any of the old analysis' selections open. --- diff --git a/alg/glseqbrowser.cpp b/alg/glseqbrowser.cpp index 30d96f8..a0fc679 100644 --- a/alg/glseqbrowser.cpp +++ b/alg/glseqbrowser.cpp @@ -297,11 +297,20 @@ AnnotationColors& GlSeqBrowser::colorMapper() void GlSeqBrowser::clear() { + clear_selection(); clear_links(); path_segments.clear(); track_container.clear(); } +void GlSeqBrowser::clear_selection() +{ + selectedMode = false; + selectedRegion.clear(); + selected_paths.clear(); + selected_tracks.clear(); +} + void GlSeqBrowser::push_sequence(const Sequence &s) { GlSequence gs(s, color_mapper); diff --git a/alg/glseqbrowser.hpp b/alg/glseqbrowser.hpp index 109bc50..8ad16c4 100644 --- a/alg/glseqbrowser.hpp +++ b/alg/glseqbrowser.hpp @@ -63,6 +63,8 @@ public: //! clear our tracks and connections void clear(); + //! clear everything related to a selection + void clear_selection(); //! add a sequence to the back of our track container void push_sequence(const Sequence &s); @@ -109,6 +111,7 @@ public: rect(T t, T l, T b, T r) : top(t), left(l), bottom(b), right(r) {} T width() { return right - left; } T height() { return top - bottom; } + void clear() { top=0; left=0; bottom=0; right=0; } }; struct Segment diff --git a/alg/sequence.hpp b/alg/sequence.hpp index 41c80cd..86acee5 100644 --- a/alg/sequence.hpp +++ b/alg/sequence.hpp @@ -49,8 +49,6 @@ struct motif : public annot //! sequence track for mussa. class Sequence { - friend class ConnView; - friend class SeqView; private: std::string sequence; std::string header; diff --git a/qui/MussaAlignedWindow.cpp b/qui/MussaAlignedWindow.cpp index a85975a..d54ef3d 100644 --- a/qui/MussaAlignedWindow.cpp +++ b/qui/MussaAlignedWindow.cpp @@ -18,26 +18,30 @@ MussaAlignedWindow::MussaAlignedWindow(Mussa& m, : QMainWindow(parent), analysis(m), pick_align_menu(tr("Choose Alignment")), - view_align_menu(tr("View Alignment")) + view_align_menu(tr("View Alignment")), + zoom(0), + alignTB(0) { setupActions(); browser.setSequences(analysis.sequences(), analysis.colorMapper()); setSelectedPaths(m, sel_paths); setAlignment(0); double zoom_level = browser.zoomToSequence(); - zoom.setValue(zoom_level); + + zoom = new ZoomWidget(); + connect(zoom, SIGNAL(valueChanged(double)), + &browser, SLOT(setZoom(double))); + zoom->setValue(zoom_level); computeMatchLines(); setupMenus(); setupAlignmentMenus(); setCentralWidget(&browser); - addToolBar(&alignTB); - alignTB.addWidget(&zoom); + alignTB = new QToolBar(); + alignTB->addWidget(zoom); + addToolBar(alignTB); - connect(&zoom, SIGNAL(valueChanged(double)), - &browser, SLOT(setZoom(double))); - ostringstream message; message << "Selected " << selected_paths.size() << " paths"; statusBar()->showMessage(message.str().c_str(), 5000); diff --git a/qui/MussaAlignedWindow.hpp b/qui/MussaAlignedWindow.hpp index 7b140a6..1e71390 100644 --- a/qui/MussaAlignedWindow.hpp +++ b/qui/MussaAlignedWindow.hpp @@ -53,7 +53,7 @@ protected: std::vector pick_actions; std::vector view_actions; - ZoomWidget zoom; - QToolBar alignTB; + ZoomWidget *zoom; + QToolBar *alignTB; }; #endif diff --git a/qui/MussaWindow.cpp b/qui/MussaWindow.cpp index d83e0b5..31d197b 100644 --- a/qui/MussaWindow.cpp +++ b/qui/MussaWindow.cpp @@ -20,10 +20,12 @@ #include "qui/MussaWindow.hpp" #include "mussa_exceptions.hpp" +#include #include #include namespace fs = boost::filesystem; +#include using namespace std; @@ -55,7 +57,6 @@ MussaWindow::MussaWindow(Mussa *analysis_, QWidget *parent) : viewMussaAlignmentAction(0), manualAssistant(0) { - setupActions(); setupMainMenu(); setupAssistant(); @@ -125,6 +126,7 @@ void MussaWindow::setAnalysis(Mussa *new_analysis) { if (new_analysis != 0) { // only switch mussas if we loaded without error + clear(); delete analysis; analysis = new_analysis; setWindowTitle(analysis->get_name().c_str()); @@ -300,6 +302,12 @@ void MussaWindow::about() QMessageBox::about(this, tr("About mussa"), msg); } +void MussaWindow::clear() +{ + aligned_windows.clear(); + browser.clear(); +} + void MussaWindow::createNewAnalysis() { try { @@ -480,27 +488,21 @@ void MussaWindow::viewMussaAlignment() QObject::tr("you should probably select some paths " "first")); } else { - MussaAlignedWindow *ma_win = new MussaAlignedWindow(*analysis, - selected_paths); - connect(this, SIGNAL(changedAnnotations()), - ma_win, SLOT(update())); + boost::shared_ptr ma_win( + new MussaAlignedWindow(*analysis, selected_paths) + ); + aligned_windows.push_back(ma_win); - ma_win->show(); + connect(this, SIGNAL(changedAnnotations()), + aligned_windows.back().get(), SLOT(update())); + aligned_windows.back()->show(); } } void MussaWindow::updateAnalysis() { threshold.setRange(analysis->get_threshold(),analysis->get_window()); - for (list::iterator maw_i = aligned_windows.begin(); - maw_i != aligned_windows.end(); - ++maw_i) - { - (*maw_i)->hide(); - delete *maw_i; - } - browser.clear(); const vector& seqs = analysis->sequences(); browser.setSequences(seqs, analysis->colorMapper()); updateLinks(); diff --git a/qui/MussaWindow.hpp b/qui/MussaWindow.hpp index 42c90a2..dfbe89c 100644 --- a/qui/MussaWindow.hpp +++ b/qui/MussaWindow.hpp @@ -2,6 +2,7 @@ #define _MUSSAWINDOW_H_ #include +#include #include #include @@ -31,6 +32,9 @@ public: MussaWindow(Mussa* analysis=0, QWidget *parent=0); ~MussaWindow(); + //! reset any attached window + void clear(); + //! switch to a new analysis void setAnalysis(Mussa *new_analysis); public slots: @@ -81,7 +85,7 @@ signals: protected: Mussa *analysis; - std::list aligned_windows; + std::list > aligned_windows; MotifEditor *motif_editor; MussaSetupDialog setup_analysis_dialog; diff --git a/qui/ZoomWidget.cpp b/qui/ZoomWidget.cpp index b32efea..24c71a1 100644 --- a/qui/ZoomWidget.cpp +++ b/qui/ZoomWidget.cpp @@ -14,10 +14,10 @@ ZoomWidget::ZoomWidget(QWidget *parent) zoom.setSingleStep(0.1); connect(&zoom, SIGNAL(valueChanged(double)), this, SLOT(setValue(double))); - QLabel *zoomLabel = new QLabel(); + auto_ptr zoomLabel(new QLabel()); zoomLabel->setPixmap(QIcon(":/icons/viewmag.png").pixmap(16, 16)); QHBoxLayout *layout = new QHBoxLayout; - layout->addWidget(zoomLabel); + layout->addWidget(zoomLabel.get()); layout->addWidget(&zoom); layout->addWidget(new QLabel("bp/pix")); setLayout(layout);